#include <enumeration.hpp>
Public Types | |
enum | Max { MAX = THE_MAX } |
typedef ENUM | native_type |
Public Member Functions | |
enumeration () | |
enumeration (ENUM v) | |
enumeration (const enumeration &other) | |
void | operator= (ENUM v) |
void | operator= (const enumeration &other) |
operator ENUM () const | |
ENUM | max () const |
void | from_string (const std::string &str) |
std::istream & | parse (std::istream &is) |
std::string | as_string () const |
std::ostream & | print (std::ostream &os=std::cerr) const |
Static Public Member Functions | |
static const char * | get_string (unsigned i) |
static bool | verify (const char *filename, unsigned line_no) |
static const std::string & | get_full_qualified_name () |
static std::string | get_name () |
Related Functions | |
(Note that these are not member functions.) | |
template<class ENUM, int THE_MAX> | |
std::ostream & | operator<< (std::ostream &os, const mapnik::enumeration< ENUM, THE_MAX > &e) |
template<class ENUM, int THE_MAX> | |
std::istream & | operator>> (std::istream &is, mapnik::enumeration< ENUM, THE_MAX > &e) |
DEFINE_ENUM(name, e) | |
IMPLEMENT_ENUM(name, strings) |
enum fruit_enum { APPLE, CHERRY, BANANA, PASSION_FRUIT, fruit_enum_MAX }; static const char * fruit_strings[] = { "apple", "cherry", "banana", "passion_fruit", "" }; DEFINE_ENUM( fruit, fruit_enum);
IMPLEMENT_ENUM( fruit, fruit_strings );
int main(int argc, char * argv[]) { fruit f(APPLE); switch ( f ) { case BANANA: case APPLE: cerr << "No thanks. I hate " << f << "s" << endl; break; default: cerr << "Hmmm ... yummy " << f << endl; break; } f = CHERRY; fruit_enum native_enum = f; f.from_string("passion_fruit"); for (unsigned i = 0; i < fruit::MAX; ++i) { cerr << i << " = " << fruit::get_string(i) << endl; } f.from_string("elephant"); // throws illegal_enum_value return 0; }
typedef ENUM mapnik::enumeration< ENUM, THE_MAX >::native_type |
enum mapnik::enumeration::Max |
mapnik::enumeration< ENUM, THE_MAX >::enumeration | ( | ) | [inline] |
mapnik::enumeration< ENUM, THE_MAX >::enumeration | ( | ENUM | v | ) | [inline] |
mapnik::enumeration< ENUM, THE_MAX >::enumeration | ( | const enumeration< ENUM, THE_MAX > & | other | ) | [inline] |
void mapnik::enumeration< ENUM, THE_MAX >::operator= | ( | ENUM | v | ) | [inline] |
Assignment operator for native enum values.
void mapnik::enumeration< ENUM, THE_MAX >::operator= | ( | const enumeration< ENUM, THE_MAX > & | other | ) | [inline] |
Assignment operator.
References mapnik::enumeration< ENUM, THE_MAX >::value_.
mapnik::enumeration< ENUM, THE_MAX >::operator ENUM | ( | ) | const [inline] |
Conversion operator for native enum values.
ENUM mapnik::enumeration< ENUM, THE_MAX >::max | ( | ) | const [inline] |
void mapnik::enumeration< ENUM, THE_MAX >::from_string | ( | const std::string & | str | ) | [inline] |
Converts str
to an enum.
illegal_enum_value | str is not a legal identifier. |
std::istream& mapnik::enumeration< ENUM, THE_MAX >::parse | ( | std::istream & | is | ) | [inline] |
Parses the input stream is
for a word consisting of characters and digits (a-z, A-Z, 0-9) and underscores (_). The failbit of the stream is set if the word is not a valid identifier.
Referenced by mapnik::enumeration< ENUM, THE_MAX >::operator>>().
std::string mapnik::enumeration< ENUM, THE_MAX >::as_string | ( | ) | const [inline] |
Returns the current value as a string identifier.
std::ostream& mapnik::enumeration< ENUM, THE_MAX >::print | ( | std::ostream & | os = std::cerr |
) | const [inline] |
Prints the string identifier to the output stream os
.
static const char* mapnik::enumeration< ENUM, THE_MAX >::get_string | ( | unsigned | i | ) | [inline, static] |
Static helper function to iterate over valid identifiers.
static bool mapnik::enumeration< ENUM, THE_MAX >::verify | ( | const char * | filename, | |
unsigned | line_no | |||
) | [inline, static] |
Performs some simple checks and quits the application if any error is detected. Tries to print helpful error messages.
static const std::string& mapnik::enumeration< ENUM, THE_MAX >::get_full_qualified_name | ( | ) | [inline, static] |
static std::string mapnik::enumeration< ENUM, THE_MAX >::get_name | ( | ) | [inline, static] |
std::ostream & operator<< | ( | std::ostream & | os, | |
const mapnik::enumeration< ENUM, THE_MAX > & | e | |||
) | [related] |
ostream operator for enumeration
std::istream & operator>> | ( | std::istream & | is, | |
mapnik::enumeration< ENUM, THE_MAX > & | e | |||
) | [related] |
istream operator for enumeration
References mapnik::enumeration< ENUM, THE_MAX >::parse().
DEFINE_ENUM | ( | name, | |||
e | ) | [related] |
Helper macro. Creates a typedef.
IMPLEMENT_ENUM | ( | name, | |||
strings | ) | [related] |
Helper macro. Runs the verify() method during static initialization.