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#include <map>
27#include <string>
28#include <typeinfo>
29
30#include <RobotAPI/interface/aron.h>
31
33{
34 template <class T1, class T2>
35 std::map<T2, T1>
36 InvertMap(const std::map<T1, T2>& m)
37 {
38 std::map<T2, T1> ret;
39 for (const auto& [key, val] : m)
40 {
41 ret.emplace(val, key);
42 }
43 return ret;
44 }
45
46 template <class T>
47 std::map<T, std::string>
48 InvertMap(const std::map<std::string, T>& m)
49 {
51 }
52
53 template <class T>
54 std::map<std::string, T>
55 InvertMap(const std::map<T, std::string>& m)
56 {
58 }
59} // namespace armarx::aron::conversion::util
60
61namespace armarx::aron::type
62{
63 const std::vector<type::Maybe> AllMaybeTypes = {type::Maybe::NONE,
64 type::Maybe::OPTIONAL,
65 type::Maybe::RAW_PTR,
66 type::Maybe::SHARED_PTR,
67 type::Maybe::UNIQUE_PTR};
68
91
111
113 {
114 // Maybe
115 const std::map<type::Maybe, std::string> Maybe2String = {
116 {Maybe::NONE, "armarx::aron::type::Maybe::NONE"},
117 {Maybe::RAW_PTR, "armarx::aron::type::Maybe::RAW_PTR"},
118 {Maybe::SHARED_PTR, "armarx::aron::type::Maybe::SHARED_PTR"},
119 {Maybe::UNIQUE_PTR, "armarx::aron::type::Maybe::UNIQUE_PTR"},
120 {Maybe::OPTIONAL, "armarx::aron::type::Maybe::OPTIONAL"}};
121
122 // Descriptor
123 const std::map<type::Descriptor, std::string> Descriptor2String = {
124 {Descriptor::LIST, "armarx::aron::type::Descriptor::LIST"},
125 {Descriptor::OBJECT, "armarx::aron::type::Descriptor::OBJECT"},
126 {Descriptor::DICT, "armarx::aron::type::Descriptor::DICT"},
127 {Descriptor::PAIR, "armarx::aron::type::Descriptor::PAIR"},
128 {Descriptor::TUPLE, "armarx::aron::type::Descriptor::TUPLE"},
129 {Descriptor::NDARRAY, "armarx::aron::type::Descriptor::NDARRAY"},
130 {Descriptor::MATRIX, "armarx::aron::type::Descriptor::MATRIX"},
131 {Descriptor::QUATERNION, "armarx::aron::type::Descriptor::QUATERNION"},
132 {Descriptor::IMAGE, "armarx::aron::type::Descriptor::IMAGE"},
133 {Descriptor::POINTCLOUD, "armarx::aron::type::Descriptor::POINTCLOUD"},
134 {Descriptor::NDARRAY, "armarx::aron::type::Descriptor::NDARRAY"},
135 {Descriptor::INT_ENUM, "armarx::aron::type::Descriptor::INT_ENUM"},
136 {Descriptor::INT, "armarx::aron::type::Descriptor::INT"},
137 {Descriptor::LONG, "armarx::aron::type::Descriptor::LONG"},
138 {Descriptor::FLOAT, "armarx::aron::type::Descriptor::FLOAT"},
139 {Descriptor::DOUBLE, "armarx::aron::type::Descriptor::DOUBLE"},
140 {Descriptor::BOOL, "armarx::aron::type::Descriptor::BOOL"},
141 {Descriptor::STRING, "armarx::aron::type::Descriptor::STRING"},
142 {Descriptor::ANY_OBJECT, "armarx::aron::type::Descriptor::ANY_OBJECT"},
143 {Descriptor::UNKNOWN, "armarx::aron::type::Descriptor::UNKNOWN"}};
144 } // namespace defaultconversion::string
145
147 {
148 // hash type
149 const std::map<size_t, Descriptor> TypeId2Descriptor = {
150 {typeid(aron::type::dto::List).hash_code(), Descriptor::LIST},
151 {typeid(aron::type::dto::AronObject).hash_code(), Descriptor::OBJECT},
152 {typeid(aron::type::dto::Tuple).hash_code(), Descriptor::TUPLE},
153 {typeid(aron::type::dto::Pair).hash_code(), Descriptor::PAIR},
154 {typeid(aron::type::dto::Dict).hash_code(), Descriptor::DICT},
155 {typeid(aron::type::dto::NDArray).hash_code(), Descriptor::NDARRAY},
156 {typeid(aron::type::dto::Matrix).hash_code(), Descriptor::MATRIX},
157 {typeid(aron::type::dto::Quaternion).hash_code(), Descriptor::QUATERNION},
158 {typeid(aron::type::dto::PointCloud).hash_code(), Descriptor::POINTCLOUD},
159 {typeid(aron::type::dto::Image).hash_code(), Descriptor::IMAGE},
160 {typeid(aron::type::dto::IntEnum).hash_code(), Descriptor::INT_ENUM},
161 {typeid(aron::type::dto::AronInt).hash_code(), Descriptor::INT},
162 {typeid(aron::type::dto::AronLong).hash_code(), Descriptor::LONG},
163 {typeid(aron::type::dto::AronFloat).hash_code(), Descriptor::FLOAT},
164 {typeid(aron::type::dto::AronDouble).hash_code(), Descriptor::DOUBLE},
165 {typeid(aron::type::dto::AronString).hash_code(), Descriptor::STRING},
166 {typeid(aron::type::dto::AronBool).hash_code(), Descriptor::BOOL},
167 {typeid(aron::type::dto::AnyObject).hash_code(), Descriptor::ANY_OBJECT}};
168 } // namespace defaultconversion::typeinfo
169
170 inline type::Descriptor
171 Aron2Descriptor(const type::dto::GenericType& t)
172 {
173 return defaultconversion::typeinfo::TypeId2Descriptor.at(typeid(t).hash_code());
174 }
175} // namespace armarx::aron::type
176
177namespace armarx::aron::data
178{
192
203
205 {
206 // Descriptor
207 const std::map<data::Descriptor, std::string> Descriptor2String = {
208 {Descriptor::LIST, "armarx::aron::data::Descriptor::LIST"},
209 {Descriptor::DICT, "armarx::aron::data::Descriptor::DICT"},
210 {Descriptor::NDARRAY, "armarx::aron::data::Descriptor::NDARRAY"},
211 {Descriptor::INT, "armarx::aron::data::Descriptor::INT"},
212 {Descriptor::LONG, "armarx::aron::data::Descriptor::LONG"},
213 {Descriptor::FLOAT, "armarx::aron::data::Descriptor::FLOAT"},
214 {Descriptor::DOUBLE, "armarx::aron::data::Descriptor::DOUBLE"},
215 {Descriptor::STRING, "armarx::aron::data::Descriptor::STRING"},
216 {Descriptor::BOOL, "armarx::aron::data::Descriptor::BOOL"},
217 {Descriptor::UNKNOWN, "armarx::aron::data::Descriptor::UNKNOWN"}};
218 } // namespace defaultconversion::string
219
221 {
222 // TypeID
223 const std::map<size_t, Descriptor> TypeId2Descriptor = {
224 {typeid(aron::data::dto::List).hash_code(), Descriptor::LIST},
225 {typeid(aron::data::dto::Dict).hash_code(), Descriptor::DICT},
226 {typeid(aron::data::dto::NDArray).hash_code(), Descriptor::NDARRAY},
227 {typeid(aron::data::dto::AronInt).hash_code(), Descriptor::INT},
228 {typeid(aron::data::dto::AronFloat).hash_code(), Descriptor::FLOAT},
229 {typeid(aron::data::dto::AronLong).hash_code(), Descriptor::LONG},
230 {typeid(aron::data::dto::AronDouble).hash_code(), Descriptor::DOUBLE},
231 {typeid(aron::data::dto::AronString).hash_code(), Descriptor::STRING},
232 {typeid(aron::data::dto::AronBool).hash_code(), Descriptor::BOOL},
233 };
234 } // namespace defaultconversion::typeinfo
235
236 inline data::Descriptor
237 Aron2Descriptor(const data::dto::GenericData& t)
238 {
239 return defaultconversion::typeinfo::TypeId2Descriptor.at(typeid(t).hash_code());
240 }
241
242 namespace defaultconversion
243 {
244 // Useful if data is present but no type information. Try to infer type from data.
256
284 } // namespace defaultconversion
285} // namespace armarx::aron::data
std::map< T2, T1 > InvertMap(const std::map< T1, T2 > &m)
Definition Descriptor.h:36
const std::map< data::Descriptor, std::string > Descriptor2String
Definition Descriptor.h:207
const std::map< size_t, Descriptor > TypeId2Descriptor
Definition Descriptor.h:223
const std::map< Descriptor, aron::type::Descriptor > Data2TypeDescriptor
Definition Descriptor.h:245
const std::map< aron::type::Descriptor, Descriptor > Type2DataDescriptor
Definition Descriptor.h:257
A convenience header to include all aron files (full include, not forward declared)
data::Descriptor Aron2Descriptor(const data::dto::GenericData &t)
Definition Descriptor.h:237
const std::vector< data::Descriptor > AllDescriptors
Definition Descriptor.h:193
const std::map< type::Maybe, std::string > Maybe2String
Definition Descriptor.h:115
const std::map< type::Descriptor, std::string > Descriptor2String
Definition Descriptor.h:123
const std::map< size_t, Descriptor > TypeId2Descriptor
Definition Descriptor.h:149
A convenience header to include all aron files (full include, not forward declared)
const std::vector< type::Descriptor > AllDescriptors
Definition Descriptor.h:92
type::Descriptor Aron2Descriptor(const type::dto::GenericType &t)
Definition Descriptor.h:171
const std::vector< type::Maybe > AllMaybeTypes
Definition Descriptor.h:63