#include <boost/config.hpp>
#include <map>
#include <string>
Go to the source code of this file.
Contains the utility classes and macros that allow for easy conversion to and from an enum value and its textual representation.
Definition in file Enum.h.
#define GG_ENUM_MAP_BEGIN |
( |
|
name | ) |
|
Value:template <> struct EnumMap< name > : EnumMapBase \
{ \
typedef name EnumType; \
typedef std::map<EnumType, std::string> MapType; \
EnumMap () \
{
Declares the beginning of a template specialization of EnumMap, for enumerated type name. Text-to-enum conversion is one of those places that calls for macro magic. To use these for e.g. "enum Foo {FOO, BAR};", write:
GG_ENUM_MAP_BEGIN( Foo )
GG_ENUM_MAP_INSERT( FOO )
GG_ENUM_MAP_INSERT( BAR )
...
GG_ENUM_MAP_END
Definition at line 88 of file Enum.h.
#define GG_ENUM_MAP_INSERT |
( |
|
value | ) |
m_map[ value ] = #value ; |
Adds a single value from an enumerated type, and its corresponding string representation, to an EnumMap.
Definition at line 98 of file Enum.h.
Value:} \
virtual const std::string& FromEnum(long int i) const \
{ \
static const std::string ERROR_STR; \
std::map<EnumType, std::string>::const_iterator it = \
m_map.find(EnumType(i)); \
return it == m_map.end() ? ERROR_STR : it->second; \
} \
long int FromString (const std::string &str) const \
{ \
for (MapType::const_iterator it = m_map.begin(); \
it != m_map.end(); \
++it) { \
if (it->second == str) \
return it->first; \
} \
return BAD_VALUE; \
} \
MapType m_map; \
};
Declares the end of a template specialization of EnumMap, for enumerated type name.
Definition at line 102 of file Enum.h.
#define GG_ENUM_STREAM_IN |
( |
|
name | ) |
|
Value:inline std::istream& operator>>(std::istream& is, name& v) \
{ \
std::string str; \
is >> str; \
v = name (GG::GetEnumMap< name >().FromString(str)); \
return is; \
}
Defines an input stream operator for enumerated type name. Note that the generated function requires that EnumMap<name> be defined.
Definition at line 126 of file Enum.h.
#define GG_ENUM_STREAM_OUT |
( |
|
name | ) |
|
Value:inline std::ostream&
operator<<(std::ostream& os, name v) \
{ \
os << GG::GetEnumMap< name >().FromEnum(v); \
return os; \
}
Defines an output stream operator for enumerated type name. Note that the generated function requires that EnumMap<name> be defined.
Definition at line 137 of file Enum.h.