--- /dev/null
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+
+$include "Value.e"
+
+#include <cpPlugins/Value.h>
+#include <cpPlugins/ProcessObject.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( )
+ : m_TypeName( "" ),
+ m_Bool( false ),
+ m_Natural( 0 ),
+ m_Integer( 0 ),
+ m_Real( 0 ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( "" )
+{
+ this->m_Source.reset( );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const std::type_info& i )
+ : m_Bool( false ),
+ m_Natural( 0 ),
+ m_Integer( 0 ),
+ m_Real( 0 ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( "" )
+{
+ if( i == typeid( bool ) )
+ this->m_TypeName = typeid( TBool ).name( );
+ else
+ {{#n}}
+ if( i == typeid( {{n}} ) )
+ this->m_TypeName = typeid( TNatural ).name( );
+ else
+ {{/n}}
+ {{#z}}
+ if( i == typeid( {{z}} ) )
+ this->m_TypeName = typeid( TInteger ).name( );
+ else
+ {{/z}}
+ {{#r}}
+ if( i == typeid( {{r}} ) )
+ this->m_TypeName = typeid( TReal ).name( );
+ else
+ {{/r}}
+ {{#r}}
+ if( i == typeid( std::complex< {{r}} > ) )
+ this->m_TypeName = typeid( TComplex ).name( );
+ else
+ {{/r}}
+ if( i == typeid( std::string ) )
+ this->m_TypeName = typeid( TString ).name( );
+ this->m_Source.reset( );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const Self& v )
+ : m_TypeName( v.m_TypeName ),
+ m_Bool( v.m_Bool ),
+ m_Natural( v.m_Natural ),
+ m_Integer( v.m_Integer ),
+ m_Real( v.m_Real ),
+ m_Complex( v.m_Complex ),
+ m_String( v.m_String ),
+ m_Source( v.m_Source )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const bool& v )
+ : m_TypeName( typeid( TBool ).name( ) ),
+ m_Bool( v ),
+ m_Natural( 0 ),
+ m_Integer( 0 ),
+ m_Real( 0 ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( "" )
+{
+ this->m_Source.reset( );
+}
+
+{{#n}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const {{n}}& v )
+ : m_TypeName( typeid( TNatural ).name( ) ),
+ m_Bool( false ),
+ m_Natural( TNatural( v ) ),
+ m_Integer( 0 ),
+ m_Real( 0 ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( "" )
+{
+ this->m_Source.reset( );
+}
+{{/n}}
+
+{{#z}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const {{z}}& v )
+ : m_TypeName( typeid( TInteger ).name( ) ),
+ m_Bool( false ),
+ m_Natural( 0 ),
+ m_Integer( TInteger( v ) ),
+ m_Real( 0 ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( "" )
+{
+ this->m_Source.reset( );
+}
+{{/z}}
+
+{{#r}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const {{r}}& v )
+ : m_TypeName( typeid( TReal ).name( ) ),
+ m_Bool( false ),
+ m_Natural( 0 ),
+ m_Integer( 0 ),
+ m_Real( TReal( v ) ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( "" )
+{
+ this->m_Source.reset( );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const std::complex< {{r}} >& v )
+ : m_TypeName( typeid( TComplex ).name( ) ),
+ m_Bool( false ),
+ m_Natural( 0 ),
+ m_Integer( 0 ),
+ m_Real( 0 ),
+ m_Complex( TComplex( std::real( v ), std::imag( v ) ) ),
+ m_String( "" )
+{
+ this->m_Source.reset( );
+}
+{{/r}}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Value( const std::string& v )
+ : m_TypeName( typeid( TString ).name( ) ),
+ m_Bool( false ),
+ m_Natural( 0 ),
+ m_Integer( 0 ),
+ m_Real( 0 ),
+ m_Complex( TComplex( 0 ) ),
+ m_String( v )
+{
+ this->m_Source.reset( );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+operator bool( ) const
+{
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ return( this->m_Bool );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ return( this->m_Natural != 0 );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ return( this->m_Integer != 0 );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ return( this->m_Real != 0 );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ return( std::norm( this->m_Complex ) != 0 );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ return( this->m_String.size( ) > 0 );
+ else
+ return( false );
+}
+
+{{#n}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+operator {{n}}( ) const
+{
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ return( ( {{n}} )( this->m_Bool ) );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ return( ( {{n}} )( this->m_Natural ) );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ return( ( {{n}} )( this->m_Integer ) );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ return( ( {{n}} )( this->m_Real ) );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ return( ( {{n}} )( std::real( this->m_Complex ) ) );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ {{n}} v;
+ std::istringstream s( this->m_String );
+ s >> v;
+ return( v );
+ }
+ else
+ return( 0 );
+}
+{{/n}}
+
+{{#z}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+operator {{z}}( ) const
+{
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ return( ( {{z}} )( this->m_Bool ) );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ return( ( {{z}} )( this->m_Natural ) );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ return( ( {{z}} )( this->m_Integer ) );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ return( ( {{z}} )( this->m_Real ) );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ return( ( {{z}} )( std::real( this->m_Complex ) ) );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ {{z}} v;
+ std::istringstream s( this->m_String );
+ s >> v;
+ return( v );
+ }
+ else
+ return( 0 );
+}
+{{/z}}
+
+{{#r}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+operator {{r}}( ) const
+{
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ return( ( {{r}} )( this->m_Bool ) );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ return( ( {{r}} )( this->m_Natural ) );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ return( ( {{r}} )( this->m_Integer ) );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ return( ( {{r}} )( this->m_Real ) );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ return( ( {{r}} )( std::real( this->m_Complex ) ) );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ {{r}} v;
+ std::istringstream s( this->m_String );
+ s >> v;
+ return( v );
+ }
+ else
+ return( 0 );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+operator std::complex< {{r}} >( ) const
+{
+ std::complex< {{r}} > c;
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ c = std::complex< {{r}} >( ( {{r}} )( this->m_Bool ) );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ c = std::complex< {{r}} >( ( {{r}} )( this->m_Natural ) );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ c = std::complex< {{r}} >( ( {{r}} )( this->m_Integer ) );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ c = std::complex< {{r}} >( ( {{r}} )( this->m_Real ) );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ c = std::complex< {{r}} >(
+ ( {{r}} )( std::real( this->m_Complex ) ),
+ ( {{r}} )( std::imag( this->m_Complex ) )
+ );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ // TODO: improve
+ {{r}} r, i;
+ std::istringstream s( this->m_String );
+ s >> r >> i;
+ c = std::complex< {{r}} >( r, i );
+ }
+ return( c );
+}
+{{/r}}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+operator std::string( ) const
+{
+ if( this->m_TypeName != typeid( TString ).name( ) )
+ {
+ std::stringstream ss;
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ ss << this->m_Bool;
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ ss << this->m_Natural;
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ ss << this->m_Integer;
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ ss << this->m_Real;
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ ss
+ << std::real( this->m_Complex ) << "+"
+ << std::imag( this->m_Complex ) << "i";
+ return( ss.str( ) );
+ }
+ else
+ return( this->m_String );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Self& cpPlugins::Value::
+operator=( const Self& v )
+{
+ if( this->m_TypeName == "" )
+ this->m_TypeName = v.m_TypeName;
+ this->m_String = "";
+ {{#w}}
+ if( v.m_TypeName == typeid( T{{w}} ).name( ) )
+ this->operator=( v.m_{{w}} );
+ else
+ {{/w}};
+ this->m_Source = v.m_Source;
+ return( *this );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Self& cpPlugins::Value::
+operator=( const bool& v )
+{
+ this->m_String = "";
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ this->m_Bool = v;
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ this->m_Natural = ( v )? 1: 0;
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ this->m_Integer = ( v )? 1: 0;
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ this->m_Real = ( v )? 1: 0;
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ this->m_Complex = TComplex( ( v )? 1: 0, 0 );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ std::stringstream ss;
+ ss << v;
+ this->m_String = ss.str( );
+ } // end if
+ return( *this );
+}
+
+{{#x}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Self& cpPlugins::Value::
+operator=( const {{x}}& v )
+{
+ this->m_String = "";
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ this->m_Bool = ( v != 0 );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ this->m_Natural = TNatural( v );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ this->m_Integer = TInteger( v );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ this->m_Real = TReal( v );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ this->m_Complex = TComplex( v );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ std::stringstream ss;
+ ss << v;
+ this->m_String = ss.str( );
+ } // end if
+ return( *this );
+}
+{{/x}}
+
+{{#r}}
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Self& cpPlugins::Value::
+operator=( const std::complex< {{r}} >& v )
+{
+ this->m_String = "";
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ this->m_Bool = ( std::real( v ) != 0 );
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ this->m_Natural = TNatural( std::real( v ) );
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ this->m_Integer = TInteger( std::real( v ) );
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ this->m_Real = TReal( std::real( v ) );
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ this->m_Complex = TComplex( std::real( v ), std::imag( v ) );
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ {
+ std::stringstream ss;
+ ss << std::real( v ) << "+" << std::imag( v ) << "i";
+ this->m_String = ss.str( );
+ } // end if
+ return( *this );
+}
+{{/r}}
+
+// -------------------------------------------------------------------------
+cpPlugins::Value::
+Self& cpPlugins::Value::
+operator=( const std::string& v )
+{
+ std::istringstream s( v );
+ this->m_String = "";
+ if( typeid( TBool ).name( ) == this->m_TypeName )
+ s >> this->m_Bool;
+ else if( typeid( TNatural ).name( ) == this->m_TypeName )
+ s >> this->m_Natural;
+ else if( typeid( TInteger ).name( ) == this->m_TypeName )
+ s >> this->m_Integer;
+ else if( typeid( TReal ).name( ) == this->m_TypeName )
+ s >> this->m_Real;
+ else if( typeid( TComplex ).name( ) == this->m_TypeName )
+ {
+ // TODO: s >> this->m_Bool;
+ }
+ else if( typeid( TString ).name( ) == this->m_TypeName )
+ this->m_String = v;
+ return( *this );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Value::
+operator<( const Self& v ) const
+{
+ if( this->m_TypeName == v.m_TypeName )
+ {
+ if( this->m_TypeName == typeid( TBool ).name( ) )
+ return( this->m_Bool < v.m_Bool );
+ else if( this->m_TypeName == typeid( TNatural ).name( ) )
+ return( this->m_Natural < v.m_Natural );
+ else if( this->m_TypeName == typeid( TInteger ).name( ) )
+ return( this->m_Integer < v.m_Integer );
+ else if( this->m_TypeName == typeid( TReal ).name( ) )
+ return( this->m_Real < v.m_Real );
+ else if( this->m_TypeName == typeid( TString ).name( ) )
+ return( this->m_String < v.m_String );
+ else if( this->m_TypeName == typeid( TComplex ).name( ) )
+ {
+ if( std::real( this->m_Complex ) == std::real( v.m_Complex ) )
+ return(
+ std::imag( this->m_Complex ) < std::imag( v.m_Complex )
+ );
+ else
+ return(
+ std::real( this->m_Complex ) < std::real( v.m_Complex )
+ );
+ } // end if
+ }
+ else
+ return( false );
+}
+
+// -------------------------------------------------------------------------
+const std::string& cpPlugins::Value::
+GetTypeName( ) const
+{
+ return( this->m_TypeName );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::ProcessObject* cpPlugins::Value::
+GetSource( )
+{
+ if( !( this->m_Source.expired( ) ) )
+ return( this->m_Source.lock( ).get( ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::ProcessObject* cpPlugins::Value::
+GetSource( ) const
+{
+ if( !( this->m_Source.expired( ) ) )
+ return( this->m_Source.lock( ).get( ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+template<>
+void cpPlugins::Value::
+SetSource( cpPlugins::ProcessObject* source )
+{
+ if( source != NULL )
+ this->m_Source = source->CastWeakPtr< cpPlugins::ProcessObject >( );
+ else
+ this->m_Source.reset( );
+}
+
+// -------------------------------------------------------------------------
+template<>
+void cpPlugins::Value::
+SetSource( cpPlugins::Parameters* source )
+{
+ this->SetSource( dynamic_cast< cpPlugins::ProcessObject* >( source ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Value::
+Print( std::ostream& o ) const
+{
+ o << std::string( *this );
+}
+
+// eof - $RCSfile$