#include <OMKIAccessor.h>
Inheritance diagram for OMK::AccessorAccT< T, T2 >:
Public Member Functions | |
AccessorAccT (IAccessorT< T2 > *accessor) | |
Constructor. | |
virtual | ~AccessorAccT () |
Destructor. | |
virtual const T & | get () const |
Get the value. | |
virtual void | set (const T &value) |
Set the value. | |
void | setAccessor (IAccessorT< T2 > *accessor) |
Set the new accessor. | |
Protected Attributes | |
IAccessorT< T2 > * | _accessor |
The accessor to the value. | |
Private Attributes | |
T | _tmpValue |
Temporary value. |
T a ; T2 b = (T2)a ; T c = (T)b ;
The other way to use this accessor is to switch between different cases with the setAccessor method. For example to defined different behavior for an object. The following code switches between an AccessorT and an AccessorFctT (which integrate the value):
class MyAccessor : public AccessorAccT< int, int > { public: MyAccessor( int value = 0 ) : AccessorAccT< int, int >( &_default ), _integrator( this, &OMK::MyAccessor::integrateValue, &OMK::MyAccessor::get ), _default( value ) {} virtual ~MyAccessor() {} void toggleBehavior() { setAccessor( _accessor == &_default ? (IAccessorT< int >*)&_default : (IAccessorT< int >*)&_integrator ) ; } private: AccessorT< int > _default ; AccessorFctT< int, MyAccessor > _integrator ; virtual void integrateValue( const int& value ) { _default.set( _default.get() + value ) ; } const int& getValue() const { return _default.get() ; } } ;
Definition at line 207 of file OMKIAccessor.h.
OMK::AccessorAccT< T, T2 >::AccessorAccT | ( | IAccessorT< T2 > * | accessor | ) | [inline] |
Constructor.
Stores the pointers on the object to get and set the value.
Definition at line 212 of file OMKIAccessor.h.
virtual OMK::AccessorAccT< T, T2 >::~AccessorAccT | ( | ) | [inline, virtual] |
virtual const T& OMK::AccessorAccT< T, T2 >::get | ( | ) | const [inline, virtual] |
Get the value.
Implements OMK::IAccessorT< T >.
Definition at line 226 of file OMKIAccessor.h.
00227 { 00228 // Gets and cast the value 00229 _tmpValue = (T)_accessor->get() ; 00230 // Returns the cast value 00231 return _tmpValue ; 00232 }
virtual void OMK::AccessorAccT< T, T2 >::set | ( | const T & | value | ) | [inline, virtual] |
Set the value.
[in] | value | The new value of the value. |
Implements OMK::IAccessorT< T >.
Definition at line 235 of file OMKIAccessor.h.
00236 { // Casts and sets the value 00237 _accessor->set( (T2)value ) ; 00238 }
void OMK::AccessorAccT< T, T2 >::setAccessor | ( | IAccessorT< T2 > * | accessor | ) | [inline] |
Set the new accessor.
[in] | accessor | The new accessor to the value. |
Definition at line 244 of file OMKIAccessor.h.
IAccessorT< T2 >* OMK::AccessorAccT< T, T2 >::_accessor [protected] |
The accessor to the value.
Definition at line 251 of file OMKIAccessor.h.
Referenced by OMK::AccessorAccT< Type, AttributType >::AccessorAccT(), OMK::AccessorAccT< Type, AttributType >::get(), OMK::AccessorAccT< Type, AttributType >::set(), and OMK::AccessorAccT< Type, AttributType >::setAccessor().
T OMK::AccessorAccT< T, T2 >::_tmpValue [mutable, private] |
Temporary value.
Only used in get method.
mutable because get is a const method.
Definition at line 257 of file OMKIAccessor.h.
Referenced by OMK::AccessorAccT< Type, AttributType >::get().
Documentation generated on Mon Jun 9 11:46:01 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |