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 247 of file parameters.h.

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

Parameter map iterator.

Definition at line 242 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 356 of file parameters.h.

357 {
358  *this = p;
359 }
libMesh::Parameters::~Parameters ( )
inlinevirtual

Destructor. Clears any allocated memory.

Definition at line 364 of file parameters.h.

References clear().

Referenced by Parameters().

365 {
366  this->clear ();
367 }
virtual void clear()
Definition: parameters.h:317

Member Function Documentation

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

Iterator pointing to the beginning of the set of parameters.

Definition at line 510 of file parameters.h.

References _values.

511 {
512  return _values.begin();
513 }
std::map< std::string, Value * > _values
Definition: parameters.h:274
Parameters::const_iterator libMesh::Parameters::begin ( ) const
inline

Iterator pointing to the beginning of the set of parameters.

Definition at line 516 of file parameters.h.

References _values.

517 {
518  return _values.begin();
519 }
std::map< std::string, Value * > _values
Definition: parameters.h:274
void libMesh::Parameters::clear ( )
inlinevirtual

Clears internal data structures & frees any allocated memory.

Definition at line 317 of file parameters.h.

References _values, and libmesh_nullptr.

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

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

Iterator pointing to the end of the set of parameters

Definition at line 522 of file parameters.h.

References _values.

523 {
524  return _values.end();
525 }
std::map< std::string, Value * > _values
Definition: parameters.h:274
Parameters::const_iterator libMesh::Parameters::end ( ) const
inline

Iterator pointing to the end of the set of parameters

Definition at line 528 of file parameters.h.

References _values.

529 {
530  return _values.end();
531 }
std::map< std::string, Value * > _values
Definition: parameters.h:274
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 426 of file parameters.h.

References _values, libMesh::demangle(), 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().

427 {
428  if (!this->have_parameter<T>(name))
429  {
430  std::ostringstream oss;
431 
432  oss << "ERROR: no";
433 #ifdef LIBMESH_HAVE_RTTI
434  oss << ' ' << demangle(typeid(T).name());
435 #endif
436  oss << " parameter named \""
437  << name << "\" found.\n\n"
438  << "Known parameters:\n"
439  << *this;
440 
441  libmesh_error_msg(oss.str());
442  }
443 
444  Parameters::const_iterator it = _values.find(name);
445 
446  libmesh_assert(it != _values.end());
447  libmesh_assert(it->second);
448 
449  return cast_ptr<Parameter<T> *>(it->second)->get();
450 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:247
std::string demangle(const char *name)
Definition: print_trace.C:250
std::map< std::string, Value * > _values
Definition: parameters.h:274
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 407 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().

408 {
410 
411  if (it != _values.end())
412 #ifdef LIBMESH_HAVE_RTTI
413  if (dynamic_cast<const Parameter<T> *>(it->second) != libmesh_nullptr)
414 #else // LIBMESH_HAVE_RTTI
415  if (cast_ptr<const Parameter<T> *>(it->second) != libmesh_nullptr)
416 #endif // LIBMESH_HAVE_RTTI
417  return true;
418 
419  return false;
420 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:247
Tnew cast_ptr(Told *oldvar)
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:274
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 454 of file parameters.h.

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

Referenced by Parameters().

455 {
456  if (!this->have_parameter<T>(name))
457  _values[name] = new Parameter<T>;
458 
459  set_attributes(name, true);
460 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * > _values
Definition: parameters.h:274
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:274
template<typename T >
unsigned int libMesh::Parameters::n_parameters ( ) const
inline
Returns
The number of parameters of the requested type.

Definition at line 494 of file parameters.h.

References _values, and libmesh_nullptr.

495 {
496  unsigned int cnt = 0;
497 
498  Parameters::const_iterator it = _values.begin();
499  const Parameters::const_iterator vals_end = _values.end();
500 
501  for (; it != vals_end; ++it)
502  if (dynamic_cast<Parameter<T> *>(it->second) != libmesh_nullptr)
503  cnt++;
504 
505  return cnt;
506 }
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:247
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:274
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 342 of file parameters.h.

References _values.

Referenced by Parameters().

343 {
344  for (Parameters::const_iterator it = source._values.begin();
345  it != source._values.end(); ++it)
346  {
347  if (_values.find(it->first) != _values.end())
348  delete _values[it->first];
349  _values[it->first] = it->second->clone();
350  }
351 
352  return *this;
353 }
std::map< std::string, Value * >::const_iterator const_iterator
Definition: parameters.h:247
std::map< std::string, Value * > _values
Definition: parameters.h:274
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 333 of file parameters.h.

References clear().

Referenced by Parameters().

334 {
335  this->clear();
336  *this += source;
337 
338  return *this;
339 }
virtual void clear()
Definition: parameters.h:317
void libMesh::Parameters::print ( std::ostream &  os = libMesh::out) const
inline

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

Definition at line 372 of file parameters.h.

References _values.

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

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

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

Definition at line 476 of file parameters.h.

References _values, and libmesh_nullptr.

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

477 {
478  Parameters::iterator it = _values.find(name);
479 
480  if (it != _values.end())
481  {
482  delete it->second;
483  it->second = libmesh_nullptr;
484 
485  _values.erase(it);
486  }
487 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * >::iterator iterator
Definition: parameters.h:242
const class libmesh_nullptr_t libmesh_nullptr
std::map< std::string, Value * > _values
Definition: parameters.h:274
template<typename T >
T & libMesh::Parameters::set ( const std::string &  name)
inline
Returns
A writable 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 465 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().

466 {
467  if (!this->have_parameter<T>(name))
468  _values[name] = new Parameter<T>;
469 
470  set_attributes(name, false);
471 
472  return cast_ptr<Parameter<T> *>(_values[name])->set();
473 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, Value * > _values
Definition: parameters.h:274
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 274 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: