Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide templated accessors for attribute value and name. #53

Open
wants to merge 1 commit into
base: kinetic-devel
Choose a base branch
from

Conversation

iwanders
Copy link

Hi,

This adds two templated functions to the serialization struct, these templated functions take an index as a template parameter and based on that provide either the name of that field or the value of that field. This makes it possible to do a compile time template recursion over the message.

This opens up a lot of possibilities; for example it makes it possible to write a recursing template to convert a ros message to an nlohmann::json object, or allows us to iterate over the message and populate each field with an appropriate random value (floats between 0.0 and 1.0, strings with some dummy content, etc...). Technically it is not strictly limited to serialization, but I thought this was the best place to put these functions, instead of adding static methods to the main struct.

This does make use of c++17 features, since the current ros1 release targets c++14 only I wrapped the additions in a preprocessor if statement. This should make sure it doesn't interfere when compiling using c++14, but is there for use when a target is built with c++17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant