12 #ifndef CXENUMCONVERTER_H_ 13 #define CXENUMCONVERTER_H_ 15 #include "cxResourceExport.h" 18 #include <boost/array.hpp> 19 #include <boost/algorithm/string.hpp> 106 template<
class ENUM,
unsigned COUNT>
110 static boost::array<QString, COUNT>
mText;
114 if (
unsigned(val)<mText.size())
121 for (
unsigned i=0; i<mText.size(); ++i)
122 if (mText[i].toUpper()==val.toUpper())
123 return static_cast<ENUM>(i);
124 return static_cast<ENUM
>(COUNT);
138 #define SNW_DECLARE_ENUM_STRING_CONVERTERS(EXPORT, NS, ENUM_NAME) \ 141 EXPORT std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val); \ 144 EXPORT QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val); \ 146 EXPORT NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val); \ 164 #define SNW_DEFINE_ENUM_STRING_CONVERTERS_BEGIN(NS, ENUM_NAME, ENUM_SIZE) \ 166 boost::array<QString, NS::ENUM_SIZE> EnumConverter<NS::ENUM_NAME,NS::ENUM_SIZE>::mText = \ 169 #define SNW_DEFINE_ENUM_STRING_CONVERTERS_END(NS, ENUM_NAME, ENUM_SIZE) \ 171 template<> QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val) \ 173 return EnumConverter<NS::ENUM_NAME, NS::ENUM_SIZE>::enum2string(val); \ 175 template<> NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val) \ 177 return EnumConverter<NS::ENUM_NAME, NS::ENUM_SIZE>::string2enum(val); \ 181 std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val) \ 183 s << enum2string(val); \ 187 // -------------------------------------------------------- static QString enum2string(const ENUM &val)
static ENUM string2enum(const QString &val)
Class for easy conversion between an enum and a QString.
static boost::array< QString, COUNT > mText