class TagStatus {public: enum Status { NoDefine, Define1, ...... } static String convertToString(Status) static Status convertToEnum(String)private: static StatusStr mStatusStr[3] = {"not define", "Что то стринг", ...} }
C++ (Qt)namespace TagStatus { #define STATUS \ X(NoDefine, "NoDefine") \ X(Define1, "Define1") \ X(Define2, "Define2") #define X(a, b) a, enum Status { STATUS };#undef X #define X(a, b) b, static const char * mStatusStr[] = { STATUS };#undef X }
ENUM(TestEnum, (v1) (v2) (v3));
C++ (Qt)class TagStatus {public: enum Status { NoDefine, Define1, Define2 }; static String convertToString(Status); static Status convertToEnum(String);private: static const std::map<Status, String> mStatusStr;}; const std::map<TagStatus::Status, String> TagStatus::mStatusStr = { {NoDefine, "not define"}, {Define1, "Что то стринг"}, {Define2, "..."}};
C++ (Qt)typedef QPair <const char *, SInt32> TNameType; // тут по-хорошему нужны темплейт аргументы struct CPairTable : public QList <TNameType> { SInt32 Name2Type ( const QString & name ) const; QString Type2Name ( SInt32 ID ) const; QString PrintError ( const QString & badName ) const; int IndexOfName ( const QString & name ) const; int IndexOfType ( SInt32 ID ) const; template <class T> CPairTable & operator << ( const T & value ) // чтобы добавлять эл-ты в объявлении const { return (CPairTable &) (QList <TNameType>::operator << (value)); }};
C++ (Qt)BOOST_ENUM(Level, (Abort)("unrecoverable problem") (Error)("recoverable problem") (Alert)("unexpected behavior") (Info)("expected behavior") (Trace)("normal flow of execution") (Debug)("detailed object state listings")) int main(){ foreach(const string& name, Level::names) { cout << name << endl; } cout << "1: " << Level::names[1] << endl; cout << "toString(Abort): " << Level::toString(Level::Abort) << endl; cout << "getValue(Abort): " << Level::getValue(Level::Abort) << endl; Level::type value = Level::Invalid; bool ret = Level::fromString("Abort", value); cout << "fromString(\"Abort\"): " << ret << ", " << value << endl; value = Level::Invalid; ret = Level::fromString("Debug", value); cout << "fromString(\"Debug\"): " << ret << ", " << value << endl; value = Level::Invalid; ret = Level::fromString("not in enum", value); cout << "fromString(\"not in enum\"): " << ret << ", " << value << endl; return 0;}
C++ (Qt)class TagStatus {public: enum Status { NoDefine, Define1, Define2 }; static String convertToString(Status); static Status convertToEnum(String);private: static class HashStr: public<String,enum> { HashStr() { insert("Not define",NoDefine); ...... } } mHashStr;};