OMK::Type::SimpleTypeT< T > Class Template Reference

A OMKType with a type which can be used as the type itself. More...

#include <OMKSimpleTypeT.h>

Inheritance diagram for OMK::Type::SimpleTypeT< T >:

Inheritance graph
[legend]
Collaboration diagram for OMK::Type::SimpleTypeT< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

Reset
virtual void resetDefaultValues ()
 Reset the default values of SimpleTypeT.
Accessors to attributes.
void setValue (const T &value)
 Set the value value of SimpleTypeT.
const T & getValue () const
 Return the value value of SimpleTypeT.
T & getValue ()
 Return the value value of SimpleTypeT.
 operator const T & () const
 Cast operator in T.
Operators.
SimpleTypeToperator= (const SimpleTypeT< T > &ref)
 Copy operator.
SimpleTypeToperator= (const T &value)
 Copy operator.
bool operator== (const T &value) const
 comparator
bool operator!= (const T &value) const
bool operator== (const SimpleTypeT< T > &value) const
bool operator!= (const SimpleTypeT< T > &value) const
Packable, Flowable, OMKType interfaces.
virtual void insertInStream (std::ostream &out=std::cout) const
 Insert datas in an output stream.
virtual void extract (std::istream &in=std::cin)
 Extract datas from an input stream.
virtual void pack (OutgoingSynchronisationMessage &out) const
 Pack datas in the message.
virtual void unpack (IncomingSynchronisationMessage &in)
 Unpack datas from the message.
virtual PolatorNTcreatePolator ()
 Default polator creator.

Protected Attributes

Datas
_value
 This member holds the value value of SimpleTypeT.

Detailed Description

template<typename T>
class OMK::Type::SimpleTypeT< T >

A OMKType with a type which can be used as the type itself.

Date:
2006-07-27
Module description :
Use this class to encapsulate a simple type or a class in a OMKType object. The default value must be provided.
For simple types, because of the convert operators, using this class is like using the encapsulated type itself. So you can write the following lines:
OMK::Type::IntType integer ; // Define as SimpleTypeT< int >
// In these three lines the implicit non const operator will convert 
// 'integer' in a 'int&'
integer++ ;     // now 'integer' is 1
integer += 3 ;  // now 'integer' is 4
integer *= 2 ;  // now 'integer' is 8
// In this line the implicit const operator will convert 'integer' in a 
// 'int' which will be compared
bool minusOrEqual3 = integer <= 3 ;  // is false
// In these two lines the two copy operators will be used
integer = 2 ;                      // now 'integer' is 2
integer = OMK::Type::IntType( 5 ) ; // now 'integer' is 5
In case of a class, it must have copy operator, copy constructor and must be able to manage streams (see SimpleTypeT(), resetDefaultValues, pack, unpack) You can use the following example to create your own structures:
// A struture with two integers
struct Something
{
  Something() : a( 0 ), b( 0 ) {}
  Something(int a_, int b_) : a( a_ ), b( b_ ) {}
  Something( const Something& q ) : a( q.a ), b( q.b ) {}
  Something& operator = ( const Something& q ) { a = q.a ; b = q.b ; return *this ; }
  int a ;
  int b ;
  void fct() { a++; b += 5 ; }
} ;
// some operators
Something& operator += ( Something& a, const Something& q ) 
// The stream operators needed by the SimpleTypeT
std::ostream&  operator << ( std::ostream& out, const Something& q ) 
std::istream&  operator >> ( std::istream& in, Something& q ) 
OMK::OutgoingSynchronisationMessage&  operator << ( OMK::OutgoingSynchronisationMessage& out, const Something& q ) 
OMK::IncomingSynchronisationMessage&  operator >> ( OMK::IncomingSynchronisationMessage& in, Something& q ) 
// The typedef
typedef OMK::Type::SimpleTypeT< Something > SomethingType ;
// The default value
template<> const Something SomethingType::s_defaultValue( 0, -1 ) ;
// Some lines code
SomethingType something;         // now 'something' is ( 0, -1 )
something=Something( 3, 3 );     // now 'something' is ( 3,  3 )
something.resetDefaultValues() ; // now 'something' is ( 0, -1 )
((Something&)something).fct() ;  // now 'something' is ( 1,  4 )
something += Something(3, 3);    // now 'something' is ( 4,  7 )
Another example with std::string:
template<> const std::string OMK::Type::SimpleTypeT< std::string >::s_defaultValue( "An empty string !" ) ;
OMK::Type::SimpleTypeT< std::string > myString;       // now 'myString' is "An empty string !"
myString = "try" ;                                   // now 'myString' is "try"
((std::string&)myString) += " to append something" ; // now 'myString' is "try to append something"
myString = "another string" ;                        // now 'myString' is "another string"
Configuration parameters :

Using loadParameters
To get the configuration parameters in the tree, you can use both of the loadParameters methods.
The following sample of configuration parameters shows how to do
 myObject
 {
   Class ObjectWhichUsesSimpleType
   Scheduling
   {
     Frequency 75
     Process processA
   }
   UserParams
   {
     AValue <T>
     AnotherValue <T>
     //... other object parameters
   }
 }
In the header:
 class ObjectWhichUsesSimpleType : public SimulatedObject
 {
   //...
  protected:
   SimpleTypeT<T> _aValue ;
   SimpleTypeT<T> _anotherValue ;
 } ;
In the source:
 void ObjectWhichUsesSimpleType::init()
 {
   //will always display a message with object informations if not found
   _aValue.loadParameters( this, "AValue" ) ;
   //will display a message if not found according to the \ref ParametersAccessor::displayWarning state
   _anotherValue.loadParameters( getConfigurationParameters(), "AnotherValue" ) ;
 }
See DECLARE_PRM_TYPE_EVENT and DECLARE_PRM_TYPE_EVENT_LISTENER.

Definition at line 144 of file OMKSimpleTypeT.h.


Constructor & Destructor Documentation

template<typename T>
OMK::Type::SimpleTypeT< T >::SimpleTypeT ( const SimpleTypeT< T > &  ref  )  [inline]

Copy constructor of SimpleTypeT.

Definition at line 151 of file OMKSimpleTypeT.h.

00151 : Base(), _value( ref._value ) {}

template<typename T>
OMK::Type::SimpleTypeT< T >::SimpleTypeT ( const T &  value = T()  )  [inline]

Constructor of SimpleTypeT with the type T.

Definition at line 153 of file OMKSimpleTypeT.h.

00153 : Base(), _value( value ) {}

template<typename T>
virtual OMK::Type::SimpleTypeT< T >::~SimpleTypeT (  )  [inline, virtual]

Destructor of SimpleTypeT.

Definition at line 155 of file OMKSimpleTypeT.h.

00155 {}

template<typename T>
OMK::Type::SimpleTypeT< T >::SimpleTypeT ( const SimpleTypeT< T > &  ref  )  [inline]

Copy constructor of SimpleTypeT.

Definition at line 151 of file OMKSimpleTypeT.h.

00151 : Base(), _value( ref._value ) {}

template<typename T>
OMK::Type::SimpleTypeT< T >::SimpleTypeT ( const T &  value = T()  )  [inline]

Constructor of SimpleTypeT with the type T.

Definition at line 153 of file OMKSimpleTypeT.h.

00153 : Base(), _value( value ) {}

template<typename T>
virtual OMK::Type::SimpleTypeT< T >::~SimpleTypeT (  )  [inline, virtual]

Destructor of SimpleTypeT.

Definition at line 155 of file OMKSimpleTypeT.h.

00155 {}


Member Function Documentation

template<typename T>
virtual void OMK::Type::SimpleTypeT< T >::resetDefaultValues (  )  [inline, virtual]

Reset the default values of SimpleTypeT.

Definition at line 162 of file OMKSimpleTypeT.h.

00162 { _value = T() ; }

template<typename T>
void OMK::Type::SimpleTypeT< T >::setValue ( const T &  value  )  [inline]

Set the value value of SimpleTypeT.

Definition at line 169 of file OMKSimpleTypeT.h.

Referenced by OMK::Type::NumericPolatorT< Type >::extrapolate().

00169 { _value = value ; }

template<typename T>
const T& OMK::Type::SimpleTypeT< T >::getValue (  )  const [inline]

Return the value value of SimpleTypeT.

Definition at line 171 of file OMKSimpleTypeT.h.

Referenced by OMK::Vis::TransparencyValueAnimator::selfProcessVis(), OMK::Vis::TransformAnimator::selfProcessVis(), OMK::Vis::SwitchAnimator::selfProcessVis(), OMK::Vis::MaterialAnimator< Type >::selfProcessVis(), OMK::Vis::AwarenessColorAnimator::selfProcessVis(), and OMK::Vis::AwarenessAnimator< Type >::selfProcessVis().

00171 { return _value ; }

template<typename T>
T& OMK::Type::SimpleTypeT< T >::getValue (  )  [inline]

Return the value value of SimpleTypeT.

Definition at line 173 of file OMKSimpleTypeT.h.

00173 { return _value ; }

template<typename T>
OMK::Type::SimpleTypeT< T >::operator const T & (  )  const [inline]

Cast operator in T.

Const version of the cast operator

Definition at line 177 of file OMKSimpleTypeT.h.

00177 { return _value ; }

template<typename T>
SimpleTypeT& OMK::Type::SimpleTypeT< T >::operator= ( const SimpleTypeT< T > &  ref  )  [inline]

Copy operator.

Definition at line 183 of file OMKSimpleTypeT.h.

00183 { _value = ref._value ; return *this ; }  

template<typename T>
SimpleTypeT& OMK::Type::SimpleTypeT< T >::operator= ( const T &  value  )  [inline]

Copy operator.

Definition at line 185 of file OMKSimpleTypeT.h.

00185 { _value = value ; return *this ; }

template<typename T>
bool OMK::Type::SimpleTypeT< T >::operator== ( const T &  value  )  const [inline]

comparator

Definition at line 187 of file OMKSimpleTypeT.h.

00187 { return _value == value ; }

template<typename T>
bool OMK::Type::SimpleTypeT< T >::operator!= ( const T &  value  )  const [inline]

Definition at line 188 of file OMKSimpleTypeT.h.

00188 { return !( *this == value ) ; }

template<typename T>
bool OMK::Type::SimpleTypeT< T >::operator== ( const SimpleTypeT< T > &  value  )  const [inline]

Definition at line 189 of file OMKSimpleTypeT.h.

00189 { return _value == (const T&)value ; }

template<typename T>
bool OMK::Type::SimpleTypeT< T >::operator!= ( const SimpleTypeT< T > &  value  )  const [inline]

Definition at line 190 of file OMKSimpleTypeT.h.

00190 { return !( *this == value ) ; }

template<typename T>
void OMK::Type::SimpleTypeT< T >::insertInStream ( std::ostream &  out = std::cout  )  const [virtual]

Insert datas in an output stream.

Implements OMK::Flowable.

Definition at line 283 of file OMKSimpleTypeT.inl.

References OMK::Type::SimpleTypeT< T >::_value.

00284 { 
00285   out << _value << " " << " " ; 
00286 }

template<typename T>
void OMK::Type::SimpleTypeT< T >::extract ( std::istream &  in = std::cin  )  [virtual]

Extract datas from an input stream.

Implements OMK::Flowable.

Definition at line 289 of file OMKSimpleTypeT.inl.

References OMK::Type::SimpleTypeT< T >::_value.

00290 { 
00291   in  >> _value ; 
00292 }

template<typename T>
void OMK::Type::SimpleTypeT< T >::pack ( OutgoingSynchronisationMessage out  )  const [virtual]

Pack datas in the message.

Reimplemented from OMK::Flowable.

Definition at line 295 of file OMKSimpleTypeT.inl.

References OMK::Type::SimpleTypeT< T >::_value.

00296 { 
00297   out << _value ;
00298 }

template<typename T>
void OMK::Type::SimpleTypeT< T >::unpack ( IncomingSynchronisationMessage in  )  [virtual]

Unpack datas from the message.

Reimplemented from OMK::Flowable.

Definition at line 301 of file OMKSimpleTypeT.inl.

References OMK::Type::SimpleTypeT< T >::_value.

Referenced by OMK::AbstractFifo< T >::unpackAllValues().

00302 {
00303   in  >> _value ; 
00304 }

PolatorNT * OMK::Type::TransformType::createPolator (  )  [inline, virtual]

Default polator creator.

Implements OMK::Type::Base.

Definition at line 46 of file OMKBaseType.h.

00046 { return new NumericPolatorT< int    >() ; }


Member Data Documentation

template<typename T>
T OMK::Type::SimpleTypeT< T >::_value [protected]

This member holds the value value of SimpleTypeT.

The value of the type.

Definition at line 216 of file OMKSimpleTypeT.h.

Referenced by OMK::Type::SimpleTypeT< T >::extract(), OMK::Type::SimpleTypeT< OMK::Type::Transform >::getValue(), OMK::Type::SimpleTypeT< T >::insertInStream(), OMK::Type::SimpleTypeT< Type >::operator const Type &(), OMK::Type::SimpleTypeT< OMK::Type::Transform >::operator=(), OMK::Type::SimpleTypeT< OMK::Type::Transform >::operator==(), OMK::Type::SimpleTypeT< T >::pack(), OMK::Type::SimpleTypeT< OMK::Type::Transform >::resetDefaultValues(), OMK::Type::SimpleTypeT< OMK::Type::Transform >::setValue(), and OMK::Type::SimpleTypeT< T >::unpack().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:05 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007