cenum.h

00001 //==========================================================================
00002 //  CENUM.H - part of
00003 //
00004 //                     OMNeT++/OMNEST
00005 //            Discrete System Simulation in C++
00006 //
00007 //
00008 //  Declaration of the following classes:
00009 //    cEnum : effective integer-to-string mapping
00010 //
00011 //==========================================================================
00012 
00013 /*--------------------------------------------------------------*
00014   Copyright (C) 1992-2008 Andras Varga
00015   Copyright (C) 2006-2008 OpenSim Ltd.
00016 
00017   This file is distributed WITHOUT ANY WARRANTY. See the file
00018   `license' for details on this and other legal matters.
00019 *--------------------------------------------------------------*/
00020 
00021 #ifndef __CENUM_H
00022 #define __CENUM_H
00023 
00024 #include "cownedobject.h"
00025 
00026 NAMESPACE_BEGIN
00027 
00028 #define Register_Enum(NAME, VALUES)  \
00029     EXECUTE_ON_STARTUP(enums.getInstance()->add((new cEnum(#NAME))->registerNames(#VALUES)->registerValues VALUES))
00030 
00039 class SIM_API cEnum : public cOwnedObject
00040 {
00041   private:
00042      std::map<int,std::string> valueToNameMap;
00043      std::map<std::string,int> nameToValueMap;
00044      std::vector<std::string> tmpNames;
00045 
00046   private:
00047      void copy(const cEnum& other);
00048 
00049   public:
00050     // internal: helper for the Register_Enum() macro
00051     cEnum *registerNames(const char *nameList);
00052     // internal: helper for the Register_Enum() macro
00053     cEnum *registerValues(int first, ...);
00054 
00055   public:
00061     explicit cEnum(const char *name=NULL);
00062 
00073     cEnum(const char *name, const char *str, ...);
00074 
00078     cEnum(const cEnum& cenum);
00079 
00083     virtual ~cEnum();
00084 
00089     cEnum& operator=(const cEnum& list);
00091 
00094 
00099     virtual cEnum *dup() const  {return new cEnum(*this);}
00100 
00105     virtual std::string info() const;
00107 
00113     void insert(int value, const char *name);
00114 
00119     const char *getStringFor(int value);
00120 
00125     int lookup(const char *name, int fallback=-1);
00127 
00131     std::string str() const;
00132 
00136     static cEnum *find(const char *name);
00137 
00141     static cEnum *get(const char *name);
00142 };
00143 
00144 NAMESPACE_END
00145 
00146 
00147 #endif
00148 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3