10void parse_enum_declarations(
const std::string& enum_declarations, std::vector<token>& enum_names, std::vector<int>& enum_values)
12 std::vector<token> toks;
15 for (
unsigned int i=0; i<toks.size(); ++i) {
16 std::vector<token> defs;
21 if (defs.size() >= 2 &&
is_integer(defs[1].begin, defs[1].end, new_val))
23 while (defs[0].size() > 0 && *defs[0].begin ==
' ')
25 while (defs[0].size() > 0 && defs[0].end[-1] ==
' ')
27 enum_names.push_back(defs[0]);
28 enum_values.push_back(val);
37 std::vector<int>::const_iterator i = std::find(enum_values.begin(), enum_values.end(), value);
38 if (i == enum_values.end())
40 return (
int)(i-enum_values.begin());
44unsigned find_enum_index(
const std::string& name,
const std::vector<token>& enum_names)
46 for (
unsigned i=0; i<enum_names.size(); ++i) {
47 if (enum_names[i] == name)
55 std::vector<token> enum_names;
56 std::vector<int> enum_values;
the tokenizer allows to split text into tokens in a convenient way.
tokenizer & set_ws(const std::string &ws)
set the list of white spaces, that separate tokens and are skipped
void parse_enum_declarations(const std::string &enum_declarations, std::vector< token > &enum_names, std::vector< int > &enum_values)
parse an enum declaration string into names and values
std::string find_enum_name(const std::string &enum_declarations, int value)
lookup name of value in enum declaration
unsigned find_enum_index(int value, const std::vector< int > &enum_values)
convert value to index
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
bool is_integer(const char *begin, const char *end, int &value)
check if the text range (begin,end( defines an integer value. If yes, store the value in the passed r...
Helper functions to process strings.
Helper functions to process enum declarations from strings.