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( Bool );
23 cpPlugins_Interface_Parameters_SetMacro( Int );
24 cpPlugins_Interface_Parameters_SetMacro( Uint );
25 cpPlugins_Interface_Parameters_SetMacro( Real );
27 // -------------------------------------------------------------------------
28 #define cpPlugins_Interface_Parameters_SetArrayMacro( TYPE, ATYPE ) \
29 void cpPlugins::Interface::Parameters:: \
30 SetValueAs##TYPE( const TString& name, const TUint& n, ... ) \
32 TParameters::iterator pIt = this->m_Parameters.find( name ); \
33 if( pIt == this->m_Parameters.end( ) ) \
35 if( pIt->second.first != Self::TYPE ) \
38 va_start( v_lst, n ); \
39 std::stringstream ss; \
40 for( TUint i = 0; i < n; ++i ) \
41 ss << va_arg( v_lst, ATYPE ) << ","; \
43 pIt->second.second = ss.str( ); \
46 cpPlugins_Interface_Parameters_SetArrayMacro( Index, long );
47 cpPlugins_Interface_Parameters_SetArrayMacro( Point, double );
49 // -------------------------------------------------------------------------
50 cpPlugins::Interface::Parameters::
56 // -------------------------------------------------------------------------
57 cpPlugins::Interface::Parameters::
58 Parameters( const Self& other )
60 this->m_Parameters = other.m_Parameters;
63 // -------------------------------------------------------------------------
64 cpPlugins::Interface::Parameters::
70 // -------------------------------------------------------------------------
71 cpPlugins::Interface::Parameters::
72 Self& cpPlugins::Interface::Parameters::
73 operator=( const Self& other )
75 this->m_Parameters = other.m_Parameters;
79 // -------------------------------------------------------------------------
80 void cpPlugins::Interface::Parameters::
83 this->m_Parameters.clear( );
86 // -------------------------------------------------------------------------
87 void cpPlugins::Interface::Parameters::
88 Configure( const Self::Type& type, const TString& name )
90 this->m_Parameters[ name ] = TParameter( type, "" );
93 // -------------------------------------------------------------------------
94 std::vector< cpPlugins::Interface::Parameters::TString >
95 cpPlugins::Interface::Parameters::
96 GetParameters( ) const
98 std::vector< TString > parameters;
99 TParameters::const_iterator pIt = this->m_Parameters.begin( );
100 for( ; pIt != this->m_Parameters.end( ); ++pIt )
101 parameters.push_back( pIt->first );
102 return( parameters );
105 // -------------------------------------------------------------------------
106 cpPlugins::Interface::Parameters::
107 Type cpPlugins::Interface::Parameters::
108 GetParameterType( const TString& name ) const
110 TParameters::const_iterator pIt = this->m_Parameters.find( name );
111 if( pIt == this->m_Parameters.end( ) )
112 return( Self::NoType );
113 return( pIt->second.first );
116 // -------------------------------------------------------------------------
117 const cpPlugins::Interface::Parameters::
118 TString& cpPlugins::Interface::Parameters::
119 GetValueAsString( const TString& name ) const
121 static const TString null_str = "";
122 TParameters::const_iterator pIt = this->m_Parameters.find( name );
123 if( pIt == this->m_Parameters.end( ) )
125 if( pIt->second.first != Self::String )
128 return( pIt->second.second );
131 // -------------------------------------------------------------------------
132 cpPlugins::Interface::Parameters::
133 TBool cpPlugins::Interface::Parameters::
134 GetValueAsBool( const TString& name ) const
136 TParameters::const_iterator pIt = this->m_Parameters.find( name );
137 if( pIt == this->m_Parameters.end( ) )
138 return( TBool( false ) );
139 if( pIt->second.first != Self::Int )
140 return( TBool( false ) );
141 return( TBool( std::atoi( pIt->second.second.c_str( ) ) == 1 ) );
144 // -------------------------------------------------------------------------
145 cpPlugins::Interface::Parameters::
146 TInt cpPlugins::Interface::Parameters::
147 GetValueAsInt( const TString& name ) const
149 TParameters::const_iterator pIt = this->m_Parameters.find( name );
150 if( pIt == this->m_Parameters.end( ) )
152 if( pIt->second.first != Self::Int )
154 return( TInt( std::atoi( pIt->second.second.c_str( ) ) ) );
157 // -------------------------------------------------------------------------
158 cpPlugins::Interface::Parameters::
159 TUint cpPlugins::Interface::Parameters::
160 GetValueAsUint( const TString& name ) const
162 TParameters::const_iterator pIt = this->m_Parameters.find( name );
163 if( pIt == this->m_Parameters.end( ) )
164 return( TUint( 0 ) );
165 if( pIt->second.first != Self::Uint )
166 return( TUint( 0 ) );
167 return( TUint( std::atoi( pIt->second.second.c_str( ) ) ) );
170 // -------------------------------------------------------------------------
171 cpPlugins::Interface::Parameters::
172 TReal cpPlugins::Interface::Parameters::
173 GetValueAsReal( const TString& name ) const
175 TParameters::const_iterator pIt = this->m_Parameters.find( name );
176 if( pIt == this->m_Parameters.end( ) )
177 return( TReal( 0 ) );
178 if( pIt->second.first != Self::Real )
179 return( TReal( 0 ) );
180 return( TReal( std::atof( pIt->second.second.c_str( ) ) ) );
183 // -------------------------------------------------------------------------
184 void cpPlugins::Interface::Parameters::
185 GetValueAsStringList(
186 std::vector< TString >& lst, const TString& name
191 // -------------------------------------------------------------------------
192 void cpPlugins::Interface::Parameters::
193 GetValueAsBoolList( std::vector< TBool >& lst, const TString& name ) const
197 // -------------------------------------------------------------------------
198 void cpPlugins::Interface::Parameters::
199 GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const
203 // -------------------------------------------------------------------------
204 void cpPlugins::Interface::Parameters::
205 GetValueAsUintList( std::vector< TUint >& lst, const TString& name ) const
209 // -------------------------------------------------------------------------
210 void cpPlugins::Interface::Parameters::
211 GetValueAsRealList( std::vector< TReal >& lst, const TString& name ) const