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

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

Parameter map iterator.

Definition at line 245 of file parameters.h.

Constructor & Destructor Documentation

libMesh::Parameters::Parameters ( )
inline

Default constructor. Does nothing.

Definition at line 69 of file parameters.h.

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

Copy constructor.

Definition at line 362 of file parameters.h.

363 {
364  *this = p;
365 }
libMesh::Parameters::~Parameters ( )
inlinevirtual

Destructor. Clears any allocated memory.

Definition at line 370 of file parameters.h.

References clear().

371 {
372  this->clear ();
373 }

Member Function Documentation

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

Iterator pointing to the beginning of the set of parameters.

Definition at line 513 of file parameters.h.

References _values.

514 {
515  return _values.begin();
516 }
Parameters::const_iterator libMesh::Parameters::begin ( ) const
inline

Iterator pointing to the beginning of the set of parameters.

Definition at line 519 of file parameters.h.

References _values.

520 {
521  return _values.begin();
522 }
void libMesh::Parameters::clear ( )
inlinevirtual

Clears internal data structures & frees any allocated memory.

Definition at line 324 of file parameters.h.

References _values.

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

325 { // before its first use (for some compilers)
326  while (!_values.empty())
327  {
328  Parameters::iterator it = _values.begin();
329 
330  delete it->second;
331  it->second = NULL;
332 
333  _values.erase(it);
334  }
335 }
Parameters::iterator libMesh::Parameters::end ( )
inline

Iterator pointing to the end of the set of parameters

Definition at line 525 of file parameters.h.

References _values.

526 {
527  return _values.end();
528 }
Parameters::const_iterator libMesh::Parameters::end ( ) const
inline

Iterator pointing to the end of the set of parameters

Definition at line 531 of file parameters.h.

References _values.

532 {
533  return _values.end();
534 }
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 432 of file parameters.h.

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

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

433 {
434  if (!this->have_parameter<T>(name))
435  {
436  libMesh::err << "ERROR: no"
437 #ifdef LIBMESH_HAVE_RTTI
438  << ' ' << demangle(typeid(T).name())
439 #endif // LIBMESH_HAVE_RTTI
440  << " parameter named \""
441  << name << "\":" << std::endl
442  << *this;
443 
444  libmesh_error();
445  }
446 
448 
449  libmesh_assert(it != _values.end());
450  libmesh_assert(it->second);
451 
452  return libmesh_cast_ptr<Parameter<T>*>(it->second)->get();
453 }
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 413 of file parameters.h.

References _values, and libMesh::libmesh_cast_ptr().

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

414 {
416 
417  if (it != _values.end())
418 #ifdef LIBMESH_HAVE_RTTI
419  if (dynamic_cast<const Parameter<T>*>(it->second) != NULL)
420 #else // LIBMESH_HAVE_RTTI
421  if (libmesh_cast_ptr<const Parameter<T>*>(it->second) != NULL)
422 #endif // LIBMESH_HAVE_RTTI
423  return true;
424 
425  return false;
426 }
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 457 of file parameters.h.

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

458 {
459  if (!this->have_parameter<T>(name))
460  _values[name] = new Parameter<T>;
461 
462  set_attributes(name, true);
463 }
unsigned int libMesh::Parameters::n_parameters ( ) const
inline
Returns
the total number of parameters.

Definition at line 142 of file parameters.h.

References _values.

142 { return _values.size(); }
template<typename T >
unsigned int libMesh::Parameters::n_parameters ( ) const
Returns
the number of parameters of the requested type.
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 348 of file parameters.h.

References _values.

349 {
350  for (Parameters::const_iterator it = source._values.begin();
351  it != source._values.end(); ++it)
352  {
353  if (_values.find(it->first) != _values.end())
354  delete _values[it->first];
355  _values[it->first] = it->second->clone();
356  }
357 
358  return *this;
359 }
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 340 of file parameters.h.

References clear().

341 {
342  this->clear();
343 
344  return (*this += source);
345 }
void libMesh::Parameters::print ( std::ostream &  os = libMesh::out) const
inline

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

Definition at line 378 of file parameters.h.

References _values.

Referenced by libMesh::operator<<().

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

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

Definition at line 479 of file parameters.h.

References _values.

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

480 {
481  Parameters::iterator it = _values.find(name);
482 
483  if (it != _values.end())
484  {
485  delete it->second;
486  it->second = NULL;
487 
488  _values.erase(it);
489  }
490 }
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 468 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().

469 {
470  if (!this->have_parameter<T>(name))
471  _values[name] = new Parameter<T>;
472 
473  set_attributes(name, false);
474 
475  return libmesh_cast_ptr<Parameter<T>*>(_values[name])->set();
476 }
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 132 of file parameters.h.

Referenced by insert(), and set().

132 {}

Member Data Documentation

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

Data structure to map names with values.

Definition at line 277 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:

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:28 UTC

Hosted By:
SourceForge.net Logo