Descriptor.h
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 #pragma once
25 
26 // STD/STL
27 #include <memory>
28 #include <typeindex>
29 #include <typeinfo>
30 #include <map>
31 #include <string>
32 
33 // Simox
34 #include <SimoxUtility/algorithm/string.h>
35 
36 // ArmarX
37 #include <RobotAPI/interface/aron.h>
38 
40 {
41  template <class T1, class T2>
42  std::map<T2, T1> InvertMap(const std::map<T1, T2>& m)
43  {
44  std::map<T2, T1> ret;
45  for (const auto &[key, val] : m)
46  {
47  ret.emplace(val, key);
48  }
49  return ret;
50  }
51 
52  template <class T>
53  std::map<T, std::string> InvertMap(const std::map<std::string, T>& m)
54  {
55  return InvertMap<std::string, T>(m);
56  }
57 
58  template <class T>
59  std::map<std::string, T> InvertMap(const std::map<T, std::string>& m)
60  {
61  return InvertMap<T, std::string>(m);
62  }
63 }
64 
65 namespace armarx::aron::type
66 {
67  const std::vector<type::Maybe> AllMaybeTypes =
68  {
70  type::Maybe::OPTIONAL,
71  type::Maybe::RAW_PTR,
72  type::Maybe::SHARED_PTR,
73  type::Maybe::UNIQUE_PTR
74  };
75 
76  enum class Descriptor
77  {
78  LIST,
79  OBJECT,
80  TUPLE,
81  PAIR,
82  DICT,
83  NDARRAY,
84  MATRIX,
85  QUATERNION,
86  POINTCLOUD,
87  IMAGE,
88  INT_ENUM,
89  INT,
90  LONG,
91  FLOAT,
92  DOUBLE,
93  BOOL,
94  STRING,
95  ANY_OBJECT,
96  UNKNOWN = -1
97  };
98 
99  const std::vector<type::Descriptor> AllDescriptors =
100  {
120  };
121 
122  namespace defaultconversion::string
123  {
124  // Maybe
125  const std::map<type::Maybe, std::string> Maybe2String =
126  {
127  {Maybe::NONE, "armarx::aron::type::Maybe::NONE"},
128  {Maybe::RAW_PTR, "armarx::aron::type::Maybe::RAW_PTR"},
129  {Maybe::SHARED_PTR, "armarx::aron::type::Maybe::SHARED_PTR"},
130  {Maybe::UNIQUE_PTR, "armarx::aron::type::Maybe::UNIQUE_PTR"},
131  {Maybe::OPTIONAL, "armarx::aron::type::Maybe::OPTIONAL"}
132  };
133 
134  // Descriptor
135  const std::map<type::Descriptor, std::string> Descriptor2String =
136  {
137  {Descriptor::LIST, "armarx::aron::type::Descriptor::LIST"},
138  {Descriptor::OBJECT, "armarx::aron::type::Descriptor::OBJECT"},
139  {Descriptor::DICT, "armarx::aron::type::Descriptor::DICT"},
140  {Descriptor::PAIR, "armarx::aron::type::Descriptor::PAIR"},
141  {Descriptor::TUPLE, "armarx::aron::type::Descriptor::TUPLE"},
142  {Descriptor::NDARRAY, "armarx::aron::type::Descriptor::NDARRAY"},
143  {Descriptor::MATRIX, "armarx::aron::type::Descriptor::MATRIX"},
144  {Descriptor::QUATERNION, "armarx::aron::type::Descriptor::QUATERNION"},
145  {Descriptor::IMAGE, "armarx::aron::type::Descriptor::IMAGE"},
146  {Descriptor::POINTCLOUD, "armarx::aron::type::Descriptor::POINTCLOUD"},
147  {Descriptor::NDARRAY, "armarx::aron::type::Descriptor::NDARRAY"},
148  {Descriptor::INT_ENUM, "armarx::aron::type::Descriptor::INT_ENUM"},
149  {Descriptor::INT, "armarx::aron::type::Descriptor::INT"},
150  {Descriptor::LONG, "armarx::aron::type::Descriptor::LONG"},
151  {Descriptor::FLOAT, "armarx::aron::type::Descriptor::FLOAT"},
152  {Descriptor::DOUBLE, "armarx::aron::type::Descriptor::DOUBLE"},
153  {Descriptor::BOOL, "armarx::aron::type::Descriptor::BOOL"},
154  {Descriptor::STRING, "armarx::aron::type::Descriptor::STRING"},
155  {Descriptor::ANY_OBJECT, "armarx::aron::type::Descriptor::ANY_OBJECT"},
156  {Descriptor::UNKNOWN, "armarx::aron::type::Descriptor::UNKNOWN"}
157  };
158  }
159 
160  namespace defaultconversion::typeinfo
161  {
162  // hash type
163  const std::map<size_t, Descriptor> TypeId2Descriptor = {
164  {typeid(aron::type::dto::List).hash_code(), Descriptor::LIST},
165  {typeid(aron::type::dto::AronObject).hash_code(), Descriptor::OBJECT},
166  {typeid(aron::type::dto::Tuple).hash_code(), Descriptor::TUPLE},
167  {typeid(aron::type::dto::Pair).hash_code(), Descriptor::PAIR},
168  {typeid(aron::type::dto::Dict).hash_code(), Descriptor::DICT},
169  {typeid(aron::type::dto::NDArray).hash_code(), Descriptor::NDARRAY},
170  {typeid(aron::type::dto::Matrix).hash_code(), Descriptor::MATRIX},
173  {typeid(aron::type::dto::Image).hash_code(), Descriptor::IMAGE},
174  {typeid(aron::type::dto::IntEnum).hash_code(), Descriptor::INT_ENUM},
175  {typeid(aron::type::dto::AronInt).hash_code(), Descriptor::INT},
176  {typeid(aron::type::dto::AronLong).hash_code(), Descriptor::LONG},
177  {typeid(aron::type::dto::AronFloat).hash_code(), Descriptor::FLOAT},
178  {typeid(aron::type::dto::AronDouble).hash_code(), Descriptor::DOUBLE},
179  {typeid(aron::type::dto::AronString).hash_code(), Descriptor::STRING},
180  {typeid(aron::type::dto::AronBool).hash_code(), Descriptor::BOOL},
181  {typeid(aron::type::dto::AnyObject).hash_code(), Descriptor::ANY_OBJECT}
182  };
183  }
184 
185  inline type::Descriptor Aron2Descriptor(const type::dto::GenericType& t)
186  {
187  return defaultconversion::typeinfo::TypeId2Descriptor.at(typeid(t).hash_code());
188  }
189 }
190 
191 namespace armarx::aron::data
192 {
193  enum class Descriptor
194  {
195  LIST,
196  DICT,
197  NDARRAY,
198  INT,
199  LONG,
200  FLOAT,
201  DOUBLE,
202  STRING,
203  BOOL,
204  UNKNOWN = -1
205  };
206 
207  const std::vector<data::Descriptor> AllDescriptors =
208  {
219  };
220 
221  namespace defaultconversion::string
222  {
223  // Descriptor
224  const std::map<data::Descriptor, std::string> Descriptor2String =
225  {
226  {Descriptor::LIST, "armarx::aron::data::Descriptor::LIST"},
227  {Descriptor::DICT, "armarx::aron::data::Descriptor::DICT"},
228  {Descriptor::NDARRAY, "armarx::aron::data::Descriptor::NDARRAY"},
229  {Descriptor::INT, "armarx::aron::data::Descriptor::INT"},
230  {Descriptor::LONG, "armarx::aron::data::Descriptor::LONG"},
231  {Descriptor::FLOAT, "armarx::aron::data::Descriptor::FLOAT"},
232  {Descriptor::DOUBLE, "armarx::aron::data::Descriptor::DOUBLE"},
233  {Descriptor::STRING, "armarx::aron::data::Descriptor::STRING"},
234  {Descriptor::BOOL, "armarx::aron::data::Descriptor::BOOL"},
235  {Descriptor::UNKNOWN, "armarx::aron::data::Descriptor::UNKNOWN"}
236  };
237  }
238 
239  namespace defaultconversion::typeinfo
240  {
241  // TypeID
242  const std::map<size_t, Descriptor> TypeId2Descriptor = {
243  {typeid(aron::data::dto::List).hash_code(), Descriptor::LIST},
244  {typeid(aron::data::dto::Dict).hash_code(), Descriptor::DICT},
245  {typeid(aron::data::dto::NDArray).hash_code(), Descriptor::NDARRAY},
246  {typeid(aron::data::dto::AronInt).hash_code(), Descriptor::INT},
247  {typeid(aron::data::dto::AronFloat).hash_code(), Descriptor::FLOAT},
248  {typeid(aron::data::dto::AronLong).hash_code(), Descriptor::LONG},
249  {typeid(aron::data::dto::AronDouble).hash_code(), Descriptor::DOUBLE},
250  {typeid(aron::data::dto::AronString).hash_code(), Descriptor::STRING},
251  {typeid(aron::data::dto::AronBool).hash_code(), Descriptor::BOOL},
252  };
253  }
254 
255  inline data::Descriptor Aron2Descriptor(const data::dto::GenericData& t)
256  {
257  return defaultconversion::typeinfo::TypeId2Descriptor.at(typeid(t).hash_code());
258  }
259 
260  namespace defaultconversion
261  {
262  // Useful if data is present but no type information. Try to infer type from data.
263  const std::map<Descriptor, aron::type::Descriptor> Data2TypeDescriptor = {
274  };
275 
276  const std::map<aron::type::Descriptor, Descriptor> Type2DataDescriptor = {
277  // containers
283 
284  // everything which gets an ndarray
290 
291  // enums
293 
294  // primitives
302  };
303  }
304 }
armarx::aron::type::Descriptor::FLOAT
@ FLOAT
armarx::aron::type::Descriptor::DOUBLE
@ DOUBLE
armarx::aron::data::Descriptor::NDARRAY
@ NDARRAY
armarx::aron::data::defaultconversion::Type2DataDescriptor
const std::map< aron::type::Descriptor, Descriptor > Type2DataDescriptor
Definition: Descriptor.h:276
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
Matrix
Eigen::Matrix< T, 3, 3 > Matrix
Definition: UnscentedKalmanFilterTest.cpp:37
armarx::VariantType::List
const VariantContainerType List
Definition: SingleTypeVariantList.h:191
armarx::aron::data::Descriptor::LIST
@ LIST
armarx::aron::type::Descriptor::IMAGE
@ IMAGE
armarx::aron::data::Descriptor::STRING
@ STRING
armarx::aron::data::defaultconversion::string::Descriptor2String
const std::map< data::Descriptor, std::string > Descriptor2String
Definition: Descriptor.h:224
armarx::aron::type::Descriptor::PAIR
@ PAIR
armarx::aron::type::Descriptor::LIST
@ LIST
armarx::aron::data::Descriptor
Descriptor
Definition: Descriptor.h:193
armarx::aron::data::AllDescriptors
const std::vector< data::Descriptor > AllDescriptors
Definition: Descriptor.h:207
armarx::aron::data::defaultconversion::Data2TypeDescriptor
const std::map< Descriptor, aron::type::Descriptor > Data2TypeDescriptor
Definition: Descriptor.h:263
armarx::aron::data::Descriptor::FLOAT
@ FLOAT
armarx::aron::type::Descriptor::NDARRAY
@ NDARRAY
armarx::aron::data::Descriptor::INT
@ INT
armarx::aron::conversion::util
Definition: Descriptor.h:39
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
armarx::aron::data::Descriptor::DICT
@ DICT
armarx::aron::type::AllMaybeTypes
const std::vector< type::Maybe > AllMaybeTypes
Definition: Descriptor.h:67
armarx::aron::type::Descriptor::BOOL
@ BOOL
armarx::aron::conversion::util::InvertMap
std::map< T2, T1 > InvertMap(const std::map< T1, T2 > &m)
Definition: Descriptor.h:42
armarx::aron::data::defaultconversion::typeinfo::TypeId2Descriptor
const std::map< size_t, Descriptor > TypeId2Descriptor
Definition: Descriptor.h:242
armarx::aron::type::Descriptor::MATRIX
@ MATRIX
armarx::aron::type::Descriptor::QUATERNION
@ QUATERNION
armarx::aron::data::Descriptor::BOOL
@ BOOL
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
armarx::aron::type::AllDescriptors
const std::vector< type::Descriptor > AllDescriptors
Definition: Descriptor.h:99
armarx::aron::data
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:3
visionx::PointCloud
pcl::PointCloud< Point > PointCloud
Definition: RCPointCloudProvider.cpp:54
armarx::aron::type::Descriptor::STRING
@ STRING
armarx::aron::type::Descriptor::LONG
@ LONG
armarx::aron::type::defaultconversion::typeinfo::TypeId2Descriptor
const std::map< size_t, Descriptor > TypeId2Descriptor
Definition: Descriptor.h:163
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::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:11
armarx::aron::type::Descriptor::INT_ENUM
@ INT_ENUM
armarx::aron::type::Descriptor::OBJECT
@ OBJECT
armarx::aron::type::Descriptor::UNKNOWN
@ UNKNOWN
armarx::aron::data::Descriptor::LONG
@ LONG
armarx::aron::type::Descriptor::DICT
@ DICT
armarx::aron::type::Descriptor::TUPLE
@ TUPLE
armarx::aron::data::Descriptor::DOUBLE
@ DOUBLE
armarx::aron::type::Descriptor::POINTCLOUD
@ POINTCLOUD
armarx::aron::data::Descriptor::UNKNOWN
@ UNKNOWN
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::data::Aron2Descriptor
data::Descriptor Aron2Descriptor(const data::dto::GenericData &t)
Definition: Descriptor.h:255
armarx::aron::type::defaultconversion::string::Maybe2String
const std::map< type::Maybe, std::string > Maybe2String
Definition: Descriptor.h:125
armarx::aron::type::Descriptor::ANY_OBJECT
@ ANY_OBJECT