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::
55 // -------------------------------------------------------------------------
56 cpPlugins::Interface::Parameters::
57 Parameters( const Self& other )
59 this->m_Parameters = other.m_Parameters;
62 // -------------------------------------------------------------------------
63 cpPlugins::Interface::Parameters::
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::
82 this->m_Parameters.clear( );
85 // -------------------------------------------------------------------------
86 void cpPlugins::Interface::Parameters::
87 Configure( const Self::Type& type, const TString& name )
89 this->m_Parameters[ name ] = TParameter( type, "" );
92 // -------------------------------------------------------------------------
93 std::vector< cpPlugins::Interface::Parameters::TString >
94 cpPlugins::Interface::Parameters::
95 GetParameters( ) const
97 std::vector< TString > parameters;
98 TParameters::const_iterator pIt = this->m_Parameters.begin( );
99 for( ; pIt != this->m_Parameters.end( ); ++pIt )
100 parameters.push_back( pIt->first );
101 return( parameters );
104 // -------------------------------------------------------------------------
105 cpPlugins::Interface::Parameters::
106 Type cpPlugins::Interface::Parameters::
107 GetParameterType( const TString& name ) const
109 TParameters::const_iterator pIt = this->m_Parameters.find( name );
110 if( pIt == this->m_Parameters.end( ) )
111 return( Self::NoType );
112 return( pIt->second.first );
115 // -------------------------------------------------------------------------
116 const cpPlugins::Interface::Parameters::
117 TString& cpPlugins::Interface::Parameters::
118 GetValueAsString( const TString& name ) const
120 static const TString null_str = "";
121 TParameters::const_iterator pIt = this->m_Parameters.find( name );
122 if( pIt == this->m_Parameters.end( ) )
124 if( pIt->second.first != Self::String )
127 return( pIt->second.second );
130 // -------------------------------------------------------------------------
131 cpPlugins::Interface::Parameters::
132 TInt cpPlugins::Interface::Parameters::
133 GetValueAsInt( const TString& name ) const
135 TParameters::const_iterator pIt = this->m_Parameters.find( name );
136 if( pIt == this->m_Parameters.end( ) )
138 if( pIt->second.first != Self::Int )
140 return( TInt( std::atoi( pIt->second.second.c_str( ) ) ) );
143 // -------------------------------------------------------------------------
144 cpPlugins::Interface::Parameters::
145 TUint cpPlugins::Interface::Parameters::
146 GetValueAsUint( const TString& name ) const
148 TParameters::const_iterator pIt = this->m_Parameters.find( name );
149 if( pIt == this->m_Parameters.end( ) )
150 return( TUint( 0 ) );
151 if( pIt->second.first != Self::Uint )
152 return( TUint( 0 ) );
153 return( TUint( std::atoi( pIt->second.second.c_str( ) ) ) );
156 // -------------------------------------------------------------------------
157 cpPlugins::Interface::Parameters::
158 TReal cpPlugins::Interface::Parameters::
159 GetValueAsReal( const TString& name ) const
161 TParameters::const_iterator pIt = this->m_Parameters.find( name );
162 if( pIt == this->m_Parameters.end( ) )
163 return( TReal( 0 ) );
164 if( pIt->second.first != Self::Real )
165 return( TReal( 0 ) );
166 return( TReal( std::atof( pIt->second.second.c_str( ) ) ) );
169 // -------------------------------------------------------------------------
170 void cpPlugins::Interface::Parameters::
171 GetValueAsStringList(
172 std::vector< TString >& lst, const TString& name
177 // -------------------------------------------------------------------------
178 void cpPlugins::Interface::Parameters::
179 GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const
183 // -------------------------------------------------------------------------
184 void cpPlugins::Interface::Parameters::
185 GetValueAsUintList( std::vector< TUint >& lst, const TString& name ) const
189 // -------------------------------------------------------------------------
190 void cpPlugins::Interface::Parameters::
191 GetValueAsRealList( std::vector< TReal >& lst, const TString& name ) const