00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef IDIOSKOPOSPROPERTYBASE_H
00021 #define IDIOSKOPOSPROPERTYBASE_H
00022
00023 #include <idioskopos/readonlypropertybase.h>
00024 #include <idioskopos/writeonlypropertybase.h>
00025
00026
00027
00028
00029 namespace Idioskopos
00030 {
00031
00041 template <typename T>
00042 class PropertyBase: public ReadOnlyPropertyBase<T>, public WriteOnlyPropertyBase<T>
00043 {
00044 public:
00045 typedef IdioskoposPointer<PropertyBase> pointer;
00046 typedef T value_type;
00047
00048 IDIOSKOPOS_OBJECT( PropertyBase );
00049
00053 PropertyBase ( const Glib::ustring& name,
00054 sigc::slot<void> slot=sigc::slot<void>() ) :
00055 Object( name, slot ),
00056 ReadOnlyPropertyBase<T>( name ),
00057 WriteOnlyPropertyBase<T>( name )
00058 { }
00059
00064 PropertyBase( const Glib::ustring& name,
00065 Introspectable& container,
00066 sigc::slot<void> slot=sigc::slot<void>() ) :
00067 Object( name, container, slot ),
00068 ReadOnlyPropertyBase<T>( name, container ),
00069 WriteOnlyPropertyBase<T>( name, container )
00070 { }
00071
00072 virtual ~PropertyBase()
00073 { }
00074
00078 PropertyBase<T>& operator= ( const T& val )
00079 {
00080 this->set( val );
00081 return *this;
00082 }
00083
00090 PropertyBase<T>& operator() ( const T& val )
00091 {
00092 this->set( val );
00093 return *this;
00094 }
00095
00105 template <typename X>
00106 PropertyBase<T>& operator+=( X other )
00107 {
00108 this->set
00109 ( this->get
00110 () + other );
00111 return *this;
00112 }
00113
00123 template <typename X>
00124 PropertyBase<T>& operator-=( X other )
00125 {
00126 this->set
00127 ( this->get
00128 () - other );
00129 return *this;
00130 }
00131
00141 template <typename X>
00142 PropertyBase<T>& operator*=( X other )
00143 {
00144 this->set
00145 ( this->get
00146 () * other );
00147 return *this;
00148 }
00149
00159 template <typename X>
00160 PropertyBase<T>& operator/=( X other )
00161 {
00162 this->set
00163 ( this->get
00164 () / other );
00165 return *this;
00166 }
00167
00177 template <typename X>
00178 PropertyBase<T>& operator%=( X other )
00179 {
00180 this->set
00181 ( this->get
00182 () % other );
00183 return *this;
00184 }
00185
00194 virtual Glib::ustring xml( int indent = -1 )
00195 {
00196 return ReadOnlyPropertyBase<T>::xml( indent );
00197 }
00198
00202 const std::type_info& type() const
00203 {
00204 return ReadOnlyPropertyBase<T>::type();
00205 }
00206
00207 };
00208
00209 }
00210
00211 #include <idioskopos/property.h>
00212 #include <idioskopos/referenceproperty.h>
00213
00214 namespace Idioskopos {
00215
00219 template <typename X, typename A>
00220 class PropertyBase<std::vector<X, A> >: public ReadOnlyPropertyBase<std::vector<X, A> >, public WriteOnlyPropertyBase<std::vector<X, A> >
00221 {
00222 public:
00223 typedef IdioskoposPointer<PropertyBase> pointer;
00224 typedef std::vector<X, A> value_type;
00225
00226 IDIOSKOPOS_OBJECT( PropertyBase );
00227
00231 PropertyBase ( const Glib::ustring& name ) :
00232 Object( name ),
00233 ReadOnlyPropertyBase<std::vector<X, A> >( name ),
00234 WriteOnlyPropertyBase<std::vector<X, A> >( name )
00235 { }
00236
00241 PropertyBase( const Glib::ustring& name, Introspectable& container ) :
00242 Object( name, container ),
00243 ReadOnlyPropertyBase<std::vector<X, A> >( name, container ),
00244 WriteOnlyPropertyBase<std::vector<X, A> >( name, container )
00245 { }
00246
00247 virtual ~PropertyBase()
00248 { }
00249
00253 PropertyBase<std::vector<X, A> >& operator= ( const std::vector<X, A> & val )
00254 {
00255 this->set( val );
00256 return *this;
00257 }
00258
00265 PropertyBase<std::vector<X, A> >& operator() ( const std::vector<X, A> & val )
00266 {
00267 this->set( val );
00268 return *this;
00269 }
00270
00279 virtual Glib::ustring xml( int indent = -1 )
00280 {
00281 return ReadOnlyPropertyBase<std::vector<X, A> >::xml( indent );
00282 }
00283
00287 const std::type_info& type() const
00288 {
00289 return ReadOnlyPropertyBase<std::vector<X, A> >::type();
00290 }
00291
00292 virtual size_t num_properties() const { return this->get_pointer()->size(); }
00293
00294 virtual Object::iterator properties_begin()
00295 {
00296 IdioskoposPointer< ReferenceProperty<X> > p;
00297 p = ReferenceProperty<X>::create(this->name()+"[0]", (*(this->get_pointer()))[0]);
00298 return Object::iterator(this, p, 0);
00299 }
00300
00301 protected:
00302 virtual Object::iterator next_property(size_t i) {
00303 std::ostringstream sout;
00304 IdioskoposPointer< ReferenceProperty<X> > p;
00305 if ( i + 1 < this->get_pointer()->size() ) {
00306 sout << this->name() << "[" << i+1 << "]";
00307 p = ReferenceProperty<X>::create(sout.str(), (*(this->get_pointer()))[i+1]);
00308 return Object::iterator(this, p, i+1);
00309 }
00310 else
00311 return this->properties_end();
00312 }
00313
00314 virtual Object::iterator previous_property(size_t i) {
00315 std::ostringstream sout;
00316 IdioskoposPointer< ReferenceProperty<X> > p;
00317 if ( i > 0 ) {
00318 sout << this->name() << "[" << i-1 << "]";
00319 p = ReferenceProperty<X>::create(sout.str(), (*(this->get_pointer()))[i-1]);
00320 return Object::iterator(this, p, i-1);
00321 }
00322 else
00323 return this->properties_end();
00324 }
00325
00326 };
00327
00328
00332 template <typename A>
00333 class PropertyBase<std::vector<bool, A> >: public ReadOnlyPropertyBase<std::vector<bool, A> >, public WriteOnlyPropertyBase<std::vector<bool, A> >
00334 {
00335 public:
00336 typedef IdioskoposPointer<PropertyBase> pointer;
00337 typedef std::vector<bool, A> value_type;
00338
00339 IDIOSKOPOS_OBJECT( PropertyBase );
00340
00344 PropertyBase ( const Glib::ustring& name ) :
00345 Object( name ),
00346 ReadOnlyPropertyBase<std::vector<bool, A> >( name ),
00347 WriteOnlyPropertyBase<std::vector<bool, A> >( name )
00348 { }
00349
00354 PropertyBase( const Glib::ustring& name, Introspectable& container ) :
00355 Object( name, container ),
00356 ReadOnlyPropertyBase<std::vector<bool, A> >( name, container ),
00357 WriteOnlyPropertyBase<std::vector<bool, A> >( name, container )
00358 { }
00359
00360 virtual ~PropertyBase()
00361 { }
00362
00366 PropertyBase<std::vector<bool, A> >& operator= ( const std::vector<bool, A> & val )
00367 {
00368 this->set( val );
00369 return *this;
00370 }
00371
00378 PropertyBase<std::vector<bool, A> >& operator() ( const std::vector<bool, A> & val )
00379 {
00380 this->set( val );
00381 return *this;
00382 }
00383
00392 virtual Glib::ustring xml( int indent = -1 )
00393 {
00394 return ReadOnlyPropertyBase<std::vector<bool, A> >::xml( indent );
00395 }
00396
00400 const std::type_info& type() const
00401 {
00402 return ReadOnlyPropertyBase<std::vector<bool, A> >::type();
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 };
00440
00444 template <typename X, size_t N>
00445 class PropertyBase<IdioskoposArray<X, N> >: public ReadOnlyPropertyBase<IdioskoposArray<X, N> >, public WriteOnlyPropertyBase<IdioskoposArray<X, N> >
00446 {
00447 public:
00448 typedef IdioskoposPointer<PropertyBase> pointer;
00449 typedef IdioskoposArray<X, N> value_type;
00450
00451 IDIOSKOPOS_OBJECT( PropertyBase );
00452
00456 PropertyBase ( const Glib::ustring& name ) :
00457 Object( name ),
00458 ReadOnlyPropertyBase<IdioskoposArray<X, N> >( name ),
00459 WriteOnlyPropertyBase<IdioskoposArray<X, N> >( name )
00460 { }
00461
00466 PropertyBase( const Glib::ustring& name, Introspectable& container ) :
00467 Object( name, container ),
00468 ReadOnlyPropertyBase<IdioskoposArray<X, N> >( name, container ),
00469 WriteOnlyPropertyBase<IdioskoposArray<X, N> >( name, container )
00470 { }
00471
00472 virtual ~PropertyBase()
00473 { }
00474
00478 PropertyBase<IdioskoposArray<X, N> >& operator= ( const IdioskoposArray<X, N> & val )
00479 {
00480 this->set( val );
00481 return *this;
00482 }
00483
00490 PropertyBase<IdioskoposArray<X, N> >& operator() ( const IdioskoposArray<X, N> & val )
00491 {
00492 this->set( val );
00493 return *this;
00494 }
00495
00504 virtual Glib::ustring xml( int indent = -1 )
00505 {
00506 return ReadOnlyPropertyBase<IdioskoposArray<X, N> >::xml( indent );
00507 }
00508
00512 const std::type_info& type() const
00513 {
00514 return ReadOnlyPropertyBase<IdioskoposArray<X, N> >::type();
00515 }
00516
00517 virtual size_t num_properties() const { return N; }
00518
00519 virtual Object::iterator properties_begin()
00520 {
00521 IdioskoposPointer< ReferenceProperty<X> > p;
00522 p = ReferenceProperty<X>::create(this->name()+"[0]", (*(this->get_pointer()))[0]);
00523 return Object::iterator(this, p, 0);
00524 }
00525
00526 protected:
00527 virtual Object::iterator next_property(size_t i) {
00528 std::ostringstream sout;
00529 IdioskoposPointer< ReferenceProperty<X> > p;
00530 if ( i + 1 < N ) {
00531 sout << this->name() << "[" << i+1 << "]";
00532 p = ReferenceProperty<X>::create(sout.str(), (*(this->get_pointer()))[i+1]);
00533 return Object::iterator(this, p, i+1);
00534 }
00535 else
00536 return this->properties_end();
00537 }
00538
00539 virtual Object::iterator previous_property(size_t i) {
00540 std::ostringstream sout;
00541 IdioskoposPointer< ReferenceProperty<X> > p;
00542 if ( i > 0 ) {
00543 sout << this->name() << "[" << i-1 << "]";
00544 p = ReferenceProperty<X>::create(sout.str(), (*(this->get_pointer()))[i-1]);
00545 return Object::iterator(this, p, i-1);
00546 }
00547 else
00548 return this->properties_end();
00549 }
00550
00551 };
00552
00553
00554 }
00555
00556 #endif
00557