00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef IDIOSKOPOSPROPERTY_H
00021 #define IDIOSKOPOSPROPERTY_H
00022
00023 #include <idioskopos/propertybase.h>
00024 #include <idioskopos/array.h>
00025
00026 namespace Idioskopos {
00027
00031 template <typename T>
00032 class ReadOnlyProperty: public ReadOnlyPropertyBase<T> {
00033 public:
00034 typedef IdioskoposPointer<ReadOnlyProperty> pointer;
00035 typedef T value_type;
00036
00037 IDIOSKOPOS_OBJECT(ReadOnlyProperty);
00038
00042 ReadOnlyProperty ( const Glib::ustring& name,
00043 sigc::slot<void> slot=sigc::slot<void>()):
00044 Object(name, slot),
00045 ReadOnlyPropertyBase<T>(name)
00046 { }
00047
00051 ReadOnlyProperty ( const Glib::ustring& name,
00052 const T& val,
00053 sigc::slot<void> slot=sigc::slot<void>() ) :
00054 Object(name, slot),
00055 ReadOnlyPropertyBase<T>(name),
00056 m_value( val )
00057 { }
00058
00063 ReadOnlyProperty( const Glib::ustring& name,
00064 Introspectable& container,
00065 sigc::slot<void> slot=sigc::slot<void>() ) :
00066 Object(name, container, slot),
00067 ReadOnlyPropertyBase<T>( name, container )
00068 { }
00069
00075 ReadOnlyProperty ( const Glib::ustring& name,
00076 const T& val,
00077 Introspectable& container,
00078 sigc::slot<void> slot=sigc::slot<void>() ) :
00079 Object(name, container, slot),
00080 ReadOnlyPropertyBase<T>( name, container ),
00081 m_value( val )
00082 { }
00083
00084 static Object::pointer create_object()
00085 {
00086 return Object::pointer( new ReadOnlyProperty<T>(Glib::ustring()) );
00087 }
00088
00089 static pointer create(const Glib::ustring& name,
00090 sigc::slot<void> slot=sigc::slot<void>())
00091 {
00092 return pointer( new ReadOnlyProperty<T>(name, slot) );
00093 }
00094
00095 static pointer create( const Glib::ustring& name,
00096 const T& val,
00097 sigc::slot<void> slot=sigc::slot<void>() )
00098 {
00099 return pointer( new ReadOnlyProperty<T>(name, val, slot) );
00100 }
00101
00102 static pointer create( const Glib::ustring& name,
00103 Introspectable& container,
00104 sigc::slot<void> slot=sigc::slot<void>() )
00105 {
00106 return pointer( new ReadOnlyProperty<T>(name, container, slot) );
00107 }
00108
00109 static pointer create( const Glib::ustring& name,
00110 const T& val,
00111 Introspectable& container,
00112 sigc::slot<void> slot=sigc::slot<void>())
00113 {
00114 return pointer( new ReadOnlyProperty<T>(name, val, container, slot) );
00115 }
00116
00117 virtual ~ReadOnlyProperty() { }
00118
00120 virtual const T& get() const { return m_value; }
00121
00123 virtual T* get_pointer() { return & m_value; }
00124
00125 protected:
00126 T m_value;
00127
00128 };
00129
00133 template <typename T>
00134 class WriteOnlyProperty: public WriteOnlyPropertyBase<T> {
00135 public:
00136 typedef IdioskoposPointer<WriteOnlyProperty> pointer;
00137 typedef T value_type;
00138
00139 IDIOSKOPOS_OBJECT(WriteOnlyProperty);
00140
00144 WriteOnlyProperty (const Glib::ustring& name, sigc::slot<void> slot=sigc::slot<void>()):
00145 Object(name, slot),
00146 WriteOnlyPropertyBase<T>(name) { }
00147
00151 WriteOnlyProperty ( const Glib::ustring& name,
00152 const T& val,
00153 sigc::slot<void> slot=sigc::slot<void>() ) :
00154 Object(name, slot),
00155 WriteOnlyPropertyBase<T>(name),
00156 m_value( val ) { }
00157
00162 WriteOnlyProperty( const Glib::ustring& name,
00163 Introspectable& container,
00164 sigc::slot<void> slot=sigc::slot<void>() ) :
00165 Object(name, container, slot),
00166 WriteOnlyPropertyBase<T>( name, container ) { }
00167
00173 WriteOnlyProperty ( const Glib::ustring& name,
00174 const T& val,
00175 Introspectable& container,
00176 sigc::slot<void> slot=sigc::slot<void>() ) :
00177 Object(name, container, slot),
00178 WriteOnlyPropertyBase<T>( name, container ),
00179 m_value( val ) { }
00180
00181 static Object::pointer create_object()
00182 {
00183 return Object::pointer( new WriteOnlyProperty<T>(Glib::ustring()) );
00184 }
00185
00186 static pointer create(const Glib::ustring& name,
00187 sigc::slot<void> slot=sigc::slot<void>())
00188 {
00189 return pointer( new WriteOnlyProperty<T>(name, slot) );
00190 }
00191
00192 static pointer create( const Glib::ustring& name,
00193 const T& val,
00194 sigc::slot<void> slot=sigc::slot<void>() )
00195 {
00196 return pointer( new WriteOnlyProperty<T>(name, val, slot) );
00197 }
00198
00199 static pointer create( const Glib::ustring& name,
00200 Introspectable& container,
00201 sigc::slot<void> slot=sigc::slot<void>() )
00202 {
00203 return pointer( new WriteOnlyProperty<T>(name, container, slot) );
00204 }
00205
00206 static pointer create( const Glib::ustring& name,
00207 const T& val,
00208 Introspectable& container,
00209 sigc::slot<void> slot=sigc::slot<void>() )
00210 {
00211 return pointer( new WriteOnlyProperty<T>(name, val, container, slot) );
00212 }
00213
00214 virtual ~WriteOnlyProperty() { }
00215
00217 virtual void set( const T& val )
00218 {
00219 m_value = val;
00220 this->signal_value_changed().emit();
00221 }
00222
00223 protected:
00224 T m_value;
00225
00226 virtual T& get_value()
00227 {
00228 return m_value;
00229 }
00230 };
00231
00235 template <typename T>
00236 class Property: public PropertyBase<T> {
00237 public:
00238 typedef IdioskoposPointer<Property> pointer;
00239 typedef T value_type;
00240
00241 IDIOSKOPOS_OBJECT(Property);
00242
00246 Property (const Glib::ustring& name,
00247 sigc::slot<void> slot=sigc::slot<void>()):
00248 Object(name, slot),
00249 PropertyBase<T>(name),
00250 m_value()
00251 { }
00252
00256 Property ( const Glib::ustring& name,
00257 const T& val,
00258 sigc::slot<void> slot=sigc::slot<void>() ) :
00259 Object(name, slot),
00260 PropertyBase<T>(name),
00261 m_value( val )
00262 { }
00263
00268 Property( const Glib::ustring& name,
00269 Introspectable& container,
00270 sigc::slot<void> slot=sigc::slot<void>() ) :
00271 Object( name, container, slot ),
00272 PropertyBase<T>(name, container),
00273 m_value()
00274 { }
00275
00281 Property ( const Glib::ustring& name,
00282 const T& val,
00283 Introspectable& container,
00284 sigc::slot<void> slot=sigc::slot<void>() ) :
00285 Object( name, container, slot ),
00286 PropertyBase<T>(name, container),
00287 m_value( val )
00288 { }
00289
00290 static Object::pointer create_object()
00291 {
00292 return Object::pointer( new Property<T>(Glib::ustring()) );
00293 }
00294
00295 static pointer create(const Glib::ustring& name,
00296 sigc::slot<void> slot=sigc::slot<void>())
00297 {
00298 return pointer( new Property<T>(name, slot) );
00299 }
00300
00301 static pointer create( const Glib::ustring& name,
00302 const T& val,
00303 sigc::slot<void> slot=sigc::slot<void>() )
00304 {
00305 return pointer( new Property<T>(name, val, slot) );
00306 }
00307
00308 static pointer create( const Glib::ustring& name,
00309 Introspectable& container,
00310 sigc::slot<void> slot=sigc::slot<void>() )
00311 {
00312 return pointer( new Property<T>(name, container, slot) );
00313 }
00314
00315 static pointer create( const Glib::ustring& name,
00316 const T& val,
00317 Introspectable& container,
00318 sigc::slot<void> slot=sigc::slot<void>() )
00319 {
00320 return pointer( new Property<T>(name, val, container, slot) );
00321 }
00322
00323 virtual ~Property() { }
00324
00326 virtual const T& get() const { return m_value; }
00327
00329 virtual T* get_pointer()
00330 {
00331 return & m_value;
00332 }
00333
00335 virtual void set
00336 ( const T& val )
00337 {
00338 m_value = val;
00339 this->signal_value_changed().emit();
00340 }
00341
00342 Property<T>& operator= (const T& val)
00343 {
00344 this->set(val);
00345 return *this;
00346 }
00347
00348 protected:
00349 T m_value;
00350
00351 virtual T& get_value()
00352 {
00353 return m_value;
00354 }
00355 };
00356
00357 }
00358
00359
00360 #endif
00361