00001 #ifndef PROPERTY_H
00002 #define PROPERTY_H
00003
00004 #define BADCAST throw(std::bad_cast){throw std::bad_cast();}
00005
00006 #include <winsock2.h>
00007 #include <string>
00008 #include <ostream>
00009 #include <string>
00010 #include <list>
00011 #include <map>
00012
00013
00014 class PropertyBag;
00015
00016 class Property
00017 {
00018 public:
00019 Property(const std::string& name,bool bDirty);
00020 const std::string& getName()const{return m_name;}
00021 const bool isDirty()const{return m_dirty;}
00022 void setDirty(bool b){m_dirty=b;}
00023 virtual operator bool()const BADCAST
00024 virtual operator DWORD()const BADCAST
00025 virtual operator LOGFONT()const BADCAST
00026 virtual operator std::string()const BADCAST
00027 virtual operator const std::string&()const BADCAST
00028 virtual operator const BYTE* ()const BADCAST
00029 virtual operator const std::list<std::string>&()const BADCAST
00030 virtual operator std::list<std::string>()const BADCAST
00031 virtual operator std::list<std::string>&() BADCAST
00032 virtual operator std::map<std::string,std::string>()const BADCAST
00033 virtual operator const std::map<std::string,std::string>&()const BADCAST
00034 virtual Property& operator=(bool b)BADCAST
00035 virtual Property& operator=(DWORD)BADCAST
00036 virtual Property& operator=(const std::string&)BADCAST
00037 virtual Property& operator=(std::string)BADCAST
00038 virtual Property& operator=(const LOGFONT&)BADCAST
00039 virtual Property& operator=(const std::list<std::string>&)BADCAST
00040 virtual Property& operator=(std::list<std::string>)BADCAST
00041 virtual Property& operator=(const std::map<std::string,std::string>&)BADCAST
00042 virtual Property& operator=(std::map<std::string,std::string>)BADCAST
00043 virtual size_t size()const=0;
00044 virtual ~Property()=0;
00045 virtual Property* clone(bool bKeepDirty=false)=0;
00046
00047 protected:
00048 bool m_dirty;
00049 std::string m_name;
00050 };
00051
00052 template <typename T>
00053 class PropertyImpl:public Property
00054 {
00055 public:
00056 PropertyImpl(const std::string& name,const T& value,bool dirty=true):Property(name,dirty),m_value(value){}
00057 ~PropertyImpl(){}
00058 operator T()const {
00059 return m_value;
00060 }
00061 operator const T&()const {
00062 return m_value;
00063 }
00064
00065 operator T&(){
00066 return m_value;
00067 }
00068 Property& operator=(T newvalue)
00069 {
00070 m_dirty=true;
00071 m_value=newvalue;
00072 return *this;
00073 }
00074 Property& operator=(const T& newvalue)
00075 {
00076 m_dirty=true;
00077 m_value=newvalue;
00078 return *this;
00079 }
00080 size_t size()const
00081 {
00082 return sizeof(T);
00083 }
00084 operator const BYTE* ()const
00085 {
00086 return reinterpret_cast<const BYTE*>(&m_value);
00087 }
00088 virtual Property* clone(bool bKeepDirty=false)
00089 {
00090 return new PropertyImpl<T>(m_name,m_value,bKeepDirty?m_dirty:false);
00091 }
00092 protected:
00093 T m_value;
00094 };
00095
00096
00097
00098 template<typename T>
00099 Property* createProperty(const std::string& name,T _default)
00100 {
00101 return new PropertyImpl<T>(name,_default);
00102 }
00103
00104
00105 #endif