19#ifndef __itkParameterMapInterface_h
20#define __itkParameterMapInterface_h
23#include "itkObjectFactory.h"
25#include "itkNumericTraits.h"
101 itkSetMacro( PrintErrorMessages,
bool );
102 itkGetConstMacro( PrintErrorMessages,
bool );
106 const std::string & parameterName )
const;
124 const std::string & parameterName,
125 const unsigned int entry_nr,
126 const bool printThisErrorMessage,
127 std::string & errorMessage )
const
137 if( numberOfEntries == 0 )
139 std::stringstream ss;
140 ss <<
"WARNING: The parameter \"" << parameterName
141 <<
"\", requested at entry number " << entry_nr
142 <<
", does not exist at all.\n"
143 <<
" The default value \"" << parameterValue
144 <<
"\" is used instead." << std::endl;
147 errorMessage = ss.str();
157 if( entry_nr >= numberOfEntries )
159 std::stringstream ss;
160 ss <<
"WARNING: The parameter \"" << parameterName
161 <<
"\" does not exist at entry number " << entry_nr
162 <<
".\n The default value \"" << parameterValue
163 <<
"\" is used instead." << std::endl;
166 errorMessage = ss.str();
172 bool castSuccesful = this->
StringCast( vec[ entry_nr ], parameterValue );
177 std::stringstream ss;
178 ss <<
"ERROR: Casting entry number " << entry_nr
179 <<
" for the parameter \"" << parameterName
181 <<
" You tried to cast \"" << vec[ entry_nr ]
182 <<
"\" from std::string to "
183 <<
typeid( parameterValue ).name() << std::endl;
185 itkExceptionMacro( << ss.str() );
195 const std::string & parameterName,
196 const unsigned int entry_nr,
197 const bool printThisErrorMessage,
198 std::string & errorMessage )
const;
205 const std::string & parameterName,
206 const unsigned int entry_nr,
207 std::string & errorMessage )
const
209 return this->
ReadParameter( parameterValue, parameterName, entry_nr,
210 true, errorMessage );
221 const std::string & parameterName,
222 const std::string & prefix,
223 const unsigned int entry_nr,
224 const int default_entry_nr,
225 const bool printThisErrorMessage,
226 std::string & errorMessage )
const
228 std::string fullname = prefix + parameterName;
232 std::string dummyString =
"";
233 if( default_entry_nr >= 0 )
236 unsigned int uintdefault =
static_cast< unsigned int >( default_entry_nr );
237 found |= this->
ReadParameter( parameterValue, parameterName, uintdefault,
238 false, dummyString );
239 found |= this->
ReadParameter( parameterValue, parameterName, entry_nr,
240 false, dummyString );
241 found |= this->
ReadParameter( parameterValue, fullname, uintdefault,
242 false, dummyString );
243 found |= this->
ReadParameter( parameterValue, fullname, entry_nr,
244 false, dummyString );
249 found |= this->
ReadParameter( parameterValue, parameterName, entry_nr,
250 false, dummyString );
251 found |= this->
ReadParameter( parameterValue, fullname, entry_nr,
252 false, dummyString );
260 return this->
ReadParameter( parameterValue, parameterName, entry_nr,
261 true, errorMessage );
274 const std::string & parameterName,
275 const std::string & prefix,
276 const unsigned int entry_nr,
277 const unsigned int default_entry_nr,
278 std::string & errorMessage )
const
280 return this->
ReadParameter( parameterValue, parameterName, prefix,
281 entry_nr, default_entry_nr,
true, errorMessage );
288 std::vector< T > & parameterValues,
289 const std::string & parameterName,
290 const unsigned int entry_nr_start,
291 const unsigned int entry_nr_end,
292 const bool printThisErrorMessage,
293 std::string & errorMessage )
const
303 if( numberOfEntries == 0 )
305 std::stringstream ss;
306 ss <<
"WARNING: The parameter \"" << parameterName
307 <<
"\", requested between entry numbers " << entry_nr_start
308 <<
" and " << entry_nr_end
309 <<
", does not exist at all.\n"
310 <<
" The default values are used instead." << std::endl;
313 errorMessage = ss.str();
319 if( entry_nr_start > entry_nr_end )
321 std::stringstream ss;
322 ss <<
"WARNING: The entry number start (" << entry_nr_start
323 <<
") should be smaller than entry number end (" << entry_nr_end
324 <<
"). It was requested for parameter \"" << parameterName
325 <<
"\"." << std::endl;
328 itkExceptionMacro( << ss.str() );
332 if( entry_nr_end >= numberOfEntries )
334 std::stringstream ss;
335 ss <<
"WARNING: The parameter \"" << parameterName
336 <<
"\" does not exist at entry number " << entry_nr_end
337 <<
".\nThe default value \"" << itk::NumericTraits< T >::Zero
338 <<
"\" is used instead." << std::endl;
339 itkExceptionMacro( << ss.str() );
353 for(
unsigned int i = entry_nr_start; i < entry_nr_end + 1; ++i )
356 bool castSuccesful = this->
StringCast( vec[ i ], parameterValues[ j ] );
362 std::stringstream ss;
363 ss <<
"ERROR: Casting entry number " << i
364 <<
" for the parameter \"" << parameterName
366 <<
" You tried to cast \"" << vec[ i ]
367 <<
"\" from std::string to "
368 <<
typeid( parameterValues[ 0 ] ).name() << std::endl;
370 itkExceptionMacro( << ss.str() );
380 std::vector< std::string > & parameterValues,
381 const std::string & parameterName,
382 const unsigned int entry_nr_start,
383 const unsigned int entry_nr_end,
384 const bool printThisErrorMessage,
385 std::string & errorMessage )
const;
407 bool StringCast(
const std::string & parameterValue, T & casted )
const
409 std::stringstream ss( parameterValue );
415 typename NumericTraits< T >::AccumulateType tempCasted;
417 casted =
static_cast< T
>( tempCasted );
418 if( ss.bad() || ss.fail() )
430 bool StringCast(
const std::string & parameterValue, std::string & casted )
const;
std::vector< std::string > ParameterValuesType
std::map< std::string, ParameterValuesType > ParameterMapType
Implements functionality to get parameters from a parameter map.
bool ReadParameter(T ¶meterValue, const std::string ¶meterName, const unsigned int entry_nr, std::string &errorMessage) const
ParameterMapInterface(const Self &)
SmartPointer< const Self > ConstPointer
bool StringCast(const std::string ¶meterValue, std::string &casted) const
bool ReadParameter(T ¶meterValue, const std::string ¶meterName, const std::string &prefix, const unsigned int entry_nr, const int default_entry_nr, const bool printThisErrorMessage, std::string &errorMessage) const
bool m_PrintErrorMessages
ParameterMapType m_ParameterMap
void SetParameterMap(const ParameterMapType &parMap)
SmartPointer< Self > Pointer
ParameterFileParser::ParameterMapType ParameterMapType
~ParameterMapInterface() override
ParameterMapInterface Self
bool ReadParameter(std::vector< std::string > ¶meterValues, const std::string ¶meterName, const unsigned int entry_nr_start, const unsigned int entry_nr_end, const bool printThisErrorMessage, std::string &errorMessage) const
bool ReadParameter(T ¶meterValue, const std::string ¶meterName, const std::string &prefix, const unsigned int entry_nr, const unsigned int default_entry_nr, std::string &errorMessage) const
ParameterFileParser::ParameterValuesType ParameterValuesType
bool ReadParameter(bool ¶meterValue, const std::string ¶meterName, const unsigned int entry_nr, const bool printThisErrorMessage, std::string &errorMessage) const
void operator=(const Self &)
std::vcl_size_t CountNumberOfParameterEntries(const std::string ¶meterName) const
bool ReadParameter(T ¶meterValue, const std::string ¶meterName, const unsigned int entry_nr, const bool printThisErrorMessage, std::string &errorMessage) const
bool StringCast(const std::string ¶meterValue, T &casted) const
bool ReadParameter(std::vector< T > ¶meterValues, const std::string ¶meterName, const unsigned int entry_nr_start, const unsigned int entry_nr_end, const bool printThisErrorMessage, std::string &errorMessage) const