Set of strings, allows converting strings to numbers. More...
Public Member Functions | |
stringset () | |
No argument constructor. | |
stringset (const char *str) | |
Constructor: str is a C string containing tokens separated by commas. More... | |
stringset (const std::string &str) | |
Constructor: str is a C++ string containing tokens separated by commas. More... | |
stringset (std::initializer_list< const char * > tokens) | |
Constructor: tokens is a sequence of tokens (each token is C string). More... | |
stringset (std::initializer_list< elem > tokens) | |
Constructor: tokens is a sequence of {token, ID} couples. More... | |
template<typename T > | |
stringset (const T &tokens) | |
Constructor: tokens is a container (vector, list, map) of tokens or {token, ID} couples. More... | |
bool | empty () const |
Tests whether the stringset is empty. | |
size_t | size () const |
Returns the size of the stringset. | |
const string_set & | elements () const |
Returns the internal set of elements (each containing a token and its IDs). | |
int | operator[] (const std::string &token) const |
Returns the ID of token or -1 if not found. | |
int | starts_with (const std::string &str) const |
Returns the ID of the token which starts with str. More... | |
void | clear () |
Clears the stringset. | |
int | insert (const std::string &token) |
Inserts token in the stringset. More... | |
int | insert (const char *token) |
Inserts token in the stringset. More... | |
int | insert (const elem &e) |
Inserts a {token, ID} couple in the stringset. More... | |
template<typename T > | |
void | append (const T &cont) |
Inserts the elements of a container (vector, list, map) of tokens or {token, ID} couples. More... | |
Set of strings, allows converting strings to numbers.
Manages a set of strings (here named tokens). Tokens are associated with a unique numeric ID, which is >=0 and can be used in switch statements for comparing strings. Provides functions to insert tokens, to test if a token belongs to the set and to retrieve the ID of a token.
Example:
Tokens must be in the same order in the enum and in the string thar is given as an argument to the stringset constr. If the labels have specific values, proceed as follows:
|
inlineexplicit |
Constructor: str is a C string containing tokens separated by commas.
Each token is associated with an ID which corresponds to its position in the list (starting from 0). Duplicate tokens are ignored.
|
inlineexplicit |
Constructor: str is a C++ string containing tokens separated by commas.
Each token is associated with an ID which corresponds to its position in the list (starting from 0). Duplicate tokens are ignored.
|
inline |
Constructor: tokens is a sequence of tokens (each token is C string).
Each token is associated with an ID which corresponds to its position in the list (starting from 0). Duplicate tokens are ignored.
|
inline |
Constructor: tokens is a sequence of {token, ID} couples.
IDs must be >= 0. Multiple couples can use the same ID but not the same token (duplicate tokens are ignored).
|
inlineexplicit |
Constructor: tokens is a container (vector, list, map) of tokens or {token, ID} couples.
Duplicate tokens are ignored. IDs must be >= 0.
|
inline |
Returns the ID of the token which starts with str.
Returns -1 if not found and -2 if several tokens match.
|
inline |
Inserts token in the stringset.
Duplicate tokens are ignored. Return the ID of token.
|
inline |
Inserts token in the stringset.
Duplicate tokens are ignored. Return the ID of token.
|
inline |
Inserts a {token, ID} couple in the stringset.
Duplicate tokens are ignored. Return the ID of token.
|
inline |
Inserts the elements of a container (vector, list, map) of tokens or {token, ID} couples.
Duplicate tokens are ignored. IDs must be >= 0.