33 #ifndef CXENUMCONVERTER_H_
34 #define CXENUMCONVERTER_H_
36 #include "cxResourceExport.h"
39 #include <boost/array.hpp>
40 #include <boost/algorithm/string.hpp>
127 template<
class ENUM,
unsigned COUNT>
131 static boost::array<QString, COUNT>
mText;
135 if (
unsigned(val)<
mText.size())
142 for (
unsigned i=0; i<
mText.size(); ++i)
143 if (
mText[i].toUpper()==val.toUpper())
144 return static_cast<ENUM>(i);
145 return static_cast<ENUM
>(COUNT);
160 #define SNW_DECLARE_ENUM_STRING_CONVERTERS(NS, ENUM_NAME) \
163 cxResource_EXPORT std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val); \
166 cxResource_EXPORT QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val); \
168 cxResource_EXPORT NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val); \
169 //-----------------------------------------------------------------
185 #define SNW_DEFINE_ENUM_STRING_CONVERTERS_BEGIN(NS, ENUM_NAME, ENUM_SIZE) \
187 boost::array<QString, NS::ENUM_SIZE> EnumConverter<NS::ENUM_NAME,NS::ENUM_SIZE>::mText = \
190 #define SNW_DEFINE_ENUM_STRING_CONVERTERS_END(NS, ENUM_NAME, ENUM_SIZE) \
192 template<> QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val) \
194 return EnumConverter<NS::ENUM_NAME, NS::ENUM_SIZE>::enum2string(val); \
196 template<> NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val) \
198 return EnumConverter<NS::ENUM_NAME, NS::ENUM_SIZE>::string2enum(val); \
202 std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val) \
204 s << enum2string(val); \
208 // --------------------------------------------------------
static QString enum2string(const ENUM &val)
ENUM string2enum(const QString &val)
static ENUM string2enum(const QString &val)
Class for easy conversion between an enum and a QString.
static boost::array< QString, COUNT > mText
QString enum2string(const ENUM &val)