libMesh::Parameters Class Reference

#include <parameters.h>

Classes

class  Parameter
 
class  Value
 

Public Types

typedef std::map< std::string, Value * >::iterator iterator
 
typedef std::map< std::string, Value * >::const_iterator const_iterator
 

Public Member Functions

 Parameters ()
 
 Parameters (const Parameters &)
 
virtual ~Parameters ()
 
virtual Parametersoperator= (const Parameters &source)
 
virtual Parametersoperator+= (const Parameters &source)
 
template<typename T >
bool have_parameter (const std::string &) const
 
template<typename T >
const T & get (const std::string &) const
 
template<typename T >
void insert (const std::string &)
 
template<typename T >
T & set (const std::string &)
 
virtual void set_attributes (const std::string &, bool)
 
void remove (const std::string &)
 
std::size_t n_parameters () const
 
template<typename T >
unsigned int n_parameters () const
 
virtual void clear ()
 
void print (std::ostream &os=libMesh::out) const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 

Protected Attributes

std::map< std::string, Value * > _values
 

Detailed Description

This class provides the ability to map between arbitrary, user-defined strings and several data types. This can be used to provide arbitrary user-specified options.

Author
Benjamin S. Kirk
Date
2004

Definition at line 63 of file parameters.h.

Member Typedef Documentation

typedef std::map<std::string, Value *>::const_iterator libMesh::Parameters::const_iterator

Constant parameter map iterator.

Definition at line 251 of file parameters.h.

typedef std::map<std::string, Value *>::iterator libMesh::Parameters::iterator

Parameter map iterator.

Definition at line 246 of file parameters.h.

Constructor & Destructor Documentation

libMesh::Parameters::Parameters ( )
inline

Default constructor. Does nothing.

Definition at line 70 of file parameters.h.

References have_parameter(), insert(), operator+=(), operator=(), and ~Parameters().

70 {}
libMesh::Parameters::Parameters ( const Parameters p)
inline

Copy constructor.

Definition at line 360 of file parameters.h.

361 {
362  *this = p;
363 }
libMesh::Parameters::~Parameters ( )
inlinevirtual

Destructor. Clears any allocated memory.

Definition at line 368 of file parameters.h.

References clear().

Referenced by Parameters().

369 {
370  this->clear ();
371 }
virtual void clear()
Definition: parameters.h:321

Member Function Documentation

Parameters::iterator libMesh::Parameters::begin ( )
inline

Iterator pointing to the beginning of the set of parameters.

Definition at line 514 of file parameters.h.

References _values.

515 {
516  return _values.begin();
517 }
std::map< std::string, Value * > _values
Definition: parameters.h:278
Parameters::const_iterator libMesh::Parameters::begin ( ) const
inline

Iterator pointing to the beginning of the set of parameters.

Definition at line 520 of file parameters.h.

References _values.

521 {
522  return _values.begin();
523 }
std::map< std::string, Value * > _values
Definition: parameters.h:278
void libMesh::Parameters::clear ( )
inlinevirtual

Clears internal data structures & frees any allocated memory.

Definition at line 321 of file parameters.h.

References _values, and libmesh_nullptr.

Referenced by libMesh::EquationSystems::clear(), n_parameters(), operator=(), and ~Parameters().

322 { // before its first use (for some compilers)
323  while (!_values.empty())
324  {
325  Parameters::iterator it = _values.begin();
326 
327  delete it->second;
328  it->second = libmesh_nullptr;
329 
330  _values.erase(it);
331  }
332 }
std::map< std::string, Value * >::iterator iterator
Definition: parameters.h:246
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:278
Parameters::iterator libMesh::Parameters::end ( )
inline

Iterator pointing to the end of the set of parameters

Definition at line 526 of file parameters.h.

References _values.

527 {
528  return _values.end();
529 }
std::map< std::string, Value * > _values
Definition: parameters.h:278
Parameters::const_iterator libMesh::Parameters::end ( ) const
inline

Iterator pointing to the end of the set of parameters

Definition at line 532 of file parameters.h.

References _values.

533 {
534  return _values.end();
535 }
std::map< std::string, Value * > _values
Definition: parameters.h:278
template<typename T >
const T & libMesh::Parameters::get ( const std::string &  name) const
inline
Returns
a constant reference to the specified parameter value. Requires, of course, that the parameter exists.

Definition at line 430 of file parameters.h.

References _values, libMesh::demangle(), libMesh::libmesh_assert(), and libMesh::Quality::name().

Referenced by libMesh::FrequencySystem::clear_all(), libMesh::ImplicitSystem::get_linear_solve_parameters(), libMesh::FEComputeData::init(), libMesh::FrequencySystem::init_data(), libMesh::FrequencySystem::n_frequencies(), libMesh::FrequencySystem::set_current_frequency(), libMesh::NonlinearImplicitSystem::set_solver_parameters(), libMesh::EigenSystem::solve(), libMesh::CondensedEigenSystem::solve(), libMesh::FrequencySystem::solve(), and libMesh::LinearImplicitSystem::solve().

431 {
432  if (!this->have_parameter<T>(name))
433  {
434  std::ostringstream oss;
435 
436  oss << "ERROR: no";
437 #ifdef LIBMESH_HAVE_RTTI
438  oss << ' ' << demangle(typeid(T).name());
439 #endif
440  oss << " parameter named \""
441  << name << "\" found.\n\n"
442  << "Known parameters:\n"
443  << *this;
444 
445  libmesh_error_msg(oss.str());
446  }
447 
448  Parameters::const_iterator it = _values.find(name);
449 
450  libmesh_assert(it != _values.end());
451  libmesh_assert(it->second);
452 
453  return cast_ptr<Parameter<T> *>(it->second)->get();
454 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:251
libmesh_assert(j)
std::string demangle(const char *name)
Definition: print_trace.C:233
std::map< std::string, Value * > _values
Definition: parameters.h:278
template<typename T >
bool libMesh::Parameters::have_parameter ( const std::string &  name) const
inline
Returns
true if a parameter of type T with a specified name exists, false otherwise.

If RTTI has been disabled then we return true if a parameter of specified name exists regardless of its type.

Definition at line 411 of file parameters.h.

References _values, libMesh::cast_ptr(), and libmesh_nullptr.

Referenced by libMesh::FrequencySystem::clear_all(), libMesh::FEComputeData::init(), libMesh::FrequencySystem::init_data(), Parameters(), libMesh::EigenSystem::solve(), and libMesh::CondensedEigenSystem::solve().

412 {
414 
415  if (it != _values.end())
416 #ifdef LIBMESH_HAVE_RTTI
417  if (dynamic_cast<const Parameter<T> *>(it->second) != libmesh_nullptr)
418 #else // LIBMESH_HAVE_RTTI
419  if (cast_ptr<const Parameter<T> *>(it->second) != libmesh_nullptr)
420 #endif // LIBMESH_HAVE_RTTI
421  return true;
422 
423  return false;
424 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:251
Tnew cast_ptr(Told *oldvar)
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:278
template<typename T >
void libMesh::Parameters::insert ( const std::string &  name)
inline

Inserts a new Parameter into the object but does not return a writable reference. The value of the newly inserted parameter may not be valid.

Definition at line 458 of file parameters.h.

References _values, libMesh::Quality::name(), and set_attributes().

Referenced by Parameters().

459 {
460  if (!this->have_parameter<T>(name))
461  _values[name] = new Parameter<T>;
462 
463  set_attributes(name, true);
464 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * > _values
Definition: parameters.h:278
virtual void set_attributes(const std::string &, bool)
Definition: parameters.h:133
std::size_t libMesh::Parameters::n_parameters ( ) const
inline
Returns
the total number of parameters.

Definition at line 143 of file parameters.h.

References _values, clear(), libMesh::out, and print().

143 { return _values.size(); }
std::map< std::string, Value * > _values
Definition: parameters.h:278
template<typename T >
unsigned int libMesh::Parameters::n_parameters ( ) const
inline
Returns
the number of parameters of the requested type.

Definition at line 498 of file parameters.h.

References _values, and libmesh_nullptr.

499 {
500  unsigned int cnt = 0;
501 
502  Parameters::const_iterator it = _values.begin();
503  const Parameters::const_iterator vals_end = _values.end();
504 
505  for (; it != vals_end; ++it)
506  if (dynamic_cast<Parameter<T> *>(it->second) != libmesh_nullptr)
507  cnt++;
508 
509  return cnt;
510 }
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:251
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:278
Parameters & libMesh::Parameters::operator+= ( const Parameters source)
inlinevirtual

Addition/Assignment operator. Inserts copies of all parameters from source. Any parameters of the same name already in this are replaced.

Definition at line 346 of file parameters.h.

References _values.

Referenced by Parameters().

347 {
348  for (Parameters::const_iterator it = source._values.begin();
349  it != source._values.end(); ++it)
350  {
351  if (_values.find(it->first) != _values.end())
352  delete _values[it->first];
353  _values[it->first] = it->second->clone();
354  }
355 
356  return *this;
357 }
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:251
std::map< std::string, Value * > _values
Definition: parameters.h:278
Parameters & libMesh::Parameters::operator= ( const Parameters source)
inlinevirtual

Assignment operator. Removes all parameters in this and inserts copies of all parameters from source

Definition at line 337 of file parameters.h.

References clear().

Referenced by Parameters().

338 {
339  this->clear();
340  *this += source;
341 
342  return *this;
343 }
virtual void clear()
Definition: parameters.h:321
void libMesh::Parameters::print ( std::ostream &  os = libMesh::out) const
inline

Prints the contents, by default to libMesh::out.

Definition at line 376 of file parameters.h.

References _values.

Referenced by n_parameters(), and libMesh::operator<<().

377 {
378  Parameters::const_iterator it = _values.begin();
379 
380  os << "Name\t Type\t Value\n"
381  << "---------------------\n";
382  while (it != _values.end())
383  {
384  os << " " << it->first
385 #ifdef LIBMESH_HAVE_RTTI
386  << "\t " << it->second->type()
387 #endif // LIBMESH_HAVE_RTTI
388  << "\t "; it->second->print(os);
389  os << '\n';
390 
391  ++it;
392  }
393 }
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:251
std::map< std::string, Value * > _values
Definition: parameters.h:278
void libMesh::Parameters::remove ( const std::string &  name)
inline

Removes the specified parameter from the list, if it exists.

Definition at line 480 of file parameters.h.

References _values, and libmesh_nullptr.

Referenced by libMesh::FrequencySystem::clear_all().

481 {
482  Parameters::iterator it = _values.find(name);
483 
484  if (it != _values.end())
485  {
486  delete it->second;
487  it->second = libmesh_nullptr;
488 
489  _values.erase(it);
490  }
491 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * >::iterator iterator
Definition: parameters.h:246
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:278
template<typename T >
T & libMesh::Parameters::set ( const std::string &  name)
inline
Returns
a writeable reference to the specified parameter. This method will create the parameter if it does not exist, so it can be used to define parameters which will later be accessed with the get() member.

Definition at line 469 of file parameters.h.

References _values, libMesh::Quality::name(), and set_attributes().

Referenced by libMesh::NewmarkSystem::clear(), libMesh::EquationSystems::EquationSystems(), libMesh::NewmarkSystem::NewmarkSystem(), libMesh::NonlinearImplicitSystem::NonlinearImplicitSystem(), libMesh::FrequencySystem::set_current_frequency(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), libMesh::FrequencySystem::set_frequencies_by_steps(), and libMesh::NewmarkSystem::set_newmark_parameters().

470 {
471  if (!this->have_parameter<T>(name))
472  _values[name] = new Parameter<T>;
473 
474  set_attributes(name, false);
475 
476  return cast_ptr<Parameter<T> *>(_values[name])->set();
477 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * > _values
Definition: parameters.h:278
virtual void set_attributes(const std::string &, bool)
Definition: parameters.h:133
virtual void libMesh::Parameters::set_attributes ( const std::string &  ,
bool   
)
inlinevirtual

Overridable function to set any extended attributes for classes inheriting from this class.

Definition at line 133 of file parameters.h.

Referenced by insert(), and set().

133 {}

Member Data Documentation

std::map<std::string, Value *> libMesh::Parameters::_values
protected

Data structure to map names with values.

Definition at line 278 of file parameters.h.

Referenced by begin(), clear(), end(), get(), have_parameter(), insert(), n_parameters(), operator+=(), print(), remove(), and set().


The documentation for this class was generated from the following file: