36 #include <boost/regex.hpp> 37 #include <boost/algorithm/string/regex.hpp> 38 #include <boost/algorithm/string/trim.hpp> 44 static const boost::regex type_regex(
"[a-zA-Z][a-zA-Z0-9_]*" 45 "(/[a-zA-Z][a-zA-Z0-9_]*){0,1}" 46 "(\\[[0-9]*\\]){0,1}");
48 static const boost::regex field_regex(
"[a-zA-Z][a-zA-Z0-9_]*");
50 static const boost::regex array_regex(
"(.+)(\\[([0-9]*)\\])");
52 static const boost::regex regex_A(
"\\S");
54 static const boost::regex regex_B(
"\\s*#");
57 std::string::const_iterator begin = definition.begin();
58 std::string::const_iterator end = definition.end();
59 boost::match_results<std::string::const_iterator> what;
66 if (regex_search(begin, end, what, type_regex))
69 begin = what[0].second;
73 throw std::runtime_error(
"Bad type when parsing field: " + definition);
76 if (regex_search(begin, end, what, field_regex))
79 begin = what[0].second;
83 throw std::runtime_error(
"Bad field when parsing field: " + definition);
86 std::string temp_type =
type;
87 if (regex_search(temp_type, what, array_regex))
95 else if (what.size() == 4)
97 std::string
size(what[3].
first, what[3].second);
98 _array_size = size.empty() ? -1 : atoi(size.c_str());
102 throw std::runtime_error(
"Bad array size when parsing field: " + definition);
112 if (regex_search(begin, end, what, regex_A))
116 begin = what[0].second;
118 if (type ==
"string")
120 value.assign(begin, end);
124 if (regex_search(begin, end, what, regex_B))
126 value.assign(begin, what[0].
first);
130 value.assign(begin, end);
135 boost::algorithm::trim(value);
137 else if (what[0] ==
"#")
144 throw std::runtime_error(
"Unexpected character after type and field: " + definition);
const std::string & value() const
If constant, value of field, else undefined.
ROSField(const std::string &definition)
const T & first(const T &value, const Tail &...)
const ROSType & type() const
span_constexpr std::size_t size(span< T, Extent > const &spn)