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);
159 #define SNW_DECLARE_ENUM_STRING_CONVERTERS(EXPORT, NS, ENUM_NAME) \ 162 EXPORT std::ostream& operator<<(std::ostream& s, const ENUM_NAME& val); \ 165 EXPORT QString enum2string<NS::ENUM_NAME>(const NS::ENUM_NAME& val); \ 167 EXPORT NS::ENUM_NAME string2enum<NS::ENUM_NAME>(const QString& val); \ 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)
static ENUM string2enum(const QString &val)
Class for easy conversion between an enum and a QString.
static boost::array< QString, COUNT > mText