00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef IDIOSKOPOSREADONLYPROPERTYBASE_H
00021 #define IDIOSKOPOSREADONLYPROPERTYBASE_H
00022
00023 #include <idioskopos/utility_stream.h>
00024
00025 namespace Idioskopos
00026 {
00027
00038 template <typename T>
00039 class ReadOnlyPropertyBase: public virtual Object
00040 {
00041 public:
00042 typedef IdioskoposPointer<ReadOnlyPropertyBase> pointer;
00043 typedef T value_type;
00044
00045 IDIOSKOPOS_OBJECT( ReadOnlyPropertyBase );
00046
00048 ReadOnlyPropertyBase ( const Glib::ustring& name,
00049 sigc::slot<void> slot=sigc::slot<void>() ):
00050 Object( name, slot )
00051 { }
00052
00057 ReadOnlyPropertyBase( const Glib::ustring& name,
00058 Introspectable& container,
00059 sigc::slot<void> slot=sigc::slot<void>() ):
00060 Object( name, container, slot )
00061 { }
00062
00064 virtual ~ReadOnlyPropertyBase()
00065 { }
00066
00068 virtual const T& get() const = 0;
00069
00071 virtual T* get_pointer() = 0;
00072
00073 virtual const T* get_pointer() const { return const_cast<ReadOnlyPropertyBase*>(this)->get_pointer(); }
00074
00076 operator const T& () const { return this->get(); }
00077
00084 const T& operator() () const { return this->get(); }
00085
00093 T* operator->() { return get_pointer(); }
00094
00103 virtual Glib::ustring xml( int indent = -1 )
00104 {
00105 Glib::ustring s;
00106 for ( int i = 0; i < indent; i++ )
00107 s += " ";
00108 s += "<property type=\"" + this->class_name() + "\" name=\"" + this->name() + "\">";
00109 if ( indent >= 0 )
00110 s += "\n";
00111 s += get_xml( static_cast<T>( *this ), ( ( indent >= 0 ) ? indent + 1 : indent ) );
00112 if ( indent >= 0 ) s += "\n";
00113 for ( int i = 0;
00114 i < indent;
00115 i++ ) s += " ";
00116 s += "</property>";
00117 if ( indent >= 0 ) s += "\n";
00118 return s;
00119 }
00120
00126 virtual Glib::ustring value()
00127 {
00128 return get_value( static_cast<T>( *this ) );
00129 }
00130
00134 const std::type_info& type() const
00135 {
00136 return typeid( T );
00137 }
00138
00139 };
00140
00144 template <typename X, typename A>
00145 class ReadOnlyPropertyBase<std::vector<X, A> >: public virtual Object
00146 {
00147 public:
00148 typedef IdioskoposPointer<ReadOnlyPropertyBase> pointer;
00149 typedef std::vector<X, A> value_type;
00150
00151 IDIOSKOPOS_OBJECT( ReadOnlyPropertyBase );
00152
00154 ReadOnlyPropertyBase ( const Glib::ustring& name,
00155 sigc::slot<void> slot=sigc::slot<void>() ):
00156 Object( name, slot )
00157 { }
00158
00163 ReadOnlyPropertyBase( const Glib::ustring& name,
00164 Introspectable& container,
00165 sigc::slot<void> slot=sigc::slot<void>() ):
00166 Object( name, container, slot )
00167 { }
00168
00170 virtual ~ReadOnlyPropertyBase()
00171 { }
00172
00174 virtual const std::vector<X, A> & get() const = 0;
00175
00177 virtual std::vector<X, A> * get_pointer() = 0;
00178
00179 virtual const std::vector<X,A>* get_pointer() const { return const_cast<ReadOnlyPropertyBase*>(this)->get_pointer(); }
00180
00182 operator const std::vector<X, A> & () const { return this->get(); }
00183
00190 const std::vector<X, A> & operator() () const { return this->get(); }
00191
00199 std::vector<X, A> * operator->() { return get_pointer(); }
00200
00209 virtual Glib::ustring xml( int indent = -1 )
00210 {
00211 Glib::ustring s;
00212 for ( int i = 0; i < indent; i++ )
00213 s += " ";
00214 s += "<property type=\"" + this->class_name() + "\" name=\"" + this->name() + "\">";
00215 if ( indent >= 0 )
00216 s += "\n";
00217 s += get_xml_vector( this->get
00218 (), ( ( indent >= 0 ) ? indent + 1 : indent ) );
00219 if ( indent >= 0 )
00220 s += "\n";
00221 for ( int i = 0; i < indent; i++ )
00222 s += " ";
00223 s += "</property>";
00224 if ( indent >= 0 )
00225 s += "\n";
00226 return s;
00227 }
00228
00234 virtual Glib::ustring value() { return get_value( static_cast<std::vector<X, A> >( *this ) ); }
00235
00239 const std::type_info& type() const { return typeid( std::vector<X, A> ); }
00240
00241 };
00242
00246 template <typename X, size_t N>
00247 class ReadOnlyPropertyBase<IdioskoposArray<X,N> >: public virtual Object
00248 {
00249 public:
00250 typedef IdioskoposPointer<ReadOnlyPropertyBase> pointer;
00251 typedef IdioskoposArray<X,N> value_type;
00252
00253 IDIOSKOPOS_OBJECT( ReadOnlyPropertyBase );
00254
00256 ReadOnlyPropertyBase ( const Glib::ustring& name,
00257 sigc::slot<void> slot=sigc::slot<void>() ):
00258 Object( name, slot )
00259 { }
00260
00265 ReadOnlyPropertyBase( const Glib::ustring& name,
00266 Introspectable& container,
00267 sigc::slot<void> slot=sigc::slot<void>() ):
00268 Object( name, container, slot )
00269 { }
00270
00272 virtual ~ReadOnlyPropertyBase()
00273 { }
00274
00276 virtual const IdioskoposArray<X,N> & get() const = 0;
00277
00279 virtual IdioskoposArray<X,N> * get_pointer() = 0;
00280
00281 virtual const IdioskoposArray<X,N>* get_pointer() const { return const_cast<ReadOnlyPropertyBase*>(this)->get_pointer(); }
00282
00284 operator const IdioskoposArray<X,N> & () const
00285 {
00286 return this->get();
00287 }
00288
00295 const IdioskoposArray<X,N> & operator() () const
00296 {
00297 return this->get
00298 ();
00299 }
00300
00308 IdioskoposArray<X,N> * operator->()
00309 {
00310 return get_pointer();
00311 }
00312
00321 virtual Glib::ustring xml( int indent = -1 )
00322 {
00323 Glib::ustring s;
00324 for ( int i = 0; i < indent; i++ )
00325 s += " ";
00326 s += "<property type=\"" + this->class_name() + "\" name=\"" + this->name() + "\">";
00327 if ( indent >= 0 )
00328 s += "\n";
00329 s += get_xml( this->get(), ( ( indent >= 0 ) ? indent + 1 : indent ) );
00330 if ( indent >= 0 )
00331 s += "\n";
00332 for ( int i = 0; i < indent; i++ )
00333 s += " ";
00334 s += "</property>";
00335 if ( indent >= 0 )
00336 s += "\n";
00337 return s;
00338 }
00339
00345 virtual Glib::ustring value()
00346 {
00347 return get_value( static_cast<IdioskoposArray<X,N> >( *this ) );
00348 }
00349
00353 const std::type_info& type() const
00354 {
00355 return typeid( IdioskoposArray<X,N> );
00356 }
00357
00358 };
00359
00360 }
00361
00362 #endif
00363