Factory.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 // STD/STL
25 
26 // Header
27 #include "Factory.h"
28 
29 // ArmarX
31 
32 namespace armarx::aron::type
33 {
34  // Access method
35  std::unique_ptr<type::Variant>
36  VariantFactory::create(const type::dto::GenericType& aron, const Path& path) const
37  {
38  auto v = aron.VERSION;
39  auto v_str =
40  std::to_string(v.MAJOR) + "." + std::to_string(v.MINOR) + "." + std::to_string(v.PATCH);
41 
42  auto d = aron::Version();
43  auto d_str =
44  std::to_string(d.MAJOR) + "." + std::to_string(d.MINOR) + "." + std::to_string(d.PATCH);
45 
46  if (v != d)
47  {
49  << "Found inconsistencies in aron versions. This may lead to ice marshalling "
50  "exceptions. Please make sure to update the sender and receiver packages. "
51  << v_str << " != " << d_str;
52  }
53 
54  auto descriptor = type::Aron2Descriptor(aron);
55  switch (descriptor)
56  {
58  return std::make_unique<type::List>(dynamic_cast<const type::dto::List&>(aron),
59  path);
61  return std::make_unique<type::Dict>(dynamic_cast<const type::dto::Dict&>(aron),
62  path);
64  return std::make_unique<type::Pair>(dynamic_cast<const type::dto::Pair&>(aron),
65  path);
67  return std::make_unique<type::Tuple>(dynamic_cast<const type::dto::Tuple&>(aron),
68  path);
70  return std::make_unique<type::Object>(
71  dynamic_cast<const type::dto::AronObject&>(aron), path);
73  return std::make_unique<type::NDArray>(
74  dynamic_cast<const type::dto::NDArray&>(aron), path);
76  return std::make_unique<type::Matrix>(dynamic_cast<const type::dto::Matrix&>(aron),
77  path);
79  return std::make_unique<type::Image>(dynamic_cast<const type::dto::Image&>(aron),
80  path);
82  return std::make_unique<type::PointCloud>(
83  dynamic_cast<const type::dto::PointCloud&>(aron), path);
85  return std::make_unique<type::Quaternion>(
86  dynamic_cast<const type::dto::Quaternion&>(aron), path);
88  return std::make_unique<type::IntEnum>(
89  dynamic_cast<const type::dto::IntEnum&>(aron), path);
91  return std::make_unique<type::Int>(dynamic_cast<const type::dto::AronInt&>(aron),
92  path);
94  return std::make_unique<type::Long>(dynamic_cast<const type::dto::AronLong&>(aron),
95  path);
97  return std::make_unique<type::Float>(
98  dynamic_cast<const type::dto::AronFloat&>(aron), path);
100  return std::make_unique<type::Double>(
101  dynamic_cast<const type::dto::AronDouble&>(aron), path);
103  return std::make_unique<type::String>(
104  dynamic_cast<const type::dto::AronString&>(aron), path);
106  return std::make_unique<type::Bool>(dynamic_cast<const type::dto::AronBool&>(aron),
107  path);
109  return std::make_unique<type::AnyObject>(
110  dynamic_cast<const type::dto::AnyObject&>(aron), path);
112  break;
113  }
115  __PRETTY_FUNCTION__,
116  "Got an unknown descriptor",
117  std::to_string((int)descriptor) + " aka " +
119  path);
120  }
121 
122 } // namespace armarx::aron::type
armarx::aron::type::Descriptor::FLOAT
@ FLOAT
armarx::aron::type::Descriptor::DOUBLE
@ DOUBLE
Matrix
Eigen::Matrix< T, 3, 3 > Matrix
Definition: UnscentedKalmanFilterTest.cpp:37
armarx::VariantType::List
const VariantContainerType List
Definition: SingleTypeVariantList.h:191
armarx::aron::type::Descriptor::IMAGE
@ IMAGE
armarx::aron::type::VariantFactory::create
std::unique_ptr< type::Variant > create(const type::dto::GenericType &, const Path &) const
the create methods. Basically does a switch case over the ice_id of the dto and then returns a new va...
Definition: Factory.cpp:36
armarx::aron::type::Descriptor::PAIR
@ PAIR
armarx::aron::type::Descriptor::LIST
@ LIST
All.h
armarx::aron::type::Descriptor::NDARRAY
@ NDARRAY
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::type::Descriptor::BOOL
@ BOOL
armarx::aron::error::ValueNotValidException
The ValueNotValidException class.
Definition: Exception.h:145
armarx::aron::type::Descriptor::MATRIX
@ MATRIX
armarx::aron::type::Descriptor::QUATERNION
@ QUATERNION
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
Factory.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
visionx::PointCloud
pcl::PointCloud< Point > PointCloud
Definition: RCPointCloudProvider.cpp:54
armarx::aron::type::Descriptor::STRING
@ STRING
armarx::aron::type::Descriptor::LONG
@ LONG
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::type::Descriptor::INT
@ INT
armarx::aron::type::Aron2Descriptor
type::Descriptor Aron2Descriptor(const type::dto::GenericType &t)
Definition: Descriptor.h:185
armarx::aron::type::defaultconversion::string::Descriptor2String
const std::map< type::Descriptor, std::string > Descriptor2String
Definition: Descriptor.h:135
armarx::aron::type::Descriptor::INT_ENUM
@ INT_ENUM
armarx::aron::type::Descriptor::OBJECT
@ OBJECT
armarx::aron::type::Descriptor::UNKNOWN
@ UNKNOWN
armarx::aron::type::Descriptor::DICT
@ DICT
armarx::aron::type::Descriptor::TUPLE
@ TUPLE
armarx::aron::type::Descriptor::POINTCLOUD
@ POINTCLOUD
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::aron::type::Descriptor::ANY_OBJECT
@ ANY_OBJECT