D:/Programming/GUI Editor (Source)/Property.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 class property_void {};
00011
00012 template <typename OwnerType, typename ValueType>
00013 class getter;
00014
00015 template <typename OwnerType, typename ValueType>
00016 class setter;
00017
00018 template <typename OwnerType, typename ValueType, typename Property1Type, typename Property2Type = property_void>
00019 class CProperty;
00020
00021 template <typename OwnerType, typename ValueType>
00022 class CPropertyBase
00023 {
00024 public:
00025 typedef OwnerType owner_type;
00026 typedef ValueType value_type;
00027 typedef getter<owner_type, value_type> getter_type;
00028 typedef setter<owner_type, value_type> setter_type;
00029 typedef CProperty<owner_type, value_type, getter_type, setter_type> readwrite_property_type;
00030 typedef CProperty<owner_type, value_type, getter_type> readonly_property_type;
00031 typedef CProperty<owner_type, value_type, setter_type> writeonly_property_type;
00032
00033 friend getter_type;
00034 friend setter_type;
00035
00036 CPropertyBase(owner_type* owner_)
00037 : owner(owner_)
00038 {
00039 }
00040
00041 private:
00042 owner_type* owner;
00043 };
00044
00045 template <typename OwnerType, typename ValueType>
00046 class getter
00047 {
00048 public:
00049 typedef OwnerType owner_type;
00050 typedef ValueType value_type;
00051 typedef value_type (OwnerType::*getter_func_type)() const;
00052 typedef CPropertyBase<owner_type, value_type> CPropertyBase_type;
00053
00054 getter(CPropertyBase_type* CPropertyBase_, getter_func_type getter_func_)
00055 : CPropertyBase(CPropertyBase_),
00056 getter_func(getter_func_)
00057 {
00058 }
00059
00060 value_type get_value() const
00061 {
00062 return (*CPropertyBase->owner.*getter_func)();
00063 }
00064
00065 private:
00066 CPropertyBase_type* CPropertyBase;
00067 getter_func_type getter_func;
00068 };
00069
00070 template <typename OwnerType, typename ValueType>
00071 class setter
00072 {
00073 public:
00074 typedef OwnerType owner_type;
00075 typedef ValueType value_type;
00076 typedef void (OwnerType::*setter_func_type)(value_type);
00077 typedef CPropertyBase<owner_type, value_type> CPropertyBase_type;
00078
00079 setter(CPropertyBase_type* CPropertyBase_, setter_func_type setter_func_)
00080 : CPropertyBase(CPropertyBase_),
00081 setter_func(setter_func_)
00082 {
00083 }
00084
00085 void set_value(const value_type& rhs)
00086 {
00087 (*CPropertyBase->owner.*setter_func)(rhs);
00088 }
00089
00090 private:
00091 CPropertyBase_type* CPropertyBase;
00092 setter_func_type setter_func;
00093 };
00094
00095 template <typename OwnerType, typename ValueType, typename Property1Type, typename Property2Type = property_void>
00096 class CProperty : public CPropertyBase<OwnerType, ValueType>, private Property1Type, private Property2Type
00097 {
00098 public:
00099 typedef OwnerType owner_type;
00100 typedef ValueType value_type;
00101 typedef Property1Type property1_type;
00102 typedef Property2Type property2_type;
00103 typedef CPropertyBase<owner_type, value_type> CPropertyBase_type;
00104 typedef CProperty<owner_type, value_type, property1_type, property2_type> this_type;
00105
00106 CProperty(owner_type* owner_, property1_type property1_)
00107 : CPropertyBase_type(owner_),
00108 property1_type(property1_)
00109 {
00110 }
00111
00112 CProperty(owner_type* owner_, property1_type property1_, property2_type property2_)
00113 : CPropertyBase_type(owner_),
00114 property1_type(property1_),
00115 property2_type(property2_)
00116 {
00117 }
00118
00119 const value_type& operator=(const value_type& rhs)
00120 {
00121 set_value(rhs);
00122 return rhs;
00123 }
00124
00125 operator value_type()
00126 {
00127 return get_value();
00128 }
00129
00130 value_type operator++()
00131 {
00132 set_value(get_value() + 1);
00133 return get_value();
00134 }
00135
00136 value_type operator++(int)
00137 {
00138 const value_type value = get_value();
00139 set_value(value + 1);
00140 return value;
00141 }
00142
00143 value_type operator--()
00144 {
00145 set_value(get_value() - 1);
00146 return get_value();
00147 }
00148
00149 value_type operator--(int)
00150 {
00151 const value_type value = get_value();
00152 set_value(value + 1);
00153 return value;
00154 }
00155
00156 template <typename rhs_type>
00157 value_type operator+=(const rhs_type& rhs)
00158 {
00159 set_value(get_value() + rhs);
00160 return get_value();
00161 }
00162
00163 template <typename rhs_type>
00164 value_type operator-=(const rhs_type& rhs)
00165 {
00166 set_value(get_value() - rhs);
00167 return get_value();
00168 }
00169
00170 template <typename rhs_type>
00171 value_type operator*=(const rhs_type& rhs)
00172 {
00173 set_value(get_value() * rhs);
00174 return get_value();
00175 }
00176
00177 template <typename rhs_type>
00178 value_type operator/=(const rhs_type& rhs)
00179 {
00180 set_value(get_value() / rhs);
00181 return get_value();
00182 }
00183
00184 template <typename rhs_type>
00185 value_type operator%=(const rhs_type& rhs)
00186 {
00187 set_value(get_value() % rhs);
00188 return get_value();
00189 }
00190
00191 template <typename rhs_type>
00192 value_type operator<<=(const rhs_type& rhs)
00193 {
00194 set_value(get_value() << rhs);
00195 return get_value();
00196 }
00197
00198 template <typename rhs_type>
00199 value_type operator>>=(const rhs_type& rhs)
00200 {
00201 set_value(get_value() >> rhs);
00202 return get_value();
00203 }
00204
00205 template <typename rhs_type>
00206 value_type operator^=(const rhs_type& rhs)
00207 {
00208 set_value(get_value() ^ rhs);
00209 return get_value();
00210 }
00211
00212 template <typename rhs_type>
00213 value_type operator&=(const rhs_type& rhs)
00214 {
00215 set_value(get_value() & rhs);
00216 return get_value();
00217 }
00218
00219 template <typename rhs_type>
00220 value_type operator|=(const rhs_type& rhs)
00221 {
00222 set_value(get_value() | rhs);
00223 return get_value();
00224 }
00225
00226 private:
00227 CProperty(const this_type& rhs);
00228 const this_type& operator=(const this_type& rhs);
00229 };
00230
Generated on Sun Jul 17 21:34:28 2005 for OpenGL GUI by
1.3.8