PropertiedClass.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 __PROPERTIEDCLASS_HPP
00032 #define __PROPERTIEDCLASS_HPP
00033 
00034 #include "dmtool/DMObject.hpp"
00035 
00036 #include "libecs.hpp"
00037 
00038 namespace libecs
00039 {
00040 
00041   //
00042   // Macros for DM class definition.
00043   //
00044 
00045 #define LIBECS_DM_CLASS( CLASSNAME, BASE )\
00046   DECLARE_CLASS( CLASSNAME );\
00047   class CLASSNAME\
00048    :\
00049   public BASE 
00050 
00051 //,\
00052 //  private PropertyInterface<CLASSNAME>
00053 
00054 
00055 #define LIBECS_DM_OBJECT_ABSTRACT( CLASSNAME )\
00056   LIBECS_DM_OBJECT_DEF_ABSTRACT( CLASSNAME );\
00057   LIBECS_DM_EXPOSE_PROPERTYINTERFACE( CLASSNAME );\
00058   LIBECS_DM_DEFINE_PROPERTIES()
00059 
00060 
00061 #define LIBECS_DM_OBJECT( CLASSNAME, DMTYPE )\
00062   DM_OBJECT( CLASSNAME, DMTYPE );\
00063   LIBECS_DM_OBJECT_DEF( CLASSNAME, DMTYPE );\
00064   LIBECS_DM_EXPOSE_PROPERTYINTERFACE( CLASSNAME );\
00065   LIBECS_DM_DEFINE_PROPERTIES()
00066 
00067 
00068 #define LIBECS_DM_BASECLASS( CLASSNAME )\
00069   DM_BASECLASS( CLASSNAME )     
00070 
00071 
00072 #define LIBECS_DM_INIT( CLASSNAME, DMTYPE )\
00073   DM_INIT( CLASSNAME, DMTYPE )\
00074   LIBECS_DM_INIT_STATIC( CLASSNAME, DMTYPE )
00075 
00076 
00077   // This macro does two things:
00078   // (1) template specialization of PropertyInterface for CLASSNAME
00079   //     is necessary here to instantiate thePropertySlotMap static variable.
00080   // (2) thePropertyInterface static variable must also be instantiated.
00081 
00082 #define LIBECS_DM_INIT_STATIC( CLASSNAME, DMTYPE )\
00083   template class PropertyInterface<CLASSNAME>;\
00084   libecs::PropertyInterface<CLASSNAME> CLASSNAME::thePropertyInterface
00085 
00086   ///@internal
00087 #define LIBECS_DM_OBJECT_DEF( CLASSNAME, DMTYPE )\
00088   typedef DMTYPE _LIBECS_DMTYPE_;\
00089   LIBECS_DM_OBJECT_DEF_ABSTRACT( CLASSNAME )
00090 
00091 #define LIBECS_DM_OBJECT_DEF_ABSTRACT( CLASSNAME )\
00092   typedef CLASSNAME _LIBECS_CLASS_;\
00093   virtual StringLiteral getClassName() const { return XSTR( CLASSNAME ); } //
00094 
00095   ///@internal
00096 #define LIBECS_DM_EXPOSE_PROPERTYINTERFACE( CLASSNAME )\
00097 private:\
00098  static PropertyInterface<CLASSNAME> thePropertyInterface;\
00099 public:\
00100  virtual PropertySlotBasePtr getPropertySlot( StringCref aPropertyName ) const\
00101  {\
00102   return thePropertyInterface.getPropertySlot( aPropertyName );\
00103  }\
00104  virtual void setProperty( StringCref aPropertyName, PolymorphCref aValue )\
00105  {\
00106   thePropertyInterface.setProperty( *this, aPropertyName, aValue );\
00107  }\
00108  virtual const Polymorph getProperty( StringCref aPropertyName ) const\
00109  {\
00110   return thePropertyInterface.getProperty( *this, aPropertyName );\
00111  }\
00112  virtual void loadProperty( StringCref aPropertyName, PolymorphCref aValue )\
00113  {\
00114   thePropertyInterface.loadProperty( *this, aPropertyName, aValue );\
00115  }\
00116  virtual const Polymorph saveProperty( StringCref aPropertyName ) const\
00117  {\
00118   return thePropertyInterface.saveProperty( *this, aPropertyName );\
00119  }\
00120  virtual const Polymorph getPropertyList() const\
00121  {\
00122   return thePropertyInterface.getPropertyList( *this );\
00123  }\
00124  virtual PropertySlotProxyPtr\
00125  createPropertySlotProxy( StringCref aPropertyName )\
00126  {\
00127   return thePropertyInterface.createPropertySlotProxy( *this, aPropertyName );\
00128  }\
00129  virtual const Polymorph\
00130  getPropertyAttributes( StringCref aPropertyName ) const\
00131  {\
00132   return thePropertyInterface.getPropertyAttributes( *this, aPropertyName );\
00133  } \
00134 static PolymorphMapCref getClassInfo( void )\
00135 {\
00136   return thePropertyInterface.getInfoMap();\
00137 }\
00138 static const void* getClassInfoPtr()\
00139 {\
00140 return reinterpret_cast<const void*>(&thePropertyInterface.getInfoMap());\
00141 }//
00142 
00143 
00144   //
00145   // Macros for property definitions
00146   //
00147 
00148 #define INHERIT_PROPERTIES( BASECLASS )\
00149     BASECLASS::initializePropertyInterface( Type2Type<TT>() );\
00150     CLASS_INFO( "Baseclass", # BASECLASS )
00151     
00152 #define CLASS_DESCRIPTION( DESCRIPTION )\
00153     CLASS_INFO( "Description", DESCRIPTION )
00154 
00155 #define NOMETHOD NULLPTR
00156 
00157 #define CLASSINFO_TRUE 1
00158 #define CLASSINFO_FALSE 0
00159 
00160 #define METHODFLAG( METHODPTR, NULLVALUE ) \
00161  METHODFLAG2( METHODPTR, NULLVALUE )
00162 
00163 #define METHODFLAG2( METHODPTR, NULLVALUE ) \
00164  ( # METHODPTR  == # NULLVALUE ? CLASSINFO_FALSE : CLASSINFO_TRUE )
00165   /**
00166          macro for setting class Info string
00167          Info is expected as PropertyName, Value both Strings
00168         Property descriptor strings 
00169   */
00170 
00171 #define CLASS_INFO( FIELDNAME, FIELDVALUE) \
00172  PropertyInterface<TT>::setInfoField( String ( FIELDNAME ), String( FIELDVALUE ) )
00173 
00174 
00175   /** 
00176           macro for setting Property class info
00177          PropertyName, Type, set_flag, get_flag, save_flag, load_flag
00178   */
00179 #define CLASSPROPERTY_INFO( PROPERTYNAME, TYPE, SETMETHOD, GETMETHOD, SAVEMETHOD, LOADMETHOD ) \
00180  PropertyInterface<TT>::setPropertyInfoField( String( PROPERTYNAME ), String( TYPE ), \
00181                                                                                           METHODFLAG(SETMETHOD, NULLPTR ), METHODFLAG( GETMETHOD, NULLPTR ), \
00182 METHODFLAG( SAVEMETHOD, NULLPTR ), METHODFLAG( LOADMETHOD, NULLPTR ) )
00183 
00184 
00185 
00186 
00187 #define PROPERTYSLOT( TYPE, NAME, SETMETHOD, GETMETHOD )\
00188   PropertyInterface<TT>::registerPropertySlot( # NAME,\
00189          new ConcretePropertySlot<TT,TYPE>( SETMETHOD, GETMETHOD ) );\
00190 CLASSPROPERTY_INFO( # NAME, # TYPE, SETMETHOD, GETMETHOD, SETMETHOD, GETMETHOD )
00191 
00192 #define PROPERTYSLOT_LOAD_SAVE( TYPE, NAME, SETMETHOD, GETMETHOD,\
00193                                 LOADMETHOD, SAVEMETHOD )\
00194   PropertyInterface<TT>::registerPropertySlot( # NAME,\
00195          new LoadSaveConcretePropertySlot<TT,TYPE>( SETMETHOD, GETMETHOD,\
00196                                                     LOADMETHOD, SAVEMETHOD ) );\
00197 CLASSPROPERTY_INFO( # NAME, # TYPE, SETMETHOD, GETMETHOD, SAVEMETHOD, LOADMETHOD )
00198 
00199 
00200 #define PROPERTYSLOT_NO_LOAD_SAVE( TYPE, NAME, SETMETHOD, GETMETHOD )\
00201         PROPERTYSLOT_LOAD_SAVE( TYPE, NAME, SETMETHOD, GETMETHOD,\
00202                                 NULLPTR, NULLPTR )
00203 
00204 #define PROPERTYSLOT_SET_GET( TYPE, NAME )\
00205   PROPERTYSLOT( TYPE, NAME,\
00206                 & _LIBECS_CLASS_::set ## NAME,\
00207                 & _LIBECS_CLASS_::get ## NAME )
00208 
00209 #define PROPERTYSLOT_SET( TYPE, NAME )\
00210   PROPERTYSLOT( TYPE, NAME,\
00211                 & _LIBECS_CLASS_::set ## NAME,\
00212                 NULLPTR )
00213 
00214 
00215 #define PROPERTYSLOT_GET( TYPE, NAME )\
00216   PROPERTYSLOT( TYPE, NAME,\
00217                 NULLPTR,\
00218                 & _LIBECS_CLASS_::get ## NAME )
00219 
00220 #define PROPERTYSLOT_SET_GET_NO_LOAD_SAVE( TYPE, NAME )\
00221   PROPERTYSLOT_NO_LOAD_SAVE( TYPE, NAME,\
00222                              & _LIBECS_CLASS_::set ## NAME,\
00223                              & _LIBECS_CLASS_::get ## NAME )
00224 
00225 #define PROPERTYSLOT_SET_NO_LOAD_SAVE( TYPE, NAME )\
00226   PROPERTYSLOT_NO_LOAD_SAVE( TYPE, NAME,\
00227                              & _LIBECS_CLASS_::set ## NAME,\
00228                              NULLPTR )
00229 
00230 #define PROPERTYSLOT_GET_NO_LOAD_SAVE( TYPE, NAME )\
00231   PROPERTYSLOT_NO_LOAD_SAVE( TYPE, NAME,\
00232                              NULLPTR,\
00233                              & _LIBECS_CLASS_::get ## NAME )
00234 
00235   // Info
00236 
00237 
00238   ///@internal
00239 #define LIBECS_DM_DEFINE_PROPERTIES()\
00240   template<class TT>\
00241   static void initializePropertyInterface( Type2Type<TT> )
00242 
00243 
00244 
00245   // 
00246   // Macros for property method declaration / definitions.
00247   //
00248 
00249 #define SET_SLOT( TYPE, METHODNAME )\
00250   void METHODNAME( libecs::Param<TYPE>::type value )
00251 
00252 #define GET_SLOT( TYPE, METHODNAME )\
00253   const TYPE METHODNAME() const
00254 
00255 #define SET_SLOT_DEF( TYPE, METHODNAME, CLASS )\
00256   SET_SLOT( TYPE, CLASS::METHODNAME )
00257 
00258 #define GET_SLOT_DEF( TYPE, METHODNAME, CLASS )\
00259   GET_SLOT( TYPE, CLASS::METHODNAME )
00260 
00261 
00262 #define SET_METHOD( TYPE, NAME )\
00263   SET_SLOT( TYPE, set ## NAME )
00264 
00265 #define GET_METHOD( TYPE, NAME )\
00266   GET_SLOT( TYPE, get ## NAME )
00267 
00268 #define LOAD_METHOD( TYPE, NAME )\
00269   SET_SLOT( TYPE, load ## NAME )
00270 
00271 #define SAVE_METHOD( TYPE, NAME )\
00272   GET_SLOT( TYPE, save ## NAME )
00273 
00274 
00275 #define SET_METHOD_DEF( TYPE, NAME, CLASS )\
00276   SET_SLOT_DEF( TYPE, set ## NAME, CLASS )
00277 
00278 #define GET_METHOD_DEF( TYPE, NAME, CLASS )\
00279   GET_SLOT_DEF( TYPE, get ## NAME, CLASS )
00280 
00281 #define LOAD_METHOD_DEF( TYPE, NAME, CLASS )\
00282   SET_SLOT_DEF( TYPE, load ## NAME, CLASS )
00283 
00284 #define SAVE_METHOD_DEF( TYPE, NAME, CLASS )\
00285   GET_SLOT_DEF( TYPE, save ## NAME, CLASS )
00286 
00287 
00288 
00289 #define SIMPLE_GET_METHOD( TYPE, NAME )\
00290   GET_METHOD( TYPE, NAME )\
00291   {\
00292     return NAME;\
00293   } //
00294 
00295 #define SIMPLE_SET_METHOD( TYPE, NAME )\
00296   SET_METHOD( TYPE, NAME )\
00297   {\
00298     NAME = value;\
00299   } //
00300 
00301 #define SIMPLE_SET_GET_METHOD( TYPE, NAME )\
00302   SIMPLE_SET_METHOD( TYPE, NAME )\
00303   SIMPLE_GET_METHOD( TYPE, NAME )
00304 
00305 
00306   /** @addtogroup property The Inter-object Communication.
00307    *  The Interobject Communication.
00308    *@{
00309 
00310   */
00311 
00312   /** @file */
00313   
00314   // probably better to replace by AssocVector.
00315   //  DECLARE_MAP( const String, PropertySlotPtr, 
00316   //           std::less<const String>, PropertySlotMap );
00317 
00318   /**
00319      Common base class for classes with PropertySlots.
00320 
00321      @see PropertySlot
00322 
00323   */
00324 
00325   class PropertiedClass
00326   {
00327 
00328   public:
00329 
00330     LIBECS_DM_DEFINE_PROPERTIES()
00331     {
00332       ; // empty, but this must be here.
00333     }
00334 
00335 
00336     PropertiedClass()
00337     {
00338       ; // do nothing
00339     }
00340 
00341     virtual ~PropertiedClass()
00342     {
00343       ; // do nothing
00344     }
00345 
00346     virtual PropertySlotBasePtr 
00347     getPropertySlot( StringCref aPropertyName ) const = 0;
00348 
00349     virtual void 
00350     setProperty( StringCref aPropertyName, PolymorphCref aValue ) = 0;
00351 
00352     virtual const Polymorph 
00353     getProperty( StringCref aPropertyName ) const = 0;
00354 
00355     virtual void 
00356     loadProperty( StringCref aPropertyName, PolymorphCref aValue ) = 0;
00357 
00358     virtual const Polymorph 
00359     saveProperty( StringCref aPropertyName ) const = 0;
00360 
00361     virtual const Polymorph getPropertyList() const = 0;
00362 
00363     virtual const Polymorph 
00364     getPropertyAttributes( StringCref aPropertyName ) const = 0;
00365 
00366     ECELL_API virtual void defaultSetProperty( StringCref aPropertyName, 
00367                                      PolymorphCref aValue );
00368     
00369     ECELL_API virtual const Polymorph 
00370     defaultGetProperty( StringCref aPorpertyName ) const;
00371     
00372     ECELL_API virtual const Polymorph defaultGetPropertyList() const;
00373     
00374     ECELL_API virtual const Polymorph 
00375     defaultGetPropertyAttributes( StringCref aPropertyName ) const;
00376 
00377     void registerLogger( LoggerPtr aLogger );
00378 
00379     void removeLogger( LoggerPtr aLogger );
00380 
00381     LoggerVectorCref getLoggerVector() const
00382     {
00383       return theLoggerVector;
00384     }
00385 
00386     const String getClassNameString() const { return getClassName(); }
00387 
00388     virtual StringLiteral getClassName() const = 0;
00389 
00390   public:
00391 
00392     /// @internal
00393 
00394     template <typename Type>
00395     void nullSet( typename Param<Type>::type )
00396     {
00397       throwNotSetable();
00398     }
00399 
00400     /// @internal
00401 
00402     template <typename Type>
00403     const Type nullGet() const
00404     {
00405       throwNotGetable();
00406     }
00407 
00408   private:
00409 
00410     static void throwNotSetable();
00411     static void throwNotGetable();
00412 
00413   protected:
00414 
00415     LoggerVector theLoggerVector;
00416 
00417   };
00418 
00419 
00420 
00421   // these specializations of nullSet/nullGet are here to avoid spreading
00422   // inline copies of them around.  This reduces sizes of DM .so files a bit.
00423 
00424 #define NULLSET_SPECIALIZATION( TYPE )\
00425   template <> ECELL_API void PropertiedClass::nullSet<TYPE>( Param<TYPE>::type )
00426 
00427   NULLSET_SPECIALIZATION( Real );
00428   NULLSET_SPECIALIZATION( Integer );
00429   NULLSET_SPECIALIZATION( String );
00430   NULLSET_SPECIALIZATION( Polymorph );
00431 
00432 #define NULLGET_SPECIALIZATION( TYPE )\
00433   template <> ECELL_API const TYPE PropertiedClass::nullGet<TYPE>() const
00434 
00435   NULLGET_SPECIALIZATION( Real );
00436   NULLGET_SPECIALIZATION( Integer );
00437   NULLGET_SPECIALIZATION( String );
00438   NULLGET_SPECIALIZATION( Polymorph );
00439 
00440 
00441   /*@}*/
00442   
00443 } // namespace libecs
00444 
00445 
00446 #endif /* __PROPERTIEDCLASS_HPP */
00447 
00448 /*
00449   Do not modify
00450   $Author: sachiboo $
00451   $Revision: 2625 $
00452   $Date: 2006-11-24 13:36:17 +0100 (Fri, 24 Nov 2006) $
00453   $Locker$
00454 */

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