PropertySlotProxy.hpp

Go to the documentation of this file.
00001 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00002 //
00003 //        This file is part of E-Cell Simulation Environment package
00004 //
00005 //                Copyright (C) 1996-2002 Keio University
00006 //
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 //
00009 //
00010 // E-Cell is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 // 
00015 // E-Cell is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 // See the GNU General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU General Public
00021 // License along with E-Cell -- see the file COPYING.
00022 // If not, write to the Free Software Foundation, Inc.,
00023 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 // 
00025 //END_HEADER
00026 //
00027 // written by Koichi Takahashi <shafi@e-cell.org>,
00028 // E-Cell Project.
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   /** @addtogroup property
00050       
00051   @ingroup libecs
00052   @{
00053   */
00054 
00055   /** @file */
00056 
00057 
00058   class PropertySlotProxy
00059   {
00060 
00061   public:
00062 
00063     PropertySlotProxy()
00064     {
00065       ; // do nothing
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     //      DefaultSpecializationInhibited();
00089     //    }
00090 
00091     template < typename Type >
00092     inline const Type get() const;
00093     //    {
00094     //      DefaultSpecializationInhibited();
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       ; // do nothing
00177     }
00178 
00179     virtual ~ConcretePropertySlotProxy()
00180     {
00181       ; // do nothing
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       ; // do nothing
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 /* __PROPERTYSLOT_HPP */

Generated on Mon Dec 18 07:29:46 2006 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.5.1