diff --git a/stepmania/src/EnumHelper.cpp b/stepmania/src/EnumHelper.cpp new file mode 100644 index 0000000000..ee564fa484 --- /dev/null +++ b/stepmania/src/EnumHelper.cpp @@ -0,0 +1,10 @@ +#include "global.h" + +#include "EnumHelper.h" +#include "ThemeManager.h" + +CString GetThemedString( CCStringRef sClass, CCStringRef sValue ) +{ + return THEME->GetMetric( sClass, sValue ); +} + diff --git a/stepmania/src/EnumHelper.h b/stepmania/src/EnumHelper.h index 77f8f8b329..419d53576a 100644 --- a/stepmania/src/EnumHelper.h +++ b/stepmania/src/EnumHelper.h @@ -34,4 +34,57 @@ static const CString EMPTY_STRING; } + +// +// An enum class with reflection-like functionality. +// String literals are stored in GetString instead of a static member so that +// the literals can be defined in the header. +// +#define BEGIN_ENUM( name ) \ +class name { \ +public: \ + enum Value { \ + +#define MIDDLE_ENUM( name ) \ + NUM, \ + INVALID = -1, \ + }; \ +protected: \ + Value m_value; \ + CCStringRef GetString(int i) const { \ + const CString s[NUM] = { \ + +#define END_ENUM( name ) \ + }; return s[i]; } \ +public: \ + name( Value value ) { m_value=value; } \ + name() { MakeInvalid(); } \ + name( int value ) { m_value=(Value)value; } \ + operator int&() { return (int&)m_value; } \ + operator size_t() const { return (size_t)m_value; } \ + static size_t Num() { return (size_t)NUM; } \ + name& operator=(Value val) { m_value = val; return *this; } \ + bool operator<(const name& other) const { return m_value < other.m_value; } \ + void MakeInvalid() { m_value=INVALID; } \ + bool IsValid() const { return m_value>=0 && m_value + + + +