Update Introduction authored by Fabian Peller's avatar Fabian Peller
...@@ -171,9 +171,40 @@ If you have a DTO, you dont know the exact type but you want to have a Aron obje ...@@ -171,9 +171,40 @@ If you have a DTO, you dont know the exact type but you want to have a Aron obje
If you know the type, you can use the constructor the specific Aron object. If you know the type, you can use the constructor the specific Aron object.
### Example to create an Aron data dict from scratch
Goal: Have an Aron dict with a list as member "the_list" and some values in it. Then echo the members and their descriptor as a string.
```cpp
using namespace armarx;
// setup aron object
auto dict = std::make_shared<aron::data::Dict>();
{
auto list = std::make_shared<aron::data::List>();
for (unsigned int i = 0; i < 10; ++i)
{
list->addElement(std::make_shared<aron::data::Int>(i));
}
dict->addElement("the_list", list);
}
// echo
auto listVariant = dict->getElement("the_list"); // will return a aron::data::VariantPtr
auto list = aron::data::List::DynamicCastAndCheck(listVariant); // cast and check whether the cast was successful
for (const auto& intVar : list->getElements())
{
auto i = aron::data::Int::DynamicCastAndCheck(intVar);
std::cout << "The value is: " << i->getValue() << std::endl;
std::cout << "The descriptor is: " << aron::data::defaultconversion::string::Descriptor2String.at(i->getDescriptor()) << std::endl;
```
Please note that we might add more methods or make the current ones more flexible (e.g. such as nlohmann::json).
## Lessons learned ## Lessons learned
- There is a difference between Aron data and Aron type - There is a difference between Aron data and Aron type
- There is a difference between Aron objects and Aron DTOs - There is a difference between Aron objects and Aron DTOs
- How are Aron DTOs structured - How are Aron DTOs structured
- How do Aron data and Aron types correspond - How do Aron data and Aron types correspond
- How to use the Aron objects
\ No newline at end of file