Provide templated accessors for attribute value and name. #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.