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 // Simox
27 #include <SimoxUtility/algorithm/string.h>
28 
29 // Header
30 #include "Factory.h"
31 
32 // ArmarX
34 
36 
37 #include "Data.h"
38 
40 {
41  void
42  printDeprecationWarning(const std::string& warning)
43  {
44  auto v = armarx::aron::Version();
45  auto v_str =
46  std::to_string(v.MAJOR) + "." + std::to_string(v.MINOR) + "." + std::to_string(v.PATCH);
47  std::cout
48  << "\033[1;33m[**Aron v" + v_str + " deprecation warning**]: " << warning
49  << "\nPlease note that a future version of aron might not support this anymore.\033[0m"
50  << std::endl;
51  }
52 
53  void
54  printWarning(const std::string& warning)
55  {
56  std::cout << "\033[1;33m[**Aron warning**]: " << warning << "\033[0m" << std::endl;
57  }
58 
60  ReaderFactory::create(const RapidXmlReaderNode& node, const Path& path)
61  {
62  static const std::map<std::string, type::Descriptor> String2Descriptor = {
81 
82  RapidXmlReaderNode nodeToUse = node;
83 
84  // check for replacement
85  if (auto it = constantes::REPLACEMENTS.find(simox::alg::to_lower(nodeToUse.name()));
86  it != constantes::REPLACEMENTS.end())
87  {
88  auto replacement = it->second;
89  if (!replacement.deprecatedWarning.empty())
90  {
91  printDeprecationWarning(replacement.deprecatedWarning);
92  }
93 
94  std::string tag = replacement.replacementTag;
96  {
97  tag += " " + std::string(constantes::DEFAULT_ATTRIBUTE_NAME) + "=\"" +
99  }
100 
101  // We make the system believe there is another string in the xml
102  RapidXmlReaderPtr reader = RapidXmlReader::FromXmlString("<" + tag + " />");
103  nodeToUse = reader->getRoot();
104  }
105 
106  auto it = String2Descriptor.find(simox::alg::to_lower(nodeToUse.name()));
107  auto descriptor = (it == String2Descriptor.end() ? type::Descriptor::UNKNOWN : it->second);
108 
109  switch (descriptor)
110  {
112  return createList(nodeToUse, path);
114  return createDict(nodeToUse, path);
116  return createObject(nodeToUse, path);
118  return createTuple(nodeToUse, path);
120  return createPair(nodeToUse, path);
122  return createNDArray(nodeToUse, path);
124  return createMatrix(nodeToUse, path);
126  return createQuaternion(nodeToUse, path);
128  return createImage(nodeToUse, path);
130  return createPointCloud(nodeToUse, path);
132  return createIntEnum(nodeToUse, path);
134  return createInt(nodeToUse, path);
136  return createLong(nodeToUse, path);
138  return createFloat(nodeToUse, path);
140  return createDouble(nodeToUse, path);
142  return createString(nodeToUse, path);
144  return createBool(nodeToUse, path);
146  return createAnyObject(nodeToUse, path);
148  return findExistingObject(nodeToUse.name(), path);
149  }
150 
151  throw aron::error::AronEOFException(__PRETTY_FUNCTION__);
152  }
153 
155  ReaderFactory::findExistingObject(const std::string& name, const Path& path) const
156  {
157  const auto public_intenum_it = allGeneratedPublicIntEnums.find(name);
158  if (public_intenum_it != allGeneratedPublicIntEnums.end())
159  {
160  // copy the navigator
162  *public_intenum_it->second.correspondingType->toAronDTO(), path);
163  return v;
164  }
165 
166  const auto public_obj_it = allGeneratedPublicObjects.find(name);
167  if (public_obj_it != allGeneratedPublicObjects.end())
168  {
169  // copy the navigator and set instantiation template args
171  *public_obj_it->second.correspondingType->toAronDTO(), path);
172  return v;
173  }
174 
175  const auto public_known_it = std::find(
177  if (public_known_it != allPreviouslyKnownPublicTypes.end())
178  {
179  // create an empty navigator
180  auto v = std::make_shared<aron::type::Object>(path);
181  v->setObjectName(*public_known_it);
182  v->setTemplates({});
183  v->setTemplateInstantiations({});
184  v->setMemberTypes({});
185  return v;
186  }
187 
188  // only works during generation process (not for top-level). Used for templates.
189  const auto private_known_it = std::find(
190  allPreviouslyKnownPrivateTypes.begin(), allPreviouslyKnownPrivateTypes.end(), name);
191  if (private_known_it != allPreviouslyKnownPrivateTypes.end())
192  {
193  // create an empty navigator
194  auto v = std::make_shared<aron::type::Object>(path);
195  v->setObjectName(*private_known_it);
196  v->setTemplates({});
197  v->setTemplateInstantiations({});
198  v->setMemberTypes({});
199  return v;
200  }
201 
202  throw error::ValueNotValidException(
203  __PRETTY_FUNCTION__, "Cannot find a valid object.", name);
204  }
205 
206  type::Maybe
207  ReaderFactory::getMaybe(const RapidXmlReaderNode& n) const
208  {
210  {
211  return type::Maybe::OPTIONAL;
212  }
214  {
215  return type::Maybe::RAW_PTR;
216  }
218  {
219  return type::Maybe::SHARED_PTR;
220  }
222  {
223  return type::Maybe::UNIQUE_PTR;
224  }
225  return type::Maybe::NONE;
226  }
227 
228  void
229  ReaderFactory::checkObjectMemberName(const std::string& s) const
230  {
232  {
233  throw error::ValueNotValidException(
234  __PRETTY_FUNCTION__,
235  "You used an invalid membername - '_' as starting or ending char is not allowed.",
236  s);
237  }
238 
239  if (simox::alg::starts_with(s, "aron"))
240  {
241  throw error::ValueNotValidException(
242  __PRETTY_FUNCTION__,
243  "You used an invalid membername - The prefix 'aron' is used for codegeneration.",
244  s);
245  }
246  }
247 
249  ReaderFactory::createObject(const RapidXmlReaderNode& node, const Path& path)
250  {
251  if (path.hasElement())
252  // ensured we are toplevel!
253  {
254  throw error::AronException(
255  __PRETTY_FUNCTION__,
256  "Having an inner class is not supported anymore since Aron Version 'beta 0.2.3'. "
257  "Please move the inner class definition to the <" +
258  std::string(constantes::GENERATE_TYPES_TAG) + ">-tag.");
259  }
260 
261  const std::string name = util::GetAttribute(node, constantes::NAME_ATTRIBUTE_NAME);
262  const std::string extends =
264  auto templates = simox::alg::split(
266 
267  auto newObjectInfo = typereader::GenerateObjectInfo();
268  newObjectInfo.typeName = name;
269  newObjectInfo.doc_brief =
271  newObjectInfo.doc_author =
273 
274  // reset private known types
275  allPreviouslyKnownPrivateTypes = templates;
276 
277  // set objPath
278  aron::Path objPath = path; // copy, just in case there are special things set
279  objPath.setRootIdentifier(name); // set the root identifier to the obj name
280 
281  std::map<std::string, type::VariantPtr> members;
282  for (const RapidXmlReaderNode& objectChild : node.nodes())
283  {
285  util::EnforceChildSize(objectChild, 1);
286 
288  const std::string key = util::GetAttribute(objectChild, constantes::KEY_ATTRIBUTE_NAME);
289 
290  checkObjectMemberName(key);
291 
293  {
294  newObjectInfo.doc_members.insert(
296  }
297 
298  std::vector<RapidXmlReaderNode> children = objectChild.nodes();
299 
300  auto maybe = getMaybe(children[0]);
301  type::VariantPtr childNavigator = create(children[0], objPath.withElement(key));
302 
303  if (childNavigator->getDescriptor() == aron::type::Descriptor::OBJECT)
304  {
305  // check if template args are present
306  std::vector<std::string> templates =
308  children[0], constantes::TEMPLATE_ATTRIBUTE_NAME, ""),
309  ",");
310  auto obj = aron::type::Object::DynamicCastAndCheck(childNavigator);
311  for (const auto& t : templates)
312  {
313  obj->addTemplateInstantiation(t);
314  }
315  }
316 
317  childNavigator->setMaybe(maybe);
318  members.insert({key, childNavigator});
319  }
320 
321  // set the new object
322  auto aronObjectType = std::make_shared<type::Object>(objPath);
323  aronObjectType->setObjectName(name);
324  aronObjectType->setTemplates(templates);
325  aronObjectType->setTemplateInstantiations({});
326  aronObjectType->setMemberTypes(members);
327 
328  if (extends != "")
329  {
330  auto parentObj = type::Object::DynamicCastAndCheck(findExistingObject(extends, Path()));
331  aronObjectType->setExtends(parentObj);
332  }
333 
334  newObjectInfo.correspondingType = aronObjectType;
335  allGeneratedPublicObjects.emplace(newObjectInfo.typeName, newObjectInfo);
336 
337  allPreviouslyKnownPrivateTypes.clear();
338  return aronObjectType;
339  }
340 
342  ReaderFactory::createList(const RapidXmlReaderNode& node, const Path& path)
343  {
344  util::EnforceChildSize(node, 1);
345 
346  std::vector<RapidXmlReaderNode> c = node.nodes();
347  const RapidXmlReaderNode typeNode = c[0];
348  type::VariantPtr type = create(typeNode, path.withAcceptedType());
349  type->setMaybe(getMaybe(typeNode));
350 
351  auto o = std::make_shared<type::List>(path);
352  o->setAcceptedType(type);
353  return o;
354  }
355 
357  ReaderFactory::createDict(const RapidXmlReaderNode& node, const Path& path)
358  {
359  util::EnforceChildSize(node, 1);
360 
361  std::vector<RapidXmlReaderNode> c = node.nodes();
362  const RapidXmlReaderNode typeNode = c[0];
363  type::VariantPtr type = create(typeNode, path.withAcceptedType());
364  type->setMaybe(getMaybe(typeNode));
365 
366  auto o = std::make_shared<type::Dict>(path);
367  o->setAcceptedType(type);
368  return o;
369  }
370 
372  ReaderFactory::createTuple(const RapidXmlReaderNode& node, const Path& path)
373  {
375 
376  unsigned int i = 0;
377  std::vector<RapidXmlReaderNode> c = node.nodes();
378  std::vector<type::VariantPtr> elementTypes;
379  for (const RapidXmlReaderNode& tupleTypeDeclarationNode : c)
380  {
381  util::EnforceChildSize(tupleTypeDeclarationNode, 1);
382 
383  std::vector<RapidXmlReaderNode> typeNodeChildren = tupleTypeDeclarationNode.nodes();
384  const RapidXmlReaderNode typeNode = typeNodeChildren[0];
385 
386  type::VariantPtr type = create(typeNode, path.withAcceptedTypeIndex(i++));
387  type->setMaybe(getMaybe(typeNode));
388 
389  elementTypes.push_back(type);
390  }
391 
392  auto o = std::make_shared<type::Tuple>(path);
393  o->setAcceptedTypes(elementTypes);
394  return o;
395  }
396 
398  ReaderFactory::createPair(const RapidXmlReaderNode& node, const Path& path)
399  {
400  util::EnforceChildSize(node, 2);
401 
402  std::vector<RapidXmlReaderNode> c = node.nodes();
403  const RapidXmlReaderNode type1Node = c[0];
404 
405  type::VariantPtr type1 = create(type1Node, path.withAcceptedTypeIndex(0));
406  type1->setMaybe(getMaybe(type1Node));
407 
408  const RapidXmlReaderNode type2Node = c[1];
409  type::VariantPtr type2 = create(type2Node, path.withAcceptedTypeIndex(1));
410  type2->setMaybe(getMaybe(type2Node));
411 
412  auto o = std::make_shared<type::Pair>(path);
413  o->setFirstAcceptedType(type1);
414  o->setSecondAcceptedType(type2);
415  return o;
416  }
417 
419  ReaderFactory::createNDArray(const RapidXmlReaderNode& node, const Path& path) const
420  {
421  static const std::map<std::string, type::ndarray::ElementType> String2NDArrayType = {
422  {constantes::CHAR_SLUG, type::ndarray::ElementType::INT8},
423  {constantes::SHORT_SLUG, type::ndarray::ElementType::INT16},
424  {constantes::INT_SLUG, type::ndarray::ElementType::INT32},
425  {constantes::LONG_SLUG, type::ndarray::ElementType::UINT8},
426  {constantes::USHORT_SLUG, type::ndarray::ElementType::UINT16},
427  {constantes::UINT_SLUG, type::ndarray::ElementType::UINT32},
428  {constantes::FLOAT_SLUG, type::ndarray::ElementType::FLOAT32},
429  {constantes::DOUBLE_SLUG, type::ndarray::ElementType::FLOAT64}};
430 
431  static const std::map<std::string, std::string> StringSlug2NDArrayDefaultValue = {
432  {constantes::ONES_SLUG, type::ndarray::default_value::ONES},
433  {constantes::ZEROS_SLUG, type::ndarray::default_value::ZEROS}};
434 
435  auto o = std::make_shared<type::NDArray>(path);
436  util::EnforceChildSize(node, 0);
438 
439  // TODO
440 
441  return nullptr;
442  }
443 
445  ReaderFactory::createMatrix(const RapidXmlReaderNode& node, const Path& path) const
446  {
447  static const std::map<std::string, type::matrix::ElementType> StringSlug2MatrixType = {
448  {constantes::UCHAR_SLUG, type::matrix::ElementType::UINT8},
449  {constantes::USHORT_SLUG, type::matrix::ElementType::UINT16},
450  {constantes::UINT_SLUG, type::matrix::ElementType::UINT32},
451  {constantes::CHAR_SLUG, type::matrix::ElementType::INT8},
452  {constantes::SHORT_SLUG, type::matrix::ElementType::INT16},
453  {constantes::INT_SLUG, type::matrix::ElementType::INT32},
454  {constantes::LONG_SLUG, type::matrix::ElementType::INT64},
455  {constantes::FLOAT_SLUG, type::matrix::ElementType::FLOAT32},
456  {constantes::DOUBLE_SLUG, type::matrix::ElementType::FLOAT64}};
457 
458  static const std::map<std::string, std::string> StringSlug2MatrixDefaultValue = {
459  {constantes::IDENTITY_SLUG, type::matrix::default_value::IDENTITY},
460  {constantes::ONES_SLUG, type::matrix::default_value::ONES},
461  {constantes::ZEROS_SLUG, type::matrix::default_value::ZEROS}};
462 
463  auto o = std::make_shared<type::Matrix>(path);
464  util::EnforceChildSize(node, 0);
465 
468 
469  // check for unknown size
470  if (std::find(constantes::WHATEVER_VALUES.begin(),
472  simox::alg::to_lower(rows_str)) != constantes::WHATEVER_VALUES.end())
473  {
474  rows_str = "-1";
475  }
476  if (std::find(constantes::WHATEVER_VALUES.begin(),
478  simox::alg::to_lower(cols_str)) != constantes::WHATEVER_VALUES.end())
479  {
480  cols_str = "-1";
481  }
482 
483  const int rows = std::stoi(rows_str);
484  const int cols = std::stoi(cols_str);
485 
486  // set rows and cols
487  o->setRows(rows);
488  o->setCols(cols);
489 
490  // get type
491  std::string type = util::GetAttribute(node, constantes::TYPE_ATTRIBUTE_NAME);
492 
494  StringSlug2MatrixType.count(simox::alg::to_lower(type)),
495  error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not resolve type", type));
496 
497  // set elem type
498  o->setElementType(StringSlug2MatrixType.at(simox::alg::to_lower(type)));
499 
500  // set default
501  const std::string def = simox::alg::to_lower(util::GetAttributeWithDefault(
502  node, constantes::DEFAULT_ATTRIBUTE_NAME, type::matrix::default_value::DEFAULT));
503 
504  if (const auto it = StringSlug2MatrixDefaultValue.find(def);
505  it != StringSlug2MatrixDefaultValue.end())
506  {
507  o->setDefaultValue(it->second);
508  }
509  else if (def == type::matrix::default_value::DEFAULT)
510  {
511  o->setDefaultValue(def);
512  }
513  else
514  {
516  o->setDefaultValue(def);
517  }
518 
519  return o;
520  }
521 
523  ReaderFactory::createQuaternion(const RapidXmlReaderNode& node, const Path& path) const
524  {
525  static const std::map<std::string, type::quaternion::ElementType>
526  StringSlug2QuaternionType = {
527  {constantes::FLOAT_SLUG, type::quaternion::ElementType::FLOAT32},
528  {constantes::DOUBLE_SLUG, type::quaternion::ElementType::FLOAT64}};
529 
530  static const std::map<std::string, std::string> StringSlug2QuaternionDefaultValue = {
531  {constantes::ONES_SLUG, type::quaternion::default_value::ONES},
532  {constantes::ZEROS_SLUG, type::quaternion::default_value::ZEROS}};
533 
534  auto o = std::make_shared<type::Quaternion>(path);
535  util::EnforceChildSize(node, 0);
537 
538  // set elem type
539  std::string type = util::GetAttribute(node, constantes::TYPE_ATTRIBUTE_NAME);
541  StringSlug2QuaternionType.count(simox::alg::to_lower(type)),
542  error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not resolve type", type));
543 
544  o->setElementType(StringSlug2QuaternionType.at(simox::alg::to_lower(type)));
545 
546  // set default
547  const std::string def = simox::alg::to_lower(util::GetAttributeWithDefault(
548  node, constantes::DEFAULT_ATTRIBUTE_NAME, type::quaternion::default_value::DEFAULT));
549 
550  if (const auto it = StringSlug2QuaternionDefaultValue.find(def);
551  it != StringSlug2QuaternionDefaultValue.end())
552  {
553  o->setDefaultValue(it->second);
554  }
555  else if (def == type::quaternion::default_value::DEFAULT)
556  {
557  o->setDefaultValue(def);
558  }
559  else
560  {
562  o->setDefaultValue(def);
563  }
564 
565  return o;
566  }
567 
569  ReaderFactory::createImage(const RapidXmlReaderNode& node, const Path& path) const
570  {
571  static const std::map<std::string, type::image::PixelType> String2PixelType = {
572  {constantes::RGB_SLUG, type::image::PixelType::RGB24},
573  {constantes::DEPTH_SLUG, type::image::PixelType::DEPTH32}};
574 
575  static const std::map<std::string, std::string> StringSlug2ImageDefaultValue = {
576  {constantes::IDENTITY_SLUG, type::image::default_value::IDENTITY},
577  {constantes::ONES_SLUG, type::image::default_value::ONES},
578  {constantes::ZEROS_SLUG, type::image::default_value::ZEROS}};
579 
580  auto o = std::make_shared<type::Image>(path);
581  util::EnforceChildSize(node, 0);
583 
584  // set elem type
585  std::string type = util::GetAttribute(node, constantes::TYPE_ATTRIBUTE_NAME);
586 
588  String2PixelType.count(simox::alg::to_lower(type)),
589  error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not resolve type", type));
590 
591  o->setPixelType(String2PixelType.at(simox::alg::to_lower(type)));
592 
593  // set default
594  const std::string def = simox::alg::to_lower(util::GetAttributeWithDefault(
595  node, constantes::DEFAULT_ATTRIBUTE_NAME, type::image::default_value::DEFAULT));
596 
597  if (const auto it = StringSlug2ImageDefaultValue.find(def);
598  it != StringSlug2ImageDefaultValue.end())
599  {
600  o->setDefaultValue(it->second);
601  }
602  else if (def == type::image::default_value::DEFAULT)
603  {
604  o->setDefaultValue(def);
605  }
606  else
607  {
609  o->setDefaultValue(def);
610  }
611 
612  return o;
613  }
614 
616  ReaderFactory::createPointCloud(const RapidXmlReaderNode& node, const Path& path) const
617  {
618  static const std::map<std::string, type::pointcloud::VoxelType> StringSlug2VoxelType = {
619  {constantes::POINT_XYZ_SLUG, type::pointcloud::VoxelType::POINT_XYZ},
620  {constantes::POINT_XYZI_SLUG, type::pointcloud::VoxelType::POINT_XYZI},
621  {constantes::POINT_XYZL_SLUG, type::pointcloud::VoxelType::POINT_XYZL},
622  {constantes::POINT_XYZRGB_SLUG, type::pointcloud::VoxelType::POINT_XYZRGB},
623  {constantes::POINT_XYZRGBL_SLUG, type::pointcloud::VoxelType::POINT_XYZRGBL},
624  {constantes::POINT_XYZRGBA_SLUG, type::pointcloud::VoxelType::POINT_XYZRGBA},
625  {constantes::POINT_XYZHSV_SLUG, type::pointcloud::VoxelType::POINT_XYZHSV}};
626 
627  static const std::map<std::string, std::string> StringSlug2PointCloudDefaultValue = {
628  {constantes::IDENTITY_SLUG, type::pointcloud::default_value::IDENTITY},
629  {constantes::ONES_SLUG, type::pointcloud::default_value::ONES},
630  {constantes::ZEROS_SLUG, type::pointcloud::default_value::ZEROS}};
631 
632  auto o = std::make_shared<type::PointCloud>(path);
633  util::EnforceChildSize(node, 0);
634 
635  // set elem type
636  std::string type = util::GetAttribute(node, constantes::TYPE_ATTRIBUTE_NAME);
637 
639  StringSlug2VoxelType.count(simox::alg::to_lower(type)),
640  error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not resolve type", type));
641 
642  o->setVoxelType(StringSlug2VoxelType.at(simox::alg::to_lower(type)));
643 
644  // set default
645  const std::string def = simox::alg::to_lower(util::GetAttributeWithDefault(
646  node, constantes::DEFAULT_ATTRIBUTE_NAME, type::pointcloud::default_value::DEFAULT));
647 
648  if (const auto it = StringSlug2PointCloudDefaultValue.find(def);
649  it != StringSlug2PointCloudDefaultValue.end())
650  {
651  o->setDefaultValue(it->second);
652  }
653  else if (def == type::pointcloud::default_value::DEFAULT)
654  {
655  o->setDefaultValue(def);
656  }
657  else
658  {
660  o->setDefaultValue(def);
661  }
662 
663  return o;
664  }
665 
667  ReaderFactory::createIntEnum(const RapidXmlReaderNode& node, const Path& path)
668  {
669  if (path.hasElement())
670  // ensured we are top-level!
671  {
672  throw error::AronException(
673  __PRETTY_FUNCTION__,
674  "Having an inner int-enum is not supported anymore since Aron Version 'beta "
675  "0.2.3'. Please move the inner int-enum definition to the <" +
676  std::string(constantes::GENERATE_TYPES_TAG) + ">-tag.");
677  }
678 
679  const std::string name = util::GetAttribute(node, constantes::NAME_ATTRIBUTE_NAME);
680 
681  auto newEnumInfo = typereader::GenerateIntEnumInfo();
682  newEnumInfo.typeName = name;
683 
684  allPreviouslyKnownPrivateTypes.clear();
685 
686  std::string defaultValue = util::GetAttributeWithDefault(
687  node, constantes::DEFAULT_ATTRIBUTE_NAME, type::aron_enum::default_value::DEFAULT);
688 
689  // get accepted values
690  std::map<std::string, int> acceptedValues;
691  for (const RapidXmlReaderNode& valueChild : node.nodes())
692  {
694  util::EnforceChildSize(valueChild, 0);
695 
696  const std::string key = util::GetAttribute(valueChild, constantes::KEY_ATTRIBUTE_NAME);
697 
699  {
700  newEnumInfo.doc_values.insert(
702  }
703 
704  const std::string value =
706 
707  // Overwrite default value if child is tagged as default
709  {
710  defaultValue = key;
711  }
712 
713  acceptedValues.emplace(key, std::stoi(value));
714  }
715 
716  if (acceptedValues.size() == 0)
717  {
718  printWarning("Found enum '" + name + "' without any members...");
719  }
720 
721  // check default value
722  if (defaultValue != type::aron_enum::default_value::DEFAULT and
723  not acceptedValues.count(defaultValue))
724  {
725  throw error::ValueNotValidException(__PRETTY_FUNCTION__,
726  "An int enum has a non existing default value set",
727  defaultValue);
728  }
729 
730 
731  // create the int enum
732  aron::Path enumPath = path; // copy, just in case there are special things set
733  enumPath.setRootIdentifier(name); // set the root identifier to the obj name
734  auto o = std::make_shared<type::IntEnum>(enumPath);
735  o->setEnumName(name);
736  o->setAcceptedValueMap(acceptedValues);
737  o->setDefaultValueName(defaultValue);
738  newEnumInfo.correspondingType = o;
739 
740  allGeneratedPublicIntEnums.emplace(newEnumInfo.typeName, newEnumInfo);
741 
742  allPreviouslyKnownPrivateTypes.clear();
743  return o;
744  }
745 
747  ReaderFactory::createInt(const RapidXmlReaderNode& node, const Path& path) const
748  {
749  auto o = std::make_shared<type::Int>(path);
750 
752  {
753  const std::string def = util::GetAttribute(node, constantes::DEFAULT_ATTRIBUTE_NAME);
755  o->setDefaultValue(simox::alg::to_<int>(def));
756  }
757 
758  return o;
759  }
760 
762  ReaderFactory::createLong(const RapidXmlReaderNode& node, const Path& path) const
763  {
764  auto o = std::make_shared<type::Long>(path);
765 
767  {
768  const std::string def = util::GetAttribute(node, constantes::DEFAULT_ATTRIBUTE_NAME);
770  o->setDefaultValue(simox::alg::to_<long>(def));
771  }
772 
773  return o;
774  }
775 
777  ReaderFactory::createFloat(const RapidXmlReaderNode& node, const Path& path) const
778  {
779  auto o = std::make_shared<type::Float>(path);
780 
782  {
783  const std::string def = util::GetAttribute(node, constantes::DEFAULT_ATTRIBUTE_NAME);
785  o->setDefaultValue(simox::alg::to_<float>(def));
786  }
787 
788  return o;
789  }
790 
792  ReaderFactory::createDouble(const RapidXmlReaderNode& node, const Path& path) const
793  {
794  auto o = std::make_shared<type::Double>(path);
795 
797  {
798  const std::string def = util::GetAttribute(node, constantes::DEFAULT_ATTRIBUTE_NAME);
800  o->setDefaultValue(simox::alg::to_<double>(def));
801  }
802 
803  return o;
804  }
805 
807  ReaderFactory::createString(const RapidXmlReaderNode& node, const Path& path) const
808  {
809  auto o = std::make_shared<type::String>(path);
810 
812  {
813  const std::string def = util::GetAttribute(node, constantes::DEFAULT_ATTRIBUTE_NAME);
814  o->setDefaultValue(def);
815  }
816 
817  return o;
818  }
819 
821  ReaderFactory::createBool(const RapidXmlReaderNode& node, const Path& path) const
822  {
823  auto o = std::make_shared<type::Bool>(path);
824 
826  {
827  const std::string def = util::GetAttribute(node, constantes::DEFAULT_ATTRIBUTE_NAME);
829  o->setDefaultValue(simox::alg::to_<bool>(def));
830  }
831 
832  return o;
833  }
834 
836  ReaderFactory::createAnyObject(const RapidXmlReaderNode& node, const Path& path) const
837  {
838  return std::make_shared<type::AnyObject>(path);
839  }
840 } // namespace armarx::aron::typereader::xml
armarx::RapidXmlReaderPtr
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
Definition: RapidXmlReader.h:66
armarx::aron::type::Descriptor::FLOAT
@ FLOAT
armarx::aron::type::Descriptor::DOUBLE
@ DOUBLE
armarx::aron::typereader::xml::util::HasAttribute
bool HasAttribute(const RapidXmlReaderNode &node, const std::string &att)
Definition: Data.cpp:174
armarx::aron::typereader::xml::constantes::VALUE_ATTRIBUTE_NAME
const constexpr auto VALUE_ATTRIBUTE_NAME
Definition: Data.h:65
armarx::aron::typereader::xml::constantes::FLOAT_TAG
const constexpr auto FLOAT_TAG
Definition: Data.h:135
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::data::rw::json::conversion::String2NDArrayType
const auto String2NDArrayType
Definition: Data.h:96
armarx::aron::typereader::xml::constantes::RGB_SLUG
const constexpr auto RGB_SLUG
Definition: Data.h:90
Data.h
armarx::aron::type::Descriptor::IMAGE
@ IMAGE
armarx::aron::typereader::xml::constantes::TUPLE_TAG
const constexpr auto TUPLE_TAG
Definition: Data.h:120
armarx::aron::type::Variant::FromAronDTO
static VariantPtr FromAronDTO(const type::dto::GenericType &, const Path &=Path())
create a variant object from an dto object
Definition: Variant.cpp:39
armarx::aron::typereader::xml::constantes::STRING_TAG
const constexpr auto STRING_TAG
Definition: Data.h:137
armarx::aron::typereader::xml::util::GetAttributeWithDefault
std::string GetAttributeWithDefault(const RapidXmlReaderNode &node, const std::string &att, const std::string &def)
Definition: Data.cpp:187
armarx::aron::typereader::xml::constantes::POINT_XYZRGB_SLUG
const constexpr auto POINT_XYZRGB_SLUG
Definition: Data.h:95
Factory.h
armarx::aron::typereader::xml::constantes::NDARRAY_TAG
const constexpr auto NDARRAY_TAG
Definition: Data.h:122
armarx::RapidXmlReader::FromXmlString
static RapidXmlReaderPtr FromXmlString(const std::string &xml)
Definition: RapidXmlReader.h:491
armarx::aron::typereader::xml::constantes::POINT_XYZRGBA_SLUG
const constexpr auto POINT_XYZRGBA_SLUG
Definition: Data.h:97
armarx::aron::typereader::xml::constantes::ENUM_VALUE_TAG
const constexpr auto ENUM_VALUE_TAG
Definition: Data.h:113
armarx::aron::typereader::xml::constantes::DOUBLE_TAG
const constexpr auto DOUBLE_TAG
Definition: Data.h:136
armarx::aron::typereader::xml::util::EnforceTagName
void EnforceTagName(const RapidXmlReaderNode &node, const std::string &name)
Definition: Data.cpp:219
DateTime.h
armarx::aron::typereader::xml::constantes::ANY_OBJECT_TAG
const constexpr auto ANY_OBJECT_TAG
Definition: Data.h:139
armarx::aron::typereader::xml::util::EnforceStrIsInt
void EnforceStrIsInt(const std::string &)
Definition: Data.cpp:47
armarx::aron::typereader::xml::ReaderFactory::allPreviouslyKnownPublicTypes
std::vector< std::string > allPreviouslyKnownPublicTypes
previously known types
Definition: Factory.h:97
armarx::aron::type::Descriptor::PAIR
@ PAIR
armarx::aron::type::Descriptor::LIST
@ LIST
armarx::aron::typereader::xml::util::EnforceChildSize
void EnforceChildSize(const RapidXmlReaderNode &node, const size_t size)
Definition: Data.cpp:279
All.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::aron::typereader::xml
All constantes for the aron XML parser, in addition to some utility functions wrapping around the arm...
Definition: Data.cpp:30
armarx::aron::typereader::xml::constantes::POINT_XYZ_SLUG
const constexpr auto POINT_XYZ_SLUG
Definition: Data.h:92
armarx::aron::type::Descriptor::NDARRAY
@ NDARRAY
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:43
armarx::aron::typereader::xml::constantes::TEMPLATE_ATTRIBUTE_NAME
const constexpr auto TEMPLATE_ATTRIBUTE_NAME
Definition: Data.h:66
armarx::aron::typereader::xml::ReaderFactory::allGeneratedPublicObjects
std::map< std::string, typereader::GenerateObjectInfo > allGeneratedPublicObjects
static map of all generated objects. Since this factory may be called recursively,...
Definition: Factory.h:91
armarx::aron::typereader::xml::constantes::POINT_XYZHSV_SLUG
const constexpr auto POINT_XYZHSV_SLUG
Definition: Data.h:98
armarx::aron::typereader::xml::constantes::CHAR_SLUG
const constexpr auto CHAR_SLUG
Definition: Data.h:100
armarx::aron::typereader::xml::constantes::PAIR_TAG
const constexpr auto PAIR_TAG
Definition: Data.h:119
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::typereader::xml::constantes::ZEROS_SLUG
const constexpr auto ZEROS_SLUG
Definition: Data.h:88
ARMARX_CHECK_AND_THROW
#define ARMARX_CHECK_AND_THROW(expression, ExceptionType)
This macro evaluates the expression and if it turns out to be false it will throw an exception of the...
Definition: ExpressionException.h:245
armarx::aron::type::Descriptor::BOOL
@ BOOL
armarx::aron::typereader::xml::constantes::ONES_SLUG
const constexpr auto ONES_SLUG
Definition: Data.h:89
armarx::RapidXmlReaderNode::name
std::string name() const
Definition: RapidXmlReader.h:349
armarx::aron::typereader::xml::constantes::DOC_AUTHOR_ATTRIBUTE_NAME
const constexpr auto DOC_AUTHOR_ATTRIBUTE_NAME
Definition: Data.h:81
armarx::aron::typereader::xml::util::EnforceStrIsNumberSeq
void EnforceStrIsNumberSeq(const std::string &)
Definition: Data.cpp:111
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::aron::typereader::xml::constantes::UINT_SLUG
const constexpr auto UINT_SLUG
Definition: Data.h:105
armarx::aron::error::AronEOFException
Definition: Exception.h:72
armarx::aron::typereader::xml::constantes::COLS_ATTRIBUTE_NAME
const constexpr auto COLS_ATTRIBUTE_NAME
Definition: Data.h:72
armarx::aron::typereader::xml::constantes::POINT_XYZL_SLUG
const constexpr auto POINT_XYZL_SLUG
Definition: Data.h:94
armarx::aron::typereader::xml::constantes::DOUBLE_SLUG
const constexpr auto DOUBLE_SLUG
Definition: Data.h:109
armarx::aron::typereader::xml::constantes::WHATEVER_VALUES
const std::vector< std::string > WHATEVER_VALUES
Definition: Data.h:142
armarx::aron::typereader::xml::constantes::MATRIX_TAG
const constexpr auto MATRIX_TAG
Definition: Data.h:123
armarx::aron::type::Descriptor::MATRIX
@ MATRIX
armarx::aron::typereader::xml::constantes::LONG_TAG
const constexpr auto LONG_TAG
Definition: Data.h:133
armarx::aron::typereader::xml::constantes::INT_TAG
const constexpr auto INT_TAG
Definition: Data.h:131
armarx::aron::typereader::xml::constantes::FLOAT_SLUG
const constexpr auto FLOAT_SLUG
Definition: Data.h:108
armarx::aron::typereader::xml::constantes::QUATERNION_TAG
const constexpr auto QUATERNION_TAG
Definition: Data.h:124
armarx::aron::typereader::xml::constantes::DICT_TAG
const constexpr auto DICT_TAG
Definition: Data.h:117
armarx::aron::typereader::xml::constantes::BOOL_TAG
const constexpr auto BOOL_TAG
Definition: Data.h:138
armarx::aron::typereader::xml::constantes::LONG_SLUG
const constexpr auto LONG_SLUG
Definition: Data.h:106
armarx::RapidXmlReaderNode
Definition: RapidXmlReader.h:68
armarx::aron::type::Descriptor::QUATERNION
@ QUATERNION
armarx::aron::typereader::xml::constantes::REPLACEMENTS
const std::map< std::string, Replacement > REPLACEMENTS
Definition: Data.h:152
armarx::aron::typereader::xml::printWarning
void printWarning(const std::string &warning)
Definition: Factory.cpp:54
armarx::aron::typereader::xml::constantes::POINT_CLOUD_TAG
const constexpr auto POINT_CLOUD_TAG
Definition: Data.h:126
armarx::aron::typereader::xml::printDeprecationWarning
void printDeprecationWarning(const std::string &warning)
Definition: Factory.cpp:42
armarx::aron::data::rw::json::conversion::String2PixelType
const auto String2PixelType
Definition: Data.h:124
armarx::aron::typereader::xml::constantes::EXTENDS_ATTRIBUTE_NAME
const constexpr auto EXTENDS_ATTRIBUTE_NAME
Definition: Data.h:63
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::aron::typereader::xml::constantes::TYPE_ATTRIBUTE_NAME
const constexpr auto TYPE_ATTRIBUTE_NAME
Definition: Data.h:68
armarx::aron::typereader::xml::constantes::POINT_XYZI_SLUG
const constexpr auto POINT_XYZI_SLUG
Definition: Data.h:93
armarx::aron::typereader::xml::constantes::SHORT_SLUG
const constexpr auto SHORT_SLUG
Definition: Data.h:102
armarx::aron::typereader::xml::constantes::SHARED_PTR_ATTRIBUTE_NAME
const constexpr auto SHARED_PTR_ATTRIBUTE_NAME
Definition: Data.h:77
armarx::aron::type::Descriptor::STRING
@ STRING
armarx::aron::type::Descriptor::LONG
@ LONG
armarx::aron::typereader::xml::constantes::OPTIONAL_ATTRIBUTE_NAME
const constexpr auto OPTIONAL_ATTRIBUTE_NAME
Definition: Data.h:75
armarx::aron::typereader::xml::constantes::IMAGE_TAG
const constexpr auto IMAGE_TAG
Definition: Data.h:125
armarx::aron::typereader::xml::util::EnforceStrIsFloat
void EnforceStrIsFloat(const std::string &)
Definition: Data.cpp:71
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::typereader::xml::constantes::DEPTH_SLUG
const constexpr auto DEPTH_SLUG
Definition: Data.h:91
armarx::aron::type::Descriptor::INT
@ INT
armarx::aron::typereader::xml::util::GetAttribute
std::string GetAttribute(const RapidXmlReaderNode &node, const std::string &att)
Definition: Data.cpp:180
armarx::aron::typereader::xml::constantes::DOC_BRIEF_ATTRIBUTE_NAME
const constexpr auto DOC_BRIEF_ATTRIBUTE_NAME
Definition: Data.h:80
armarx::aron::typereader::xml::util::EnforceAttribute
void EnforceAttribute(const RapidXmlReaderNode &node, const std::string &att)
Definition: Data.cpp:162
armarx::aron::typereader::xml::constantes::NAME_ATTRIBUTE_NAME
const constexpr auto NAME_ATTRIBUTE_NAME
Definition: Data.h:64
armarx::aron::data::rw::json::conversion::String2Descriptor
const auto String2Descriptor
Definition: Data.h:73
armarx::aron::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:11
armarx::aron::typereader::xml::constantes::LIST_TAG
const constexpr auto LIST_TAG
Definition: Data.h:116
armarx::aron::typereader::xml::constantes::UNIQUE_PTR_ATTRIBUTE_NAME
const constexpr auto UNIQUE_PTR_ATTRIBUTE_NAME
Definition: Data.h:78
armarx::aron::type::Descriptor::INT_ENUM
@ INT_ENUM
armarx::aron::type::Descriptor::OBJECT
@ OBJECT
armarx::aron::typereader::xml::constantes::INT_ENUM_TAG
const constexpr auto INT_ENUM_TAG
Definition: Data.h:121
armarx::aron::typereader::xml::constantes::KEY_ATTRIBUTE_NAME
const constexpr auto KEY_ATTRIBUTE_NAME
Definition: Data.h:67
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:50
armarx::aron::typereader::xml::constantes::USHORT_SLUG
const constexpr auto USHORT_SLUG
Definition: Data.h:103
armarx::aron::type::Descriptor::UNKNOWN
@ UNKNOWN
armarx::aron::type::detail::SpecializedVariantBase< type::dto::AronObject, Object >::DynamicCastAndCheck
static std::shared_ptr< Object > DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:124
armarx::aron::type::Descriptor::DICT
@ DICT
armarx::aron::type::Descriptor::TUPLE
@ TUPLE
armarx::aron::typereader::xml::constantes::GENERATE_TYPES_TAG
const constexpr auto GENERATE_TYPES_TAG
Definition: Data.h:52
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::aron::typereader::xml::constantes::INT_SLUG
const constexpr auto INT_SLUG
Definition: Data.h:104
armarx::aron::typereader::xml::util::EnforceStrIsBool
void EnforceStrIsBool(const std::string &)
Definition: Data.cpp:138
armarx::aron::type::Descriptor::POINTCLOUD
@ POINTCLOUD
armarx::aron::typereader::xml::constantes::OBJECT_CHILD_TAG
const constexpr auto OBJECT_CHILD_TAG
Definition: Data.h:112
armarx::aron::typereader::xml::constantes::DEFAULT_ATTRIBUTE_NAME
const constexpr auto DEFAULT_ATTRIBUTE_NAME
Definition: Data.h:84
armarx::aron::typereader::xml::ReaderFactory::allGeneratedPublicIntEnums
std::map< std::string, typereader::GenerateIntEnumInfo > allGeneratedPublicIntEnums
same for int enums
Definition: Factory.h:94
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::aron::typereader::xml::constantes::RAW_PTR_ATTRIBUTE_NAME
const constexpr auto RAW_PTR_ATTRIBUTE_NAME
Definition: Data.h:76
armarx::aron::typereader::xml::constantes::UCHAR_SLUG
const constexpr auto UCHAR_SLUG
Definition: Data.h:101
armarx::aron::typereader::xml::util::EnforceChildSizeGreater
void EnforceChildSizeGreater(const RapidXmlReaderNode &node, const size_t size)
Definition: Data.cpp:307
armarx::aron::type::Descriptor::ANY_OBJECT
@ ANY_OBJECT
armarx::aron::typereader::xml::util::EnforceStrIsNumber
void EnforceStrIsNumber(const std::string &)
Definition: Data.cpp:87
armarx::aron::typereader::xml::ReaderFactory::create
type::VariantPtr create(const RapidXmlReaderNode &, const Path &)
the creation methods to return the types. Basically does a switch-case over the xml tag names convert...
Definition: Factory.cpp:60
armarx::aron::typereader::xml::constantes::POINT_XYZRGBL_SLUG
const constexpr auto POINT_XYZRGBL_SLUG
Definition: Data.h:96
armarx::aron::typereader::xml::constantes::ROWS_ATTRIBUTE_NAME
const constexpr auto ROWS_ATTRIBUTE_NAME
Definition: Data.h:71
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36
armarx::aron::typereader::xml::constantes::IDENTITY_SLUG
const constexpr auto IDENTITY_SLUG
Definition: Data.h:87
armarx::aron::typereader::xml::constantes::OBJECT_TAG
const constexpr auto OBJECT_TAG
Definition: Data.h:118
armarx::aron::typereader::xml::util::AttributeIsTrue
bool AttributeIsTrue(const RapidXmlReaderNode &node, const std::string &att)
Definition: Data.cpp:199