$extrastylesheet
libMesh::Parameters Class Reference

#include <parameters.h>

List of all members.

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

Default constructor. Does nothing.

Definition at line 70 of file parameters.h.

{}

Copy constructor.

Definition at line 364 of file parameters.h.

{
  *this = p;
}
libMesh::Parameters::~Parameters ( ) [inline, virtual]

Destructor. Clears any allocated memory.

Definition at line 372 of file parameters.h.

References clear().

{
  this->clear ();
}

Member Function Documentation

Iterator pointing to the beginning of the set of parameters.

Definition at line 517 of file parameters.h.

References _values.

{
  return _values.begin();
}

Iterator pointing to the beginning of the set of parameters.

Definition at line 523 of file parameters.h.

References _values.

{
  return _values.begin();
}
void libMesh::Parameters::clear ( ) [inline, virtual]

Clears internal data structures & frees any allocated memory.

Definition at line 325 of file parameters.h.

References _values.

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

{                         // before its first use (for some compilers)
  while (!_values.empty())
    {
      Parameters::iterator it = _values.begin();

      delete it->second;
      it->second = NULL;

      _values.erase(it);
    }
}

Iterator pointing to the end of the set of parameters

Definition at line 529 of file parameters.h.

References _values.

{
  return _values.end();
}

Iterator pointing to the end of the set of parameters

Definition at line 535 of file parameters.h.

References _values.

{
  return _values.end();
}
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 434 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::CondensedEigenSystem::solve(), libMesh::EigenSystem::solve(), libMesh::LinearImplicitSystem::solve(), and libMesh::FrequencySystem::solve().

{
  if (!this->have_parameter<T>(name))
    {
      std::ostringstream oss;

      oss << "ERROR: no";
#ifdef LIBMESH_HAVE_RTTI
      oss << ' ' << demangle(typeid(T).name());
#endif
      oss << " parameter named \""
          << name << "\":\n"
          << *this;

      libmesh_error_msg(oss.str());
    }

  Parameters::const_iterator it = _values.find(name);

  libmesh_assert(it != _values.end());
  libmesh_assert(it->second);

  return cast_ptr<Parameter<T>*>(it->second)->get();
}
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 415 of file parameters.h.

References _values, and libMesh::cast_ptr().

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

{
  Parameters::const_iterator it = _values.find(name);

  if (it != _values.end())
#ifdef LIBMESH_HAVE_RTTI
    if (dynamic_cast<const Parameter<T>*>(it->second) != NULL)
#else // LIBMESH_HAVE_RTTI
      if (cast_ptr<const Parameter<T>*>(it->second) != NULL)
#endif // LIBMESH_HAVE_RTTI
        return true;

  return false;
}
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 461 of file parameters.h.

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

{
  if (!this->have_parameter<T>(name))
    _values[name] = new Parameter<T>;

  set_attributes(name, true);
}
unsigned int libMesh::Parameters::n_parameters ( ) const [inline]
Returns:
the total number of parameters.

Definition at line 143 of file parameters.h.

References _values.

{ 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) [inline, virtual]

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

Definition at line 350 of file parameters.h.

References _values.

{
  for (Parameters::const_iterator it = source._values.begin();
       it != source._values.end(); ++it)
    {
      if (_values.find(it->first) != _values.end())
        delete _values[it->first];
      _values[it->first] = it->second->clone();
    }

  return *this;
}
Parameters & libMesh::Parameters::operator= ( const Parameters source) [inline, virtual]

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

Definition at line 341 of file parameters.h.

References clear().

{
  this->clear();
  *this += source;

  return *this;
}
void libMesh::Parameters::print ( std::ostream &  os = libMesh::out) const [inline]

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

Definition at line 380 of file parameters.h.

References _values.

Referenced by libMesh::operator<<().

{
  Parameters::const_iterator it = _values.begin();

  os << "Name\t Type\t Value\n"
     << "---------------------\n";
  while (it != _values.end())
    {
      os << " "   << it->first
#ifdef LIBMESH_HAVE_RTTI
         << "\t " << it->second->type()
#endif // LIBMESH_HAVE_RTTI
         << "\t ";   it->second->print(os);
      os << '\n';

      ++it;
    }
}
void libMesh::Parameters::remove ( const std::string &  name) [inline]

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

Definition at line 483 of file parameters.h.

References _values.

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

{
  Parameters::iterator it = _values.find(name);

  if (it != _values.end())
    {
      delete it->second;
      it->second = NULL;

      _values.erase(it);
    }
}
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 472 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().

{
  if (!this->have_parameter<T>(name))
    _values[name] = new Parameter<T>;

  set_attributes(name, false);

  return cast_ptr<Parameter<T>*>(_values[name])->set();
}
virtual void libMesh::Parameters::set_attributes ( const std::string &  ,
bool   
) [inline, virtual]

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().

{}

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: