#include <substitution_rule.hpp>
Public Member Functions | |
const std::vector < absl::string_view > & | alias () const |
size_t | hash () const |
SubstitutionRule & | operator= (const SubstitutionRule &other) |
bool | operator== (const SubstitutionRule &other) const |
const std::vector < absl::string_view > & | pattern () const |
const std::vector < absl::string_view > & | substitution () const |
SubstitutionRule (const char *pattern, const char *alias, const char *substitution) | |
Pass the three arguments (pattern, alias, substitution) as point separated strings. | |
SubstitutionRule (const SubstitutionRule &other) | |
Private Attributes | |
std::vector< absl::string_view > | _alias |
std::string | _full_alias |
std::string | _full_pattern |
std::string | _full_substitution |
size_t | _hash |
std::vector< absl::string_view > | _pattern |
std::vector< absl::string_view > | _substitution |
Definition at line 45 of file substitution_rule.hpp.
RosIntrospection::SubstitutionRule::SubstitutionRule | ( | const char * | pattern, |
const char * | alias, | ||
const char * | substitution | ||
) |
Pass the three arguments (pattern, alias, substitution) as point separated strings.
Example; consider the JointState message. Before renaming your key/value pair will look like
JointState/header/seq >> 1234 JointState/header/stamp >> 2000.00 JointState/header/frame_id >> base_frame
JointState/position.0 >> 11 JointState/velocity.0 >> 21 JointState/effort.0 >> 31 JointState/name.0 >> first_joint
JointState/position/1 >> 12 JointState/velocity.1 >> 22 JointState/effort.1 >> 32 JointState/name.1 >> second_joint
you can "remap" this to
JointState/header/seq >> 1234 JointState/header/stamp >> 2000.00 JointState/header/frame_id >> base_frame
JointState/first_joint/pos >> 11 JointState/first_joint/vel >> 21 JointState/first_joint/eff >> 31
JointState/second_joint/pos >> 12 JointState/second_joint/vel >> 22 JointState/second_joint/eff >> 32
using these three rules:
std::vector<SubstitutionRule> rules; rules.push_back( SubstitutionRule( "position/#", "name/#", "@/pos" )); rules.push_back( SubstitutionRule( "velocity/#", "name/#", "@/vel" )); rules.push_back( SubstitutionRule( "effort/#", "name/#", "@/eff" ));
These rules are pretty easy to use. For instance, let's consider the following example:
the rule `SubstitutionRule( "position/#", "name/#", "@/pos" )` is using `JointState/name.0 = first_joint` to convert `JointState/position/0 = 11` into `JointState/first_joint/pos = 11`
1. The first argument, __"position/#"__, means: "find any element in `FlatMessage::value` which contains the pattern [position/#] where __#__ is a number".
JointState/position/0 = 11
2. The second argument, __"name/#"__, means: "find the element in `FlatMessage::name` which contains the pattern [name.#] where __#__ is the __same__ number found in the previous pattern".
JointState/name.0 = first_joint
3. The third argument, __"@/pos"__, means: "substitute the pattern found in 1. with this string, where the symbol __@__ represent the name found in 2". The final result is therefore:
JointState/first_joint.pos = 11
pattern | The pattern to be found in FlatMessage::value. |
alias | The name_id that substitutes the number in the pattern. To be found in FlatMessage::name. |
substitution | The way the alias should be used to substitute the pattern in FlatMessage::renamed_value. |
Definition at line 40 of file substitution_rule.cpp.
RosIntrospection::SubstitutionRule::SubstitutionRule | ( | const SubstitutionRule & | other | ) | [inline] |
Definition at line 116 of file substitution_rule.hpp.
const std::vector<absl::string_view>& RosIntrospection::SubstitutionRule::alias | ( | ) | const [inline] |
Definition at line 121 of file substitution_rule.hpp.
size_t RosIntrospection::SubstitutionRule::hash | ( | ) | const [inline] |
Definition at line 128 of file substitution_rule.hpp.
SubstitutionRule & RosIntrospection::SubstitutionRule::operator= | ( | const SubstitutionRule & | other | ) |
Definition at line 55 of file substitution_rule.cpp.
bool RosIntrospection::SubstitutionRule::operator== | ( | const SubstitutionRule & | other | ) | const [inline] |
Definition at line 124 of file substitution_rule.hpp.
const std::vector<absl::string_view>& RosIntrospection::SubstitutionRule::pattern | ( | ) | const [inline] |
Definition at line 120 of file substitution_rule.hpp.
const std::vector<absl::string_view>& RosIntrospection::SubstitutionRule::substitution | ( | ) | const [inline] |
Definition at line 122 of file substitution_rule.hpp.
std::vector<absl::string_view> RosIntrospection::SubstitutionRule::_alias [private] |
Definition at line 135 of file substitution_rule.hpp.
std::string RosIntrospection::SubstitutionRule::_full_alias [private] |
Definition at line 132 of file substitution_rule.hpp.
std::string RosIntrospection::SubstitutionRule::_full_pattern [private] |
Definition at line 131 of file substitution_rule.hpp.
std::string RosIntrospection::SubstitutionRule::_full_substitution [private] |
Definition at line 133 of file substitution_rule.hpp.
size_t RosIntrospection::SubstitutionRule::_hash [private] |
Definition at line 137 of file substitution_rule.hpp.
std::vector<absl::string_view> RosIntrospection::SubstitutionRule::_pattern [private] |
Definition at line 134 of file substitution_rule.hpp.
std::vector<absl::string_view> RosIntrospection::SubstitutionRule::_substitution [private] |
Definition at line 136 of file substitution_rule.hpp.