ARON Readers, Writers and Conversion

ARON offers ways to simply convert any aron object into another representation (e.g. from variant to nlohmann::json or vice versa). To do so, it makes use of specific readers and writers. In the following we will only describe the readers, writers and converters for ARON data, not for types (but the principle is the same).

Readers

An ARON reader is used to get information of an ARON object in a specific representation. Assume you have an nlohmann::json aron object which contains some information (for example, it is a dict, containing some members, ...). We need this information to create another object in another representation with the same content.

To do so, you only have to implement the armarx::aron::data::ReaderInterface class. It needs one template parameter for your InputType (e.g. here const nlohmann::json).

The interface provides the following pure virtual methods:

virtual void readList(InputType& input, std::vector<InputTypeNonConst>& elements) = 0;
virtual void readDict(InputType& input, std::map<std::string, InputTypeNonConst>& elements) = 0;
virtual void readNDArray(InputType& input, std::vector<int>& shape, std::string& typeAsString, std::vector<unsigned char>& data) = 0;
virtual void readInt(InputType& input, int& i) = 0;
virtual void readLong(InputType& input, long& i) = 0;
virtual void readFloat(InputType& input, float& i) = 0;
virtual void readDouble(InputType& input, double& i) = 0;
virtual void readString(InputType& input, std::string& s) = 0;
virtual void readBool(InputType& input, bool& i) = 0;

You have to implement the function so that the non-const arguments of the method will be filled with the values of the input. For example, the implementation of the readString method for the nlohmann::json reader would be:

void NlohmannJSONReader::readString(const nlohmann::json& input, std::string& i)
{
if (input[rw::json::constantes::TYPE_SLUG] != expectedType)
{
throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Wrong type in json encountered.", input[rw::json::constantes::TYPE_SLUG], expectedType);
}
}

Of course, the way to get the member depend on the way how to construct (writer) the nlohmann::json.

armarx::aron::data::rw::json::constantes::VALUE_SLUG
const std::string VALUE_SLUG
Definition: Data.h:39
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::aron::data::rw::json::constantes::TYPE_SLUG
const std::string TYPE_SLUG
Definition: Data.h:34
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33