referenceproperty.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 
00020 #ifndef IDIOSKOPOSREFERENCEPROPERTY_H
00021 #define IDIOSKOPOSREFERENCEPROPERTY_H
00022 
00023 #include <idioskopos/readonlypropertybase.h>
00024 #include <idioskopos/writeonlypropertybase.h>
00025 #include <idioskopos/propertybase.h>
00026 
00027 namespace Idioskopos {
00028 
00032   template <typename T>
00033   class ReadOnlyReferenceProperty: public ReadOnlyPropertyBase<T> {
00034     public:
00035       typedef IdioskoposPointer<ReadOnlyReferenceProperty> pointer;
00036       typedef T value_type;
00037 
00038       IDIOSKOPOS_OBJECT(ReadOnlyReferenceProperty);
00039 
00043       ReadOnlyReferenceProperty ( const Glib::ustring& name,
00044                                   T& val,
00045                                   sigc::slot<void> slot=sigc::slot<void>() ) :
00046           Object(name, slot),
00047           ReadOnlyPropertyBase<T>(name),
00048           m_value( val ) { }
00049 
00055       ReadOnlyReferenceProperty ( const Glib::ustring& name,
00056                                   T& val,
00057                                   Introspectable& container,
00058                                   sigc::slot<void> slot=sigc::slot<void>() ) :
00059           Object(name, container, slot),
00060           ReadOnlyPropertyBase<T>( name, container ),
00061           m_value( val )
00062       { }
00063 
00064       static pointer create( const Glib::ustring& name,
00065                              T& val,
00066                              sigc::slot<void> slot=sigc::slot<void>() )
00067       {
00068         return pointer( new ReadOnlyReferenceProperty<T>(name, val, slot) );
00069       }
00070 
00071       static pointer create( const Glib::ustring& name,
00072                              T& val,
00073                              Introspectable& container,
00074                              sigc::slot<void> slot=sigc::slot<void>() )
00075       {
00076         return pointer( new ReadOnlyReferenceProperty<T>(name, val, container, slot) );
00077       }
00078 
00079       virtual ~ReadOnlyReferenceProperty() { }
00080 
00082       virtual const T& get() const { return m_value; }
00083 
00085       virtual T* get_pointer() {
00086         return & m_value;
00087       }
00088 
00089     protected:
00090       T& m_value;
00091 
00092   };
00093 
00097   template <typename T>
00098   class WriteOnlyReferenceProperty: public WriteOnlyPropertyBase<T> {
00099     public:
00100       typedef IdioskoposPointer<WriteOnlyReferenceProperty> pointer;
00101       typedef T value_type;
00102 
00103       IDIOSKOPOS_OBJECT(WriteOnlyReferenceProperty);
00104 
00108       WriteOnlyReferenceProperty ( const Glib::ustring& name,
00109                                    T& val,
00110                                    sigc::slot<void> slot=sigc::slot<void>() ) :
00111           Object(name, slot),
00112           WriteOnlyPropertyBase<T>(name,val),
00113           m_value( val ) { }
00114 
00120       WriteOnlyReferenceProperty ( const Glib::ustring& name,
00121                                    T& val,
00122                                    Introspectable& container,
00123                                    sigc::slot<void> slot=sigc::slot<void>() ) :
00124               Object(name, container, slot),
00125               WriteOnlyPropertyBase<T>( name, container ),
00126               m_value( val ) { }
00127 
00128       static pointer create( const Glib::ustring& name,
00129                              T& val,
00130                              sigc::slot<void> slot=sigc::slot<void>() )
00131       {
00132         return pointer( new WriteOnlyReferenceProperty<T>(name, val, slot) );
00133       }
00134 
00135       static pointer create( const Glib::ustring& name,
00136                              T& val,
00137                              Introspectable& container,
00138                              sigc::slot<void> slot=sigc::slot<void>() )
00139       {
00140         return pointer( new WriteOnlyReferenceProperty<T>(name, val, container, slot) );
00141       }
00142 
00143       virtual ~WriteOnlyReferenceProperty() { }
00144 
00146       virtual void set
00147         ( const T& val ) {
00148         m_value = val;
00149         this->signal_value_changed().emit();
00150       }
00151 
00152     protected:
00153       T& m_value;
00154 
00155       virtual T& get_value() { return m_value; }
00156   };
00157 
00161   template <typename T>
00162   class ReferenceProperty: public PropertyBase<T> {
00163     public:
00164       typedef IdioskoposPointer<ReferenceProperty> pointer;
00165       typedef T value_type;
00166 
00167       IDIOSKOPOS_OBJECT(ReferenceProperty);
00168 
00172       ReferenceProperty ( const Glib::ustring& name,
00173                           T& val,
00174                           sigc::slot<void> slot=sigc::slot<void>() ) :
00175           Object(name, slot),
00176           PropertyBase<T>(name),
00177           m_value( val ) { }
00178 
00184       ReferenceProperty ( const Glib::ustring& name,
00185                           T& val,
00186                           Introspectable& container,
00187                           sigc::slot<void> slot=sigc::slot<void>() ) :
00188           Object( name, container, slot ),
00189           PropertyBase<T>(name, container),
00190           m_value( val ) { }
00191 
00192       static pointer create( const Glib::ustring& name,
00193                              T& val,
00194                              sigc::slot<void> slot=sigc::slot<void>() )
00195       {
00196         return pointer( new ReferenceProperty<T>(name, val, slot) );
00197       }
00198 
00199       static pointer create( const Glib::ustring& name,
00200                              T& val,
00201                              Introspectable& container,
00202                              sigc::slot<void> slot=sigc::slot<void>() )
00203       {
00204         return pointer( new ReferenceProperty<T>(name, val, container, slot) );
00205       }
00206 
00207       virtual ~ReferenceProperty() { }
00208 
00210       virtual const T& get() const { return m_value; }
00211 
00213       virtual T* get_pointer() {
00214         return & m_value;
00215       }
00216 
00218       virtual void set( const T& val ) {
00219         m_value = val;
00220         this->signal_value_changed().emit();
00221       }
00222 
00223     protected:
00224       T& m_value;
00225 
00226       virtual T& get_value() { return m_value; }
00227   };
00228 
00229 }
00230 
00231 
00232 #endif
00233 

Generated on Thu Jan 11 00:26:41 2007 by  doxygen 1.5.1