diff --git a/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp b/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp index f458e3d9973bf34dd2dc13e49b5f505db4e403e4..3b7418fe505dc5a82e54285404ab44708f4d33c5 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp @@ -33,7 +33,8 @@ namespace armarx::aron::data { // Access method - std::unique_ptr<data::Variant> VariantFactory::create(const data::dto::GenericDataPtr& aron, const Path& path) const + std::unique_ptr<data::Variant> + VariantFactory::create(const data::dto::GenericDataPtr& aron, const Path& path) const { // if aron is null ==> e.g. optional or ptr not set if (!aron) @@ -41,20 +42,47 @@ namespace armarx::aron::data return nullptr; }; + // compare versions + auto aronVersion = aron->VERSION; + if (aronVersion != armarx::aron::VERSION) + { + ARMARX_WARNING + << "Found inconsistencies in aron versions. This may lead to ice marshalling " + "exceptions. Please make sure to update the sender and receiver packages. " + << aronVersion << " != " << armarx::aron::VERSION; + } + auto descriptor = data::Aron2Descriptor(*aron); - switch(descriptor) + switch (descriptor) { - case data::Descriptor::LIST: return std::make_unique<data::List>(data::dto::ListPtr::dynamicCast(aron), path); - case data::Descriptor::DICT: return std::make_unique<data::Dict>(data::dto::DictPtr::dynamicCast(aron), path); - case data::Descriptor::NDARRAY: return std::make_unique<data::NDArray>(data::dto::NDArrayPtr::dynamicCast(aron), path); - case data::Descriptor::INT: return std::make_unique<data::Int>(data::dto::AronIntPtr::dynamicCast(aron), path); - case data::Descriptor::LONG: return std::make_unique<data::Long>(data::dto::AronLongPtr::dynamicCast(aron), path); - case data::Descriptor::FLOAT: return std::make_unique<data::Float>(data::dto::AronFloatPtr::dynamicCast(aron), path); - case data::Descriptor::DOUBLE: return std::make_unique<data::Double>(data::dto::AronDoublePtr::dynamicCast(aron), path); - case data::Descriptor::STRING: return std::make_unique<data::String>(data::dto::AronStringPtr::dynamicCast(aron), path); - case data::Descriptor::BOOL: return std::make_unique<data::Bool>(data::dto::AronBoolPtr::dynamicCast(aron), path); - case data::Descriptor::UNKNOWN: break; + case data::Descriptor::LIST: + return std::make_unique<data::List>(data::dto::ListPtr::dynamicCast(aron), path); + case data::Descriptor::DICT: + return std::make_unique<data::Dict>(data::dto::DictPtr::dynamicCast(aron), path); + case data::Descriptor::NDARRAY: + return std::make_unique<data::NDArray>(data::dto::NDArrayPtr::dynamicCast(aron), + path); + case data::Descriptor::INT: + return std::make_unique<data::Int>(data::dto::AronIntPtr::dynamicCast(aron), path); + case data::Descriptor::LONG: + return std::make_unique<data::Long>(data::dto::AronLongPtr::dynamicCast(aron), + path); + case data::Descriptor::FLOAT: + return std::make_unique<data::Float>(data::dto::AronFloatPtr::dynamicCast(aron), + path); + case data::Descriptor::DOUBLE: + return std::make_unique<data::Double>(data::dto::AronDoublePtr::dynamicCast(aron), + path); + case data::Descriptor::STRING: + return std::make_unique<data::String>(data::dto::AronStringPtr::dynamicCast(aron), + path); + case data::Descriptor::BOOL: + return std::make_unique<data::Bool>(data::dto::AronBoolPtr::dynamicCast(aron), + path); + case data::Descriptor::UNKNOWN: + break; } - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "", std::to_string((int) descriptor), path); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "", std::to_string((int)descriptor), path); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp b/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp index 405a5e7487213fc8097acc09986a8012b81edfad..fccc4e1306af41cc3498c700f8ed448e83d42b7b 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp @@ -32,32 +32,85 @@ namespace armarx::aron::type { // Access method - std::unique_ptr<type::Variant> VariantFactory::create(const type::dto::GenericType& aron, const Path& path) const + std::unique_ptr<type::Variant> + VariantFactory::create(const type::dto::GenericType& aron, const Path& path) const { + + auto aronVersion = aron.VERSION; + if (aronVersion != armarx::aron::VERSION) + { + ARMARX_WARNING + << "Found inconsistencies in aron versions. This may lead to ice marshalling " + "exceptions. Please make sure to update the sender and receiver packages. " + << aronVersion << " != " << armarx::aron::VERSION; + } + auto descriptor = type::Aron2Descriptor(aron); - switch(descriptor) + switch (descriptor) { - case type::Descriptor::LIST: return std::make_unique<type::List>(dynamic_cast<const type::dto::List&>(aron), path); - case type::Descriptor::DICT: return std::make_unique<type::Dict>(dynamic_cast<const type::dto::Dict&>(aron), path); - case type::Descriptor::PAIR: return std::make_unique<type::Pair>(dynamic_cast<const type::dto::Pair&>(aron), path); - case type::Descriptor::TUPLE: return std::make_unique<type::Tuple>(dynamic_cast<const type::dto::Tuple&>(aron), path); - case type::Descriptor::OBJECT: return std::make_unique<type::Object>(dynamic_cast<const type::dto::AronObject&>(aron), path); - case type::Descriptor::NDARRAY: return std::make_unique<type::NDArray>(dynamic_cast<const type::dto::NDArray&>(aron), path); - case type::Descriptor::MATRIX: return std::make_unique<type::Matrix>(dynamic_cast<const type::dto::Matrix&>(aron), path); - case type::Descriptor::IMAGE: return std::make_unique<type::Image>(dynamic_cast<const type::dto::Image&>(aron), path); - case type::Descriptor::POINTCLOUD: return std::make_unique<type::PointCloud>(dynamic_cast<const type::dto::PointCloud&>(aron), path); - case type::Descriptor::QUATERNION: return std::make_unique<type::Quaternion>(dynamic_cast<const type::dto::Quaternion&>(aron), path); - case type::Descriptor::INT_ENUM: return std::make_unique<type::IntEnum>(dynamic_cast<const type::dto::IntEnum&>(aron), path); - case type::Descriptor::INT: return std::make_unique<type::Int>(dynamic_cast<const type::dto::AronInt&>(aron), path); - case type::Descriptor::LONG: return std::make_unique<type::Long>(dynamic_cast<const type::dto::AronLong&>(aron), path); - case type::Descriptor::FLOAT: return std::make_unique<type::Float>(dynamic_cast<const type::dto::AronFloat&>(aron), path); - case type::Descriptor::DOUBLE: return std::make_unique<type::Double>(dynamic_cast<const type::dto::AronDouble&>(aron), path); - case type::Descriptor::STRING: return std::make_unique<type::String>(dynamic_cast<const type::dto::AronString&>(aron), path); - case type::Descriptor::BOOL: return std::make_unique<type::Bool>(dynamic_cast<const type::dto::AronBool&>(aron), path); - case type::Descriptor::ANY_OBJECT: return std::make_unique<type::AnyObject>(dynamic_cast<const type::dto::AnyObject&>(aron), path); - case type::Descriptor::UNKNOWN: break; + case type::Descriptor::LIST: + return std::make_unique<type::List>(dynamic_cast<const type::dto::List&>(aron), + path); + case type::Descriptor::DICT: + return std::make_unique<type::Dict>(dynamic_cast<const type::dto::Dict&>(aron), + path); + case type::Descriptor::PAIR: + return std::make_unique<type::Pair>(dynamic_cast<const type::dto::Pair&>(aron), + path); + case type::Descriptor::TUPLE: + return std::make_unique<type::Tuple>(dynamic_cast<const type::dto::Tuple&>(aron), + path); + case type::Descriptor::OBJECT: + return std::make_unique<type::Object>( + dynamic_cast<const type::dto::AronObject&>(aron), path); + case type::Descriptor::NDARRAY: + return std::make_unique<type::NDArray>( + dynamic_cast<const type::dto::NDArray&>(aron), path); + case type::Descriptor::MATRIX: + return std::make_unique<type::Matrix>(dynamic_cast<const type::dto::Matrix&>(aron), + path); + case type::Descriptor::IMAGE: + return std::make_unique<type::Image>(dynamic_cast<const type::dto::Image&>(aron), + path); + case type::Descriptor::POINTCLOUD: + return std::make_unique<type::PointCloud>( + dynamic_cast<const type::dto::PointCloud&>(aron), path); + case type::Descriptor::QUATERNION: + return std::make_unique<type::Quaternion>( + dynamic_cast<const type::dto::Quaternion&>(aron), path); + case type::Descriptor::INT_ENUM: + return std::make_unique<type::IntEnum>( + dynamic_cast<const type::dto::IntEnum&>(aron), path); + case type::Descriptor::INT: + return std::make_unique<type::Int>(dynamic_cast<const type::dto::AronInt&>(aron), + path); + case type::Descriptor::LONG: + return std::make_unique<type::Long>(dynamic_cast<const type::dto::AronLong&>(aron), + path); + case type::Descriptor::FLOAT: + return std::make_unique<type::Float>( + dynamic_cast<const type::dto::AronFloat&>(aron), path); + case type::Descriptor::DOUBLE: + return std::make_unique<type::Double>( + dynamic_cast<const type::dto::AronDouble&>(aron), path); + case type::Descriptor::STRING: + return std::make_unique<type::String>( + dynamic_cast<const type::dto::AronString&>(aron), path); + case type::Descriptor::BOOL: + return std::make_unique<type::Bool>(dynamic_cast<const type::dto::AronBool&>(aron), + path); + case type::Descriptor::ANY_OBJECT: + return std::make_unique<type::AnyObject>( + dynamic_cast<const type::dto::AnyObject&>(aron), path); + case type::Descriptor::UNKNOWN: + break; } - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Got an unknown descriptor", std::to_string((int) descriptor) + " aka " + defaultconversion::string::Descriptor2String.at(descriptor), path); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, + "Got an unknown descriptor", + std::to_string((int)descriptor) + " aka " + + defaultconversion::string::Descriptor2String.at(descriptor), + path); } -} +} // namespace armarx::aron::type