1 #include <cpPlugins/Interface/Parameters.h>
6 // -------------------------------------------------------------------------
7 #define cpPlugins_Interface_Parameters_SetMacro( TYPE ) \
8 void cpPlugins::Interface::Parameters:: \
9 SetValueAs##TYPE( const TString& name, const T##TYPE& v ) \
11 TParameters::iterator pIt = this->m_Parameters.find( name ); \
12 if( pIt == this->m_Parameters.end( ) ) \
14 if( pIt->second.first != Self::TYPE ) \
16 std::stringstream ss; \
18 pIt->second.second = ss.str( ); \
21 cpPlugins_Interface_Parameters_SetMacro( String );
22 cpPlugins_Interface_Parameters_SetMacro( Int );
23 cpPlugins_Interface_Parameters_SetMacro( Uint );
24 cpPlugins_Interface_Parameters_SetMacro( Real );
26 // -------------------------------------------------------------------------
27 #define cpPlugins_Interface_Parameters_SetArrayMacro( TYPE, ATYPE ) \
28 void cpPlugins::Interface::Parameters:: \
29 SetValueAs##TYPE( const TString& name, const TUint& n, ... ) \
31 TParameters::iterator pIt = this->m_Parameters.find( name ); \
32 if( pIt == this->m_Parameters.end( ) ) \
34 if( pIt->second.first != Self::TYPE ) \
37 va_start( v_lst, n ); \
38 std::stringstream ss; \
39 for( TUint i = 0; i < n; ++i ) \
40 ss << va_arg( v_lst, ATYPE ) << ","; \
42 pIt->second.second = ss.str( ); \
45 cpPlugins_Interface_Parameters_SetArrayMacro( Index, long );
46 cpPlugins_Interface_Parameters_SetArrayMacro( Point, double );
48 // -------------------------------------------------------------------------
49 cpPlugins::Interface::Parameters::
52 this->m_Parameters.clear( );
55 // -------------------------------------------------------------------------
56 cpPlugins::Interface::Parameters::
57 Parameters( const Self& other )
59 this->m_Parameters = other.m_Parameters;
62 // -------------------------------------------------------------------------
63 cpPlugins::Interface::Parameters::
66 this->m_Parameters.clear( );
69 // -------------------------------------------------------------------------
70 cpPlugins::Interface::Parameters::
71 Self& cpPlugins::Interface::Parameters::
72 operator=( const Self& other )
74 this->m_Parameters = other.m_Parameters;
78 // -------------------------------------------------------------------------
79 void cpPlugins::Interface::Parameters::
80 Configure( const Self::Type& type, const TString& name )
82 this->m_Parameters[ name ] = TParameter( type, "" );
85 // -------------------------------------------------------------------------
86 std::vector< cpPlugins::Interface::Parameters::TString >
87 cpPlugins::Interface::Parameters::
88 GetParameters( ) const
90 std::vector< TString > parameters;
91 TParameters::const_iterator pIt = this->m_Parameters.begin( );
92 for( ; pIt != this->m_Parameters.end( ); ++pIt )
93 parameters.push_back( pIt->first );
97 // -------------------------------------------------------------------------
98 cpPlugins::Interface::Parameters::
99 Type cpPlugins::Interface::Parameters::
100 GetParameterType( const TString& name ) const
102 TParameters::const_iterator pIt = this->m_Parameters.find( name );
103 if( pIt == this->m_Parameters.end( ) )
104 return( Self::NoType );
105 return( pIt->second.first );
108 // -------------------------------------------------------------------------
109 const cpPlugins::Interface::Parameters::
110 TString& cpPlugins::Interface::Parameters::
111 GetValueAsString( const TString& name ) const
113 static const TString null_str = "";
114 TParameters::const_iterator pIt = this->m_Parameters.find( name );
115 if( pIt == this->m_Parameters.end( ) )
117 if( pIt->second.first != Self::String )
120 return( pIt->second.second );
123 // -------------------------------------------------------------------------
124 cpPlugins::Interface::Parameters::
125 TInt cpPlugins::Interface::Parameters::
126 GetValueAsInt( const TString& name ) const
128 TParameters::const_iterator pIt = this->m_Parameters.find( name );
129 if( pIt == this->m_Parameters.end( ) )
131 if( pIt->second.first != Self::Int )
133 return( TInt( std::atoi( pIt->second.second.c_str( ) ) ) );
136 // -------------------------------------------------------------------------
137 cpPlugins::Interface::Parameters::
138 TUint cpPlugins::Interface::Parameters::
139 GetValueAsUint( const TString& name ) const
141 TParameters::const_iterator pIt = this->m_Parameters.find( name );
142 if( pIt == this->m_Parameters.end( ) )
143 return( TUint( 0 ) );
144 if( pIt->second.first != Self::Uint )
145 return( TUint( 0 ) );
146 return( TUint( std::atoi( pIt->second.second.c_str( ) ) ) );
149 // -------------------------------------------------------------------------
150 cpPlugins::Interface::Parameters::
151 TReal cpPlugins::Interface::Parameters::
152 GetValueAsReal( const TString& name ) const
154 TParameters::const_iterator pIt = this->m_Parameters.find( name );
155 if( pIt == this->m_Parameters.end( ) )
156 return( TReal( 0 ) );
157 if( pIt->second.first != Self::Real )
158 return( TReal( 0 ) );
159 return( TReal( std::atof( pIt->second.second.c_str( ) ) ) );
162 // -------------------------------------------------------------------------
163 void cpPlugins::Interface::Parameters::
164 GetValueAsStringList(
165 std::vector< TString >& lst, const TString& name
170 // -------------------------------------------------------------------------
171 void cpPlugins::Interface::Parameters::
172 GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const
176 // -------------------------------------------------------------------------
177 void cpPlugins::Interface::Parameters::
178 GetValueAsUintList( std::vector< TUint >& lst, const TString& name ) const
182 // -------------------------------------------------------------------------
183 void cpPlugins::Interface::Parameters::
184 GetValueAsRealList( std::vector< TReal >& lst, const TString& name ) const