oopapidocs  2.0
enum.h
00001 #ifndef OOENUM_H
00002 #define OOENUM_H
00003 
00004 #include <QStringList>
00005 #include <QTextStream>
00006 #include <QMap>
00007 #include "dobjs_export.h"
00008 
00009 typedef QMap<QString, int> NameMap;
00010 
00011 //start
00026 class DOBJS_EXPORT Enum {
00027 public:
00032     virtual const NameMap&  nameMap() const = 0;
00033 
00034     friend DOBJS_EXPORT QTextStream& operator>>(QTextStream& ts,  Enum& pref);
00035     friend DOBJS_EXPORT QDataStream& operator>>(QDataStream& ds,  Enum& pref);
00036 
00037     Enum(int enumval = 0);
00038         Enum(const Enum& other);
00039     virtual ~Enum();
00040 
00042     virtual QString toString() const;
00043 
00046     virtual bool fromString(QString str);
00047 
00049     virtual int intValue() const ;
00050 
00051     bool operator=(int other);
00052     bool operator=(QString other);
00053 
00054     bool operator==(const Enum& other) const {
00055         return m_Val == other.m_Val;
00056     }
00057     bool operator==(const QString& other) const;
00058     bool operator!=(const Enum& other) const {
00059         return m_Val != other.m_Val;
00060     }
00061     bool operator<(const Enum& other) const {
00062         return m_Val < other.m_Val;
00063     }
00064     bool operator>(const Enum& other) const {
00065         return m_Val > other.m_Val;
00066     }
00069     QStringList names() const;
00070 
00071 
00072 protected:
00073     //end
00074     void setIntValue(int v) {m_Val = v;}
00082     static NameMap& initMap(NameMap& nameMap, QStringList nameList, 
00083                             bool&  initialized, int startIndex = 0);
00084     //start
00085     int m_Val;
00086 
00087 };
00088 
00089 DOBJS_EXPORT QTextStream& operator<<(QTextStream& ts, const Enum& pref);
00090 DOBJS_EXPORT QTextStream& operator>>(QTextStream& ts, Enum& pref);
00091 
00092 DOBJS_EXPORT QDataStream& operator<<(QDataStream& ds, const Enum& pref);
00093 DOBJS_EXPORT QDataStream& operator>>(QDataStream& ds, Enum& pref);
00094 
00095 //end
00096 #endif
00097 
 All Classes Namespaces Functions Enumerations