Skip to content

C++ reflection library with focus on serialization/configuration (ROS parameters, YAML, JSON, XML, etc)

License

Notifications You must be signed in to change notification settings

asherikov/ariles

Repository files navigation

Ariles

branch HEAD v2 pkg_ws_2
(ROS/ROS2 packages)
CI status Build Status Build Status
package Latest version of 'ariles' @ Cloudsmith
Latest version of 'ariles' @ Cloudsmith
Latest version of 'ariles' @ Cloudsmith
Latest version of 'ariles' @ Cloudsmith

Contents

Links

Introduction

Loosely speaking, ariles is a C++ reflection library, i.e., it provides meta-programming APIs for implementation of class visitors (processors). It also provides a number of (de)serializers based on these APIs, e.g., YAML, JSON, XML, ROS parameter server, ROS2 parameters; and serialization wrappers for some types, e.g., STL containers, smart pointers, Eigen matrices, etc.

Use cases

  1. Parsing and generation of configuration files. Unlike some common serialization libraries, e.g., boost::serialization, ariles tries to be flexible while parsing by:

    • silently ignoring unused entries (if possible),
    • ignoring ordering of entries (if possible),
    • not discriminating attributes from childs in XML,
    • optionally ignoring missing entries.
  2. Conversion between different formats, for example, YAML <-> ROS parameter server. Note that the conversion is not data-agnostic, i.e., the complete data structure must be represented in C++ code.

  3. Flattening of a class hierarchy to a list of name-value pairs (string-double), which is useful for collection of time-series data.

  4. Exporting of numerical data to an Octave script for debugging purposes.

  5. Implementation of parsers for specific data formats, e.g., URDF.

Applications

Minimal example

Class [./tests/api_v2/types/minimal.h]:

class Configurable : public ariles2::DefaultBase
{
    #define ARILES2_DEFAULT_ID "ConfigurableEntryName" // optional, defaults to 'ariles'
    #define ARILES2_ENTRIES(v) \
        ARILES2_TYPED_ENTRY(v, integer_member, int)
    #include ARILES2_INITIALIZE
};

Serialization:

Configurable configurable;
configurable.integer_member = 10;
ariles2::apply<ariles2::yaml_cpp::Writer>("config.yaml", configurable);
ariles2::apply<ariles2::yaml_cpp::Writer>(std::cout, configurable);

Result:

ConfigurableEntryName:
    integer_member: 10

Deserialization:

ariles2::apply<ariles2::yaml_cpp::Reader>("config.yaml", configurable);

Conversion:

// read class from a file
ariles2::apply<ariles2::yaml_cpp::Reader>("config.yaml", configurable);
// dump class to ROS parameter server
ariles2::apply<ariles2::rosparam::Writer>(nh, configurable, "/some_namespace/");

Note that ROS/ROS2 compatible packages are available in a separate branch https://github.com/asherikov/ariles/tree/pkg_ws_2.

See demo for more examples: https://asherikov.github.io/ariles/2/DEMO.html [./tests/api_v2/demo_api_v2.cpp]

Visitors

ariles includes a number of optional visitors that support various data representation formats, in particular:

There are also a few utility visitors, e.g.,

  • compare for class comparison;
  • copyto for copying data to non-ariles classes;
  • copyfrom for copying data from non-ariles classes.

The complete list of modules is available at https://asherikov.github.io/ariles/2/modules.html

Supported data types

ariles provides serialization wrappers for the following types:

  • Fundamental types: integers, floats, booleans.
  • Some STL classes (WIP): std::string, std::vector, std::map, std::pair, std::shared_ptr, std::unique_ptr.
  • Eigen types: matrices, transforms, quaternions.
  • Boost classes: boost::optional, boost::movelib::unique_ptr. boost::shared_ptr.
  • Better enums -> https://github.com/aantron/better-enums.

Dependencies and compilation

Dependencies

  • cmake >= 3.13
  • C++17 compatible compiler
  • boost

Visitors and corresponding dependencies can be enabled or disabled via cmake options, the same applies to data types which depend on external libraries.

Compilation in a ROS1/ROS2 workspace

ROS1/ROS2 compatible packages are provided in the pkg_ws_2 branch of the main repository -> https://github.com/asherikov/ariles/tree/pkg_ws_2.

Advanced features

Sloppy maps and pairs

std::pair is by default represented in the following way:

    my_pair:
        first: first_value
        second: second_value

The default behavior is generic and robust, but some users prefer to use a more compact form provided that the first value is represented by std::string:

    my_pair:
        first_value: second_value

The alternative behavior can be enabled using sloppy_pairs_ flag in serialization::Parameters. Note that in general it is up to the user to ensure that first_value is a valid map key in the target serialization format. std::map with string keys are handled in a similar way when sloppy_maps_ parameter is enabled. If you are inheriting from a "sloppy" ariles base classes, e.g., ariles2::SloppyBase (see ariles2/extra.h header), both of these flags are enabled by default.

"Any": polymorphic configurations

ariles2::Any2 class defined in ariles2/types.h provides functionality similar to protobuf::Any: it allows automatic instantiation and configuration reading of user-defined classes based on their string ids. See tests/api_v2/types/any.h for an example.

Tips

Ariles can read what it writes

If you are having problems figuring out the correct confguration file layout for an ariles class, try writing it first to get an example.

Related software

Deprecated

  • ariles2::namevalue
  • ariles2::Any

About

C++ reflection library with focus on serialization/configuration (ROS parameters, YAML, JSON, XML, etc)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •