00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __PROPERTYSLOTPROXY_HPP
00032 #define __PROPERTYSLOTPROXY_HPP
00033
00034 #include <iostream>
00035 #include <functional>
00036
00037 #include "libecs.hpp"
00038 #include "Util.hpp"
00039 #include "PropertySlot.hpp"
00040 #include "LoggerAdapter.hpp"
00041 #include "convertTo.hpp"
00042
00043 #include "Polymorph.hpp"
00044
00045 namespace libecs
00046 {
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class PropertySlotProxy
00059 {
00060
00061 public:
00062
00063 PropertySlotProxy()
00064 {
00065 ;
00066 }
00067
00068 ECELL_API virtual ~PropertySlotProxy();
00069
00070 virtual SET_METHOD( Polymorph, Polymorph ) = 0;
00071 virtual GET_METHOD( Polymorph, Polymorph ) = 0;
00072
00073 virtual SET_METHOD( Real, Real ) = 0;
00074 virtual GET_METHOD( Real, Real ) = 0;
00075
00076 virtual SET_METHOD( Integer, Integer ) = 0;
00077 virtual GET_METHOD( Integer, Integer ) = 0;
00078
00079 virtual SET_METHOD( String, String ) = 0;
00080 virtual GET_METHOD( String, String ) = 0;
00081
00082 virtual const bool isSetable() const = 0;
00083 virtual const bool isGetable() const = 0;
00084
00085 template < typename Type >
00086 inline void set( typename Param<Type>::type aValue );
00087
00088
00089
00090
00091 template < typename Type >
00092 inline const Type get() const;
00093
00094
00095
00096
00097
00098 protected:
00099
00100 };
00101
00102
00103
00104 template <>
00105 inline void
00106 PropertySlotProxy::set<Polymorph>( Param<Polymorph>::type aValue )
00107 {
00108 setPolymorph( aValue );
00109 }
00110
00111 template <>
00112 inline void PropertySlotProxy::set<Real>( Param<Real>::type aValue )
00113 {
00114 setReal( aValue );
00115 }
00116
00117 template <>
00118 inline void PropertySlotProxy::set<Integer>( Param<Integer>::type aValue )
00119 {
00120 setInteger( aValue );
00121 }
00122
00123 template <>
00124 inline void PropertySlotProxy::set<String>( Param<String>::type aValue )
00125 {
00126 setString( aValue );
00127 }
00128
00129 template <>
00130 inline const Polymorph PropertySlotProxy::get() const
00131 {
00132 return getPolymorph();
00133 }
00134
00135 template <>
00136 inline const String PropertySlotProxy::get() const
00137 {
00138 return getString();
00139 }
00140
00141 template <>
00142 inline const Real PropertySlotProxy::get() const
00143 {
00144 return getReal();
00145 }
00146
00147
00148 template <>
00149 inline const Integer PropertySlotProxy::get() const
00150 {
00151 return getInteger();
00152 }
00153
00154
00155
00156 template
00157 <
00158 class T
00159 >
00160 class ConcretePropertySlotProxy
00161 :
00162 public PropertySlotProxy
00163 {
00164
00165 public:
00166
00167 typedef PropertySlot<T> PropertySlot_;
00168 DECLARE_TYPE( PropertySlot_, PropertySlot );
00169
00170 ConcretePropertySlotProxy( T& anObject,
00171 PropertySlotRef aPropertySlot )
00172 :
00173 theObject( anObject ),
00174 thePropertySlot( aPropertySlot )
00175 {
00176 ;
00177 }
00178
00179 virtual ~ConcretePropertySlotProxy()
00180 {
00181 ;
00182 }
00183
00184
00185 #define _PROPERTYSLOT_SETMETHOD( TYPE )\
00186 virtual SET_METHOD( TYPE, TYPE )\
00187 {\
00188 thePropertySlot.set ## TYPE( theObject, value );\
00189 }
00190
00191 #define _PROPERTYSLOT_GETMETHOD( TYPE )\
00192 virtual GET_METHOD( TYPE, TYPE )\
00193 {\
00194 return thePropertySlot.get ## TYPE( theObject );\
00195 }
00196
00197 _PROPERTYSLOT_SETMETHOD( Polymorph );
00198 _PROPERTYSLOT_GETMETHOD( Polymorph );
00199
00200 _PROPERTYSLOT_SETMETHOD( Real );
00201 _PROPERTYSLOT_GETMETHOD( Real );
00202
00203 _PROPERTYSLOT_SETMETHOD( Integer );
00204 _PROPERTYSLOT_GETMETHOD( Integer );
00205
00206 _PROPERTYSLOT_SETMETHOD( String );
00207 _PROPERTYSLOT_GETMETHOD( String );
00208
00209 #undef _PROPERTYSLOT_SETMETHOD
00210 #undef _PROPERTYSLOT_GETMETHOD
00211
00212
00213 virtual const bool isSetable() const
00214 {
00215 return thePropertySlot.isSetable();
00216 }
00217
00218 virtual const bool isGetable() const
00219 {
00220 return thePropertySlot.isGetable();
00221 }
00222
00223 private:
00224
00225 ConcretePropertySlotProxy();
00226
00227 T& theObject;
00228 PropertySlotRef thePropertySlot;
00229
00230 };
00231
00232
00233
00234 class PropertySlotProxyLoggerAdapter
00235 :
00236 public LoggerAdapter
00237 {
00238
00239 public:
00240
00241 PropertySlotProxyLoggerAdapter( PropertySlotProxyPtr aPropertySlotProxy )
00242 :
00243 thePropertySlotProxy( aPropertySlotProxy )
00244 {
00245 ;
00246 }
00247
00248 virtual ~PropertySlotProxyLoggerAdapter()
00249 {
00250 delete thePropertySlotProxy;
00251 }
00252
00253 virtual const Real getValue() const
00254 {
00255 return thePropertySlotProxy->getReal();
00256 }
00257
00258 private:
00259
00260 PropertySlotProxyPtr thePropertySlotProxy;
00261
00262 };
00263
00264
00265
00266 }
00267
00268
00269 #endif