]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.hxx
Kind of bored: graph editor debugged
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.hxx
1 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
2 #define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
3
4 // -------------------------------------------------------------------------
5 template< class I >
6 I cpPlugins::Interface::Parameters::
7 GetIndex( const TString& name, const TUint& dim ) const
8 {
9   I v;
10   TParameters::const_iterator i = this->m_Parameters.find( name );
11   if( i != this->m_Parameters.end( ) )
12   {
13     if( i->second.first == Self::Index )
14     {
15       std::istringstream str( i->second.second );
16       std::string token;
17       unsigned int d = 0;
18       while( std::getline( str, token, ';' ) && d < dim )
19       {
20         v[ d ] = std::atoi( token.c_str( ) );
21         d++;
22
23       } // elihw
24       return( v );
25
26     } // fi
27
28   } // fi
29
30   // If parameter not found
31   for( unsigned int d = 0; d < dim; ++d )
32     v[ d ] = 0;
33   return( v );
34 }
35
36 // -------------------------------------------------------------------------
37 template< class P >
38 P cpPlugins::Interface::Parameters::
39 GetPoint( const TString& name, const TUint& dim ) const
40 {
41   P v;
42   TParameters::const_iterator i = this->m_Parameters.find( name );
43   if( i != this->m_Parameters.end( ) )
44   {
45     if( i->second.first == Self::Point )
46     {
47       std::istringstream str( i->second.second );
48       std::string token;
49       unsigned int d = 0;
50       while( std::getline( str, token, ';' ) && d < dim )
51       {
52         std::istringstream tok_str( token );
53         tok_str >> v[ d ];
54         d++;
55
56       } // elihw
57       return( v );
58
59     } // fi
60
61   } // fi
62
63   // If parameter not found
64   for( unsigned int d = 0; d < dim; ++d )
65     v[ d ] = float( 0 );
66   return( v );
67 }
68
69 // -------------------------------------------------------------------------
70 template< class V >
71 V cpPlugins::Interface::Parameters::
72 GetVector( const TString& name, const TUint& dim ) const
73 {
74   V v;
75   TParameters::const_iterator i = this->m_Parameters.find( name );
76   if( i != this->m_Parameters.end( ) )
77   {
78     if( i->second.first == Self::Vector )
79     {
80       std::istringstream str( i->second.second );
81       std::string token;
82       unsigned int d = 0;
83       while( std::getline( str, token, ';' ) && d < dim )
84       {
85         std::istringstream tok_str( token );
86         tok_str >> v[ d ];
87         d++;
88
89       } // elihw
90       return( v );
91
92     } // fi
93
94   } // fi
95
96   // If parameter not found
97   for( unsigned int d = 0; d < dim; ++d )
98     v[ d ] = float( 0 );
99   return( v );
100 }
101
102 // -------------------------------------------------------------------------
103 template< class I >
104 void cpPlugins::Interface::Parameters::
105 GetIndexList(
106   std::vector< I >& lst, const TString& name, const TUint& dim
107   ) const
108 {
109   lst.clear( );
110
111   TParameters::const_iterator i = this->m_Parameters.find( name );
112   if( i == this->m_Parameters.end( ) )
113     return;
114   if( i->second.first == Self::IndexList )
115     return;
116
117   std::istringstream str( i->second.second );
118   std::string token;
119   unsigned int d = 0;
120   while( std::getline( str, token, '#' ) )
121   {
122     std::istringstream str2( token );
123     std::string token2;
124     unsigned int d = 0;
125     I v;
126     while( std::getline( str2, token2, ';' ) && d < dim )
127     {
128       v[ d ] = std::atoi( token.c_str( ) );
129       d++;
130
131     } // elihw
132     lst.push_back( v );
133
134   } // elihw
135 }
136
137 // -------------------------------------------------------------------------
138 template< class P >
139 void cpPlugins::Interface::Parameters::
140 GetPointList(
141   std::vector< P >& lst, const TString& name, const TUint& dim
142   ) const
143 {
144   lst.clear( );
145
146   TParameters::const_iterator i = this->m_Parameters.find( name );
147   if( i == this->m_Parameters.end( ) )
148     return;
149   if( i->second.first == Self::PointList )
150     return;
151
152   std::istringstream str( i->second.second );
153   std::string token;
154   unsigned int d = 0;
155   while( std::getline( str, token, '#' ) )
156   {
157     std::istringstream str2( token );
158     std::string token2;
159     unsigned int d = 0;
160     P v;
161     while( std::getline( str2, token2, ';' ) && d < dim )
162     {
163       std::istringstream tok_str( token );
164       tok_str >> v[ d ];
165       d++;
166
167     } // elihw
168     lst.push_back( v );
169
170   } // elihw
171 }
172
173 // -------------------------------------------------------------------------
174 template< class V >
175 void cpPlugins::Interface::Parameters::
176 GetVectorList(
177   std::vector< V >& lst, const TString& name, const TUint& dim
178   ) const
179 {
180   lst.clear( );
181
182   TParameters::const_iterator i = this->m_Parameters.find( name );
183   if( i == this->m_Parameters.end( ) )
184     return;
185   if( i->second.first == Self::VectorList )
186     return;
187
188   std::istringstream str( i->second.second );
189   std::string token;
190   unsigned int d = 0;
191   while( std::getline( str, token, '#' ) )
192   {
193     std::istringstream str2( token );
194     std::string token2;
195     unsigned int d = 0;
196     V v;
197     while( std::getline( str2, token2, ';' ) && d < dim )
198     {
199       std::istringstream tok_str( token );
200       tok_str >> v[ d ];
201       d++;
202
203     } // elihw
204     lst.push_back( v );
205
206   } // elihw
207 }
208
209 // -------------------------------------------------------------------------
210 template< class I >
211 void cpPlugins::Interface::Parameters::
212 SetIndex( const TString& name, const TUint& dim, const I& v )
213 {
214   TParameters::iterator i = this->m_Parameters.find( name );
215   if( i == this->m_Parameters.end( ) )
216     return;
217   if( i->second.first != Self::Index )
218     return;
219
220   std::stringstream str;
221   str << v[ 0 ];
222   for( unsigned int d = 1; d < dim; ++d )
223     str << ";" << v[ d ];
224   i->second.second = str.str( );
225   this->Modified( );
226 }
227
228 // -------------------------------------------------------------------------
229 template< class P >
230 void cpPlugins::Interface::Parameters::
231 SetPoint( const TString& name, const TUint& dim, const P& v )
232 {
233   TParameters::iterator i = this->m_Parameters.find( name );
234   if( i == this->m_Parameters.end( ) )
235     return;
236   if( i->second.first != Self::Point )
237     return;
238
239   std::stringstream str;
240   str << v[ 0 ];
241   for( unsigned int d = 1; d < dim; ++d )
242     str << ";" << v[ d ];
243   i->second.second = str.str( );
244   this->Modified( );
245 }
246
247 // -------------------------------------------------------------------------
248 template< class V >
249 void cpPlugins::Interface::Parameters::
250 SetVector( const TString& name, const TUint& dim, const V& v )
251 {
252   TParameters::iterator i = this->m_Parameters.find( name );
253   if( i == this->m_Parameters.end( ) )
254     return;
255   if( i->second.first != Self::Vector )
256     return;
257
258   std::stringstream str;
259   str << v[ 0 ];
260   for( unsigned int d = 1; d < dim; ++d )
261     str << ";" << v[ d ];
262   i->second.second = str.str( );
263   this->Modified( );
264 }
265
266 // -------------------------------------------------------------------------
267 template< class I >
268 void cpPlugins::Interface::Parameters::
269 AddToIndexList( const TString& name, const TUint& dim, const I& v )
270 {
271   TParameters::iterator i = this->m_Parameters.find( name );
272   if( i == this->m_Parameters.end( ) )
273     return;
274   if( i->second.first != Self::IndexList )
275     return;
276
277   std::stringstream str;
278   if( i->second.second == "" )
279     str << v[ 0 ];
280   else
281     str << "#" << v[ 0 ];
282   for( unsigned int d = 1; d < dim; ++d )
283     str << ";" << v[ d ];
284   i->second.second += str.str( );
285   this->Modified( );
286 }
287
288 // -------------------------------------------------------------------------
289 template< class P >
290 void cpPlugins::Interface::Parameters::
291 AddToPointList( const TString& name, const TUint& dim, const P& v )
292 {
293   TParameters::iterator i = this->m_Parameters.find( name );
294   if( i == this->m_Parameters.end( ) )
295     return;
296   if( i->second.first != Self::PointList )
297     return;
298
299   std::stringstream str;
300   if( i->second.second == "" )
301     str << v[ 0 ];
302   else
303     str << "#" << v[ 0 ];
304   for( unsigned int d = 1; d < dim; ++d )
305     str << ";" << v[ d ];
306   i->second.second += str.str( );
307   this->Modified( );
308 }
309
310 // -------------------------------------------------------------------------
311 template< class V >
312 void cpPlugins::Interface::Parameters::
313 AddToVectorList( const TString& name, const TUint& dim, const V& v )
314 {
315   TParameters::iterator i = this->m_Parameters.find( name );
316   if( i == this->m_Parameters.end( ) )
317     return;
318   if( i->second.first != Self::VectorList )
319     return;
320
321   std::stringstream str;
322   if( i->second.second == "" )
323     str << v[ 0 ];
324   else
325     str << "#" << v[ 0 ];
326   for( unsigned int d = 1; d < dim; ++d )
327     str << ";" << v[ d ];
328   i->second.second += str.str( );
329   this->Modified( );
330 }
331
332 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
333
334 // eof - $RCSfile$