From 08d952c9c4012f9f0b443976d668fa8b0db02db8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 7 Apr 2004 20:50:24 +0000 Subject: [PATCH] add helper enum class --- stepmania/src/EnumHelper.cpp | 10 +++++ stepmania/src/EnumHelper.h | 53 +++++++++++++++++++++++++ stepmania/src/Makefile.am | 2 +- stepmania/src/StepMania.dsp | 71 +++++++++++++++++++++------------- stepmania/src/StepMania.vcproj | 6 +++ 5 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 stepmania/src/EnumHelper.cpp 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 + + + +