36 #include <boost/regex.hpp> 37 #include <boost/algorithm/string/regex.hpp> 38 #include <boost/algorithm/string/trim.hpp> 45 static const boost::regex type_regex(
"[a-zA-Z][a-zA-Z0-9_]*" 46 "(/[a-zA-Z][a-zA-Z0-9_]*){0,1}" 47 "(\\[[0-9]*\\]){0,1}");
49 static const boost::regex field_regex(
"[a-zA-Z][a-zA-Z0-9_]*");
51 static const boost::regex array_regex(
"(.+)(\\[([0-9]*)\\])");
54 std::string::const_iterator begin = definition.begin();
55 std::string::const_iterator end = definition.end();
56 boost::match_results<std::string::const_iterator> what;
63 if( regex_search(begin, end, what, type_regex)) {
65 begin = what[0].second;
68 throw std::runtime_error(
"Bad type when parsing field: " + definition);
71 if (regex_search(begin, end, what, field_regex))
74 begin = what[0].second;
77 throw std::runtime_error(
"Bad field when parsing field: " + definition);
80 std::string temp_type =
type;
81 if (regex_search(temp_type, what, array_regex))
85 if (what.size() == 3) {
88 else if (what.size() == 4) {
89 std::string
size(what[3].first, what[3].second);
90 _array_size = size.empty() ? -1 : atoi(size.c_str());
93 throw std::runtime_error(
"Bad array size when parsing field: " + definition);
102 if (regex_search(begin, end, what, boost::regex(
"\\S")))
106 begin = what[0].second;
108 if (type ==
"string") {
109 value.assign(begin, end);
112 if (regex_search(begin, end, what, boost::regex(
"\\s*#")))
114 value.assign(begin, what[0].first);
117 value.assign(begin, end);
122 boost::algorithm::trim(value);
123 }
else if (what[0] ==
"#") {
127 throw std::runtime_error(
"Unexpected character after type and field: " +
const std::string & value() const
If constant, value of field, else undefined.
ROSField(const std::string &definition)
const ROSType & type() const
span_constexpr std::size_t size(span< T, Extent > const &spn)