27 #include <SimoxUtility/algorithm/string.h>
44 auto v = armarx::aron::Version();
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"
56 std::cout <<
"\033[1;33m[**Aron warning**]: " << warning <<
"\033[0m" << std::endl;
88 auto replacement = it->second;
89 if (!replacement.deprecatedWarning.empty())
94 std::string tag = replacement.replacementTag;
103 nodeToUse = reader->getRoot();
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);
155 ReaderFactory::findExistingObject(
const std::string& name,
const Path& path)
const
162 *public_intenum_it->second.correspondingType->toAronDTO(), path);
171 *public_obj_it->second.correspondingType->toAronDTO(), path);
175 const auto public_known_it = std::find(
180 auto v = std::make_shared<aron::type::Object>(path);
181 v->setObjectName(*public_known_it);
183 v->setTemplateInstantiations({});
184 v->setMemberTypes({});
189 const auto private_known_it = std::find(
190 allPreviouslyKnownPrivateTypes.begin(), allPreviouslyKnownPrivateTypes.end(), name);
191 if (private_known_it != allPreviouslyKnownPrivateTypes.end())
194 auto v = std::make_shared<aron::type::Object>(path);
195 v->setObjectName(*private_known_it);
197 v->setTemplateInstantiations({});
198 v->setMemberTypes({});
202 throw error::ValueNotValidException(
203 __PRETTY_FUNCTION__,
"Cannot find a valid object.", name);
207 ReaderFactory::getMaybe(
const RapidXmlReaderNode& n)
const
211 return type::Maybe::OPTIONAL;
215 return type::Maybe::RAW_PTR;
219 return type::Maybe::SHARED_PTR;
223 return type::Maybe::UNIQUE_PTR;
229 ReaderFactory::checkObjectMemberName(
const std::string&
s)
const
233 throw error::ValueNotValidException(
235 "You used an invalid membername - '_' as starting or ending char is not allowed.",
241 throw error::ValueNotValidException(
243 "You used an invalid membername - The prefix 'aron' is used for codegeneration.",
249 ReaderFactory::createObject(
const RapidXmlReaderNode& node,
const Path& path)
251 if (path.hasElement())
254 throw error::AronException(
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 <" +
262 const std::string extends =
267 auto newObjectInfo = typereader::GenerateObjectInfo();
268 newObjectInfo.typeName = name;
269 newObjectInfo.doc_brief =
271 newObjectInfo.doc_author =
275 allPreviouslyKnownPrivateTypes = templates;
279 objPath.setRootIdentifier(name);
281 std::map<std::string, type::VariantPtr> members;
282 for (
const RapidXmlReaderNode& objectChild : node.nodes())
290 checkObjectMemberName(key);
294 newObjectInfo.doc_members.insert(
298 std::vector<RapidXmlReaderNode> children = objectChild.nodes();
300 auto maybe = getMaybe(children[0]);
306 std::vector<std::string> templates =
311 for (
const auto& t : templates)
313 obj->addTemplateInstantiation(t);
317 childNavigator->setMaybe(maybe);
318 members.insert({key, childNavigator});
322 auto aronObjectType = std::make_shared<type::Object>(objPath);
323 aronObjectType->setObjectName(name);
324 aronObjectType->setTemplates(templates);
325 aronObjectType->setTemplateInstantiations({});
326 aronObjectType->setMemberTypes(members);
331 aronObjectType->setExtends(parentObj);
334 newObjectInfo.correspondingType = aronObjectType;
337 allPreviouslyKnownPrivateTypes.clear();
338 return aronObjectType;
342 ReaderFactory::createList(
const RapidXmlReaderNode& node,
const Path& path)
346 std::vector<RapidXmlReaderNode>
c = node.nodes();
347 const RapidXmlReaderNode typeNode =
c[0];
349 type->setMaybe(getMaybe(typeNode));
351 auto o = std::make_shared<type::List>(path);
352 o->setAcceptedType(type);
357 ReaderFactory::createDict(
const RapidXmlReaderNode& node,
const Path& path)
361 std::vector<RapidXmlReaderNode>
c = node.nodes();
362 const RapidXmlReaderNode typeNode =
c[0];
364 type->setMaybe(getMaybe(typeNode));
366 auto o = std::make_shared<type::Dict>(path);
367 o->setAcceptedType(type);
372 ReaderFactory::createTuple(
const RapidXmlReaderNode& node,
const Path& path)
377 std::vector<RapidXmlReaderNode>
c = node.nodes();
378 std::vector<type::VariantPtr> elementTypes;
379 for (
const RapidXmlReaderNode& tupleTypeDeclarationNode :
c)
383 std::vector<RapidXmlReaderNode> typeNodeChildren = tupleTypeDeclarationNode.nodes();
384 const RapidXmlReaderNode typeNode = typeNodeChildren[0];
387 type->setMaybe(getMaybe(typeNode));
389 elementTypes.push_back(type);
392 auto o = std::make_shared<type::Tuple>(path);
393 o->setAcceptedTypes(elementTypes);
398 ReaderFactory::createPair(
const RapidXmlReaderNode& node,
const Path& path)
402 std::vector<RapidXmlReaderNode>
c = node.nodes();
403 const RapidXmlReaderNode type1Node =
c[0];
406 type1->setMaybe(getMaybe(type1Node));
408 const RapidXmlReaderNode type2Node =
c[1];
410 type2->setMaybe(getMaybe(type2Node));
412 auto o = std::make_shared<type::Pair>(path);
413 o->setFirstAcceptedType(type1);
414 o->setSecondAcceptedType(type2);
419 ReaderFactory::createNDArray(
const RapidXmlReaderNode& node,
const Path& path)
const
431 static const std::map<std::string, std::string> StringSlug2NDArrayDefaultValue = {
435 auto o = std::make_shared<type::NDArray>(path);
445 ReaderFactory::createMatrix(
const RapidXmlReaderNode& node,
const Path& path)
const
447 static const std::map<std::string, type::matrix::ElementType> StringSlug2MatrixType = {
458 static const std::map<std::string, std::string> StringSlug2MatrixDefaultValue = {
463 auto o = std::make_shared<type::Matrix>(path);
483 const int rows = std::stoi(rows_str);
484 const int cols = std::stoi(cols_str);
494 StringSlug2MatrixType.count(simox::alg::to_lower(type)),
495 error::ValueNotValidException(__PRETTY_FUNCTION__,
"Could not resolve type", type));
498 o->setElementType(StringSlug2MatrixType.at(simox::alg::to_lower(type)));
504 if (
const auto it = StringSlug2MatrixDefaultValue.find(def);
505 it != StringSlug2MatrixDefaultValue.end())
507 o->setDefaultValue(it->second);
509 else if (def == type::matrix::default_value::DEFAULT)
511 o->setDefaultValue(def);
516 o->setDefaultValue(def);
523 ReaderFactory::createQuaternion(
const RapidXmlReaderNode& node,
const Path& path)
const
525 static const std::map<std::string, type::quaternion::ElementType>
526 StringSlug2QuaternionType = {
530 static const std::map<std::string, std::string> StringSlug2QuaternionDefaultValue = {
534 auto o = std::make_shared<type::Quaternion>(path);
541 StringSlug2QuaternionType.count(simox::alg::to_lower(type)),
542 error::ValueNotValidException(__PRETTY_FUNCTION__,
"Could not resolve type", type));
544 o->setElementType(StringSlug2QuaternionType.at(simox::alg::to_lower(type)));
550 if (
const auto it = StringSlug2QuaternionDefaultValue.find(def);
551 it != StringSlug2QuaternionDefaultValue.end())
553 o->setDefaultValue(it->second);
555 else if (def == type::quaternion::default_value::DEFAULT)
557 o->setDefaultValue(def);
562 o->setDefaultValue(def);
569 ReaderFactory::createImage(
const RapidXmlReaderNode& node,
const Path& path)
const
571 static const std::map<std::string, type::image::PixelType>
String2PixelType = {
575 static const std::map<std::string, std::string> StringSlug2ImageDefaultValue = {
580 auto o = std::make_shared<type::Image>(path);
589 error::ValueNotValidException(__PRETTY_FUNCTION__,
"Could not resolve type", type));
597 if (
const auto it = StringSlug2ImageDefaultValue.find(def);
598 it != StringSlug2ImageDefaultValue.end())
600 o->setDefaultValue(it->second);
602 else if (def == type::image::default_value::DEFAULT)
604 o->setDefaultValue(def);
609 o->setDefaultValue(def);
616 ReaderFactory::createPointCloud(
const RapidXmlReaderNode& node,
const Path& path)
const
618 static const std::map<std::string, type::pointcloud::VoxelType> StringSlug2VoxelType = {
627 static const std::map<std::string, std::string> StringSlug2PointCloudDefaultValue = {
632 auto o = std::make_shared<type::PointCloud>(path);
639 StringSlug2VoxelType.count(simox::alg::to_lower(type)),
640 error::ValueNotValidException(__PRETTY_FUNCTION__,
"Could not resolve type", type));
642 o->setVoxelType(StringSlug2VoxelType.at(simox::alg::to_lower(type)));
648 if (
const auto it = StringSlug2PointCloudDefaultValue.find(def);
649 it != StringSlug2PointCloudDefaultValue.end())
651 o->setDefaultValue(it->second);
653 else if (def == type::pointcloud::default_value::DEFAULT)
655 o->setDefaultValue(def);
660 o->setDefaultValue(def);
667 ReaderFactory::createIntEnum(
const RapidXmlReaderNode& node,
const Path& path)
669 if (path.hasElement())
672 throw error::AronException(
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 <" +
681 auto newEnumInfo = typereader::GenerateIntEnumInfo();
682 newEnumInfo.typeName = name;
684 allPreviouslyKnownPrivateTypes.clear();
690 std::map<std::string, int> acceptedValues;
691 for (
const RapidXmlReaderNode& valueChild : node.nodes())
700 newEnumInfo.doc_values.insert(
704 const std::string
value =
713 acceptedValues.emplace(key, std::stoi(
value));
716 if (acceptedValues.size() == 0)
718 printWarning(
"Found enum '" + name +
"' without any members...");
722 if (defaultValue != type::aron_enum::default_value::DEFAULT and
723 not acceptedValues.count(defaultValue))
725 throw error::ValueNotValidException(__PRETTY_FUNCTION__,
726 "An int enum has a non existing default value set",
733 enumPath.setRootIdentifier(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;
742 allPreviouslyKnownPrivateTypes.clear();
747 ReaderFactory::createInt(
const RapidXmlReaderNode& node,
const Path& path)
const
749 auto o = std::make_shared<type::Int>(path);
755 o->setDefaultValue(simox::alg::to_<int>(def));
762 ReaderFactory::createLong(
const RapidXmlReaderNode& node,
const Path& path)
const
764 auto o = std::make_shared<type::Long>(path);
770 o->setDefaultValue(simox::alg::to_<long>(def));
777 ReaderFactory::createFloat(
const RapidXmlReaderNode& node,
const Path& path)
const
779 auto o = std::make_shared<type::Float>(path);
785 o->setDefaultValue(simox::alg::to_<float>(def));
792 ReaderFactory::createDouble(
const RapidXmlReaderNode& node,
const Path& path)
const
794 auto o = std::make_shared<type::Double>(path);
800 o->setDefaultValue(simox::alg::to_<double>(def));
807 ReaderFactory::createString(
const RapidXmlReaderNode& node,
const Path& path)
const
809 auto o = std::make_shared<type::String>(path);
814 o->setDefaultValue(def);
821 ReaderFactory::createBool(
const RapidXmlReaderNode& node,
const Path& path)
const
823 auto o = std::make_shared<type::Bool>(path);
829 o->setDefaultValue(simox::alg::to_<bool>(def));
836 ReaderFactory::createAnyObject(
const RapidXmlReaderNode& node,
const Path& path)
const
838 return std::make_shared<type::AnyObject>(path);