12 #ifndef CXENUMCONVERTER_H_ 13 #define CXENUMCONVERTER_H_ 15 #include "cxResourceExport.h" 18 #include <boost/array.hpp> 19 #include <boost/algorithm/string.hpp> 114 template<
class ENUM,
unsigned COUNT>
118 static boost::array<QString, COUNT>
mText;
122 if (
unsigned(val)<mText.size())
129 for (
unsigned i=0; i<mText.size(); ++i)
130 if (mText[i].toUpper()==val.toUpper())
131 return static_cast<ENUM>(i);
132 return static_cast<ENUM
>(COUNT);
146 #define SNW_DECLARE_ENUM_STRING_CONVERTERS(EXPORT, NS, ENUM_NAME) \ 149 EXPORT std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val); \ 152 EXPORT QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val); \ 154 EXPORT NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val); \ 172 #define DEFINE_ENUM_STRING_CONVERTERS_BEGIN(NS, ENUM_NAME, ENUM_SIZE) \ 174 boost::array<QString, NS::ENUM_SIZE> EnumConverter<NS::ENUM_NAME,NS::ENUM_SIZE>::mText = \ 177 #define DEFINE_ENUM_STRING_CONVERTERS_END(NS, ENUM_NAME, ENUM_SIZE) \ 179 template<> QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val) \ 181 return EnumConverter<NS::ENUM_NAME, NS::ENUM_SIZE>::enum2string(val); \ 183 template<> NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val) \ 185 return EnumConverter<NS::ENUM_NAME, NS::ENUM_SIZE>::string2enum(val); \ 189 std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val) \ 191 s << enum2string(val); \ 195 // -------------------------------------------------------- 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