OMKIAccessor.h

Go to the documentation of this file.
00001 
00002 /************************************************************************/
00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00004 /* 1993-2002, thereinafter the Software                                 */
00005 /*                                                                      */
00006 /* The Software has been developped within the Siames Project.          */
00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00008 /* property rights                                                      */
00009 /*                                                                      */
00010 /* The Software has been registered with the Agence pour la Protection  */
00011 /* des Programmes (APP) under registration number                       */
00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00013 /*                                                                      */
00014 /* This file may be distributed under the terms of the Q Public License */
00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00016 /* the file LICENSE.QPL included in the packaging of this file.         */
00017 /*                                                                      */
00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00019 /* Universite Rennes 1 for the software may use this file in            */
00020 /* acordance with that specific license                                 */
00021 /************************************************************************/
00022                 
00023 #if !defined OMK_IACCESSORS_H
00024 #define OMK_IACCESSORS_H
00025 
00026 #include "OMKTracer.h"
00027 
00028 namespace OMK  
00029 {
00030 //-----------------------------------------------------------------
00031 
00049 template< typename T >
00050 class IAccessorT
00051 { 
00052 public:
00054   virtual ~IAccessorT() {}
00057   virtual const T& get() const = 0 ;
00060   virtual void set( const T& value ) = 0 ;
00063   operator const T&() const { return get() ; } 
00064 } ;
00065 //-----------------------------------------------------------------
00066 
00078 template< typename T >
00079 class AccessorT : public IAccessorT< T >
00080 { 
00082 
00083 public:
00086   AccessorT( const T& initialValue ) : _value( initialValue ) {}
00088   virtual ~AccessorT() {}
00090 
00091 
00092   virtual const T& get() const { return _value ; }
00095   virtual void set( const T& value ) { _value = value ; }
00098   operator T&() { return _value ; }
00099 protected:
00101   T _value ;
00102 } ;
00103 //-----------------------------------------------------------------
00104 
00118 template< typename T, typename ObjectT >
00119 class AccessorFctT : public IAccessorT< T >
00120 { 
00121 public:
00130   typedef const T & (ObjectT::*GetMethod)() const ;
00139   typedef void (ObjectT::*SetMethod)( const T & value ) ;
00142   AccessorFctT( ObjectT *object, SetMethod setMethod, GetMethod getMethod )
00143     : _object( object ), _setMethod( setMethod ), _getMethod( getMethod ) {}
00145   virtual ~AccessorFctT() {}
00147 
00148 
00149   virtual const T& get() const { return (_object->*_getMethod)() ; }
00152   virtual void set( const T& value ) { (_object->*_setMethod)( value ) ; }
00153 protected:
00155   ObjectT *_object ;
00157   SetMethod _setMethod ;
00159   GetMethod _getMethod ;
00160 } ;
00161 //-----------------------------------------------------------------
00162 
00206 template< typename T, typename T2 >
00207 class AccessorAccT : public IAccessorT< T >
00208 { 
00209 public:
00212   AccessorAccT( IAccessorT< T2 >* accessor )
00213     : _accessor( accessor ) 
00214   { 
00215     OMASSERTM( _accessor, "Must be valid" ) ;
00216   }
00218   virtual ~AccessorAccT() {}
00220 
00221 
00222 
00223 
00224 
00225 
00226   virtual const T& get() const 
00227   { 
00228     // Gets and cast the value
00229     _tmpValue = (T)_accessor->get() ; 
00230     // Returns the cast value
00231     return _tmpValue ; 
00232   }
00235   virtual void set( const T& value ) 
00236   { // Casts and sets the value
00237     _accessor->set( (T2)value ) ; 
00238   }
00244   void setAccessor( IAccessorT< T2 >* accessor )
00245   {
00246     _accessor = accessor ;
00247     OMASSERTM( _accessor, "Must be valid" ) ;
00248   }
00249 protected:
00251   IAccessorT< T2 >* _accessor ;
00252 private:
00257   mutable T _tmpValue ;
00258 } ;
00259 //-----------------------------------------------------------------
00260 
00261 
00262 }// namespace OMK
00263 
00264 #endif // defined OMK_IACCESSORS_H

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007