OpenMPCD
Classes | Public Member Functions | List of all members
OpenMPCD::Configuration Class Reference

Represents the configuration of the simulation. More...

#include <Configuration.hpp>

Classes

class  List
 Represents a list, or an array, of values. More...
 
class  Setting
 Represents a setting in the configuration. More...
 

Public Member Functions

 Configuration ()
 The constructor. More...
 
 Configuration (const std::string &filename)
 The constructor. More...
 
 Configuration (const Configuration &rhs)
 The copy constructor. More...
 
bool has (const std::string &setting) const
 Returns whether a setting with the given name exists. More...
 
template<typename ValueType , unsigned int settingsCount>
void read (const std::pair< const char *, ValueType * >(&settingsAndValues)[settingsCount]) const
 Reads the specified settings from the given configuration file and stores them in the given location. More...
 
template<typename ValueType >
void read (const std::string &setting, ValueType *const value) const
 Reads the specified setting from the given configuration file and stores them in the given location. More...
 
template<typename ValueType >
ValueType read (const std::string &setting) const
 Returns the specified setting from the given configuration file. More...
 
const Setting getSetting (const std::string &name) const
 Returns the setting object with the given name. More...
 
const List getList (const std::string &name) const
 Returns the list with the given name. More...
 
template<typename ValueType >
void assertValue (const std::string &setting, const ValueType &value) const
 Asserts that the given setting exists, and has the specified type and value. More...
 
template<int N>
void assertValue (const std::string &setting, const char(&value)[N]) const
 Asserts that the given setting exists, and has the specified type and value. More...
 
template<typename ValueType >
void set (const std::string &setting, const ValueType value)
 Sets a setting's value. More...
 
void createGroup (const std::string &name)
 Creates a settings group. More...
 
void createList (const std::string &name)
 Creates a settings list. More...
 
void writeToFile (const std::string &path) const
 Writes the configuration to the given path. More...
 
const Configurationoperator= (const Configuration &rhs)
 The assignment operator. More...
 
template<>
void set (const std::string &setting, const unsigned int value)
 Sets a setting's value. More...
 

Detailed Description

Represents the configuration of the simulation.

Definition at line 28 of file Configuration.hpp.

Constructor & Destructor Documentation

◆ Configuration() [1/3]

OpenMPCD::Configuration::Configuration ( )
inline

The constructor.

Definition at line 479 of file Configuration.hpp.

◆ Configuration() [2/3]

OpenMPCD::Configuration::Configuration ( const std::string &  filename)
inline

The constructor.

Exceptions
OpenMPCD::IOExceptionThrows if the configuration file could not be read.
OpenMPCD::MalformedFileExceptionThrows if the configuration file is malformed.
Parameters
[in]filenameThe filename for the configuration file.

Definition at line 15 of file ImplementationDetails/Configuration/Configuration.hpp.

◆ Configuration() [3/3]

OpenMPCD::Configuration::Configuration ( const Configuration rhs)
inline

The copy constructor.

Parameters
[in]rhsThe instance to copy.

Definition at line 499 of file Configuration.hpp.

Member Function Documentation

◆ assertValue() [1/2]

template<int N>
void OpenMPCD::Configuration::assertValue ( const std::string &  setting,
const char(&)  value[N] 
) const
inline

Asserts that the given setting exists, and has the specified type and value.

Exceptions
std::runtime_errorThrows if the assertion fails.
Template Parameters
ValueTypeThe type of the settings value.
Parameters
[in]settingThe name of the setting to read.
[in]valueThe value that the setting should have.

Definition at line 639 of file Configuration.hpp.

◆ assertValue() [2/2]

template<typename ValueType >
void OpenMPCD::Configuration::assertValue ( const std::string &  setting,
const ValueType &  value 
) const
inline

Asserts that the given setting exists, and has the specified type and value.

Exceptions
std::runtime_errorThrows if the assertion fails.
Template Parameters
ValueTypeThe type of the settings value.
Parameters
[in]settingThe name of the setting to read.
[in]valueThe value that the setting should have.

Definition at line 617 of file Configuration.hpp.

◆ createGroup()

void OpenMPCD::Configuration::createGroup ( const std::string &  name)
inline

Creates a settings group.

Parent groups are created as necessary.

Parameters
[in]nameThe name of the group.
Exceptions
ExceptionThrows if the name is already in use.

Definition at line 719 of file Configuration.hpp.

◆ createList()

void OpenMPCD::Configuration::createList ( const std::string &  name)
inline

Creates a settings list.

Parent groups are created as necessary.

Parameters
[in]nameThe name of the list.
Exceptions
ExceptionThrows if the name is already in use.

Definition at line 730 of file Configuration.hpp.

◆ getList()

const List OpenMPCD::Configuration::getList ( const std::string &  name) const
inline

Returns the list with the given name.

Parameters
[in]nameThe list name.
Exceptions
InvalidConfigurationExceptionThrows if the given name does not exist or is not a list.

Definition at line 596 of file Configuration.hpp.

◆ getSetting()

const Setting OpenMPCD::Configuration::getSetting ( const std::string &  name) const
inline

Returns the setting object with the given name.

Exceptions
OpenMPCD::InvalidConfigurationExceptionThrows if the given name does not exist.
Parameters
[in]nameThe setting name.

Definition at line 579 of file Configuration.hpp.

◆ has()

bool OpenMPCD::Configuration::has ( const std::string &  setting) const
inline

Returns whether a setting with the given name exists.

Parameters
[in]settingThe setting name.

Definition at line 509 of file Configuration.hpp.

◆ operator=()

const Configuration& OpenMPCD::Configuration::operator= ( const Configuration rhs)
inline

The assignment operator.

Parameters
[in]rhsThe instance to copy.
Returns
Returns a reference to this instance.

Definition at line 752 of file Configuration.hpp.

◆ read() [1/3]

template<typename ValueType , unsigned int settingsCount>
void OpenMPCD::Configuration::read ( const std::pair< const char *, ValueType * >(&)  settingsAndValues[settingsCount]) const
inline

Reads the specified settings from the given configuration file and stores them in the given location.

Exceptions
std::runtime_errorThrows if any of the settings could not be read into the specified type.
std::runtime_errorIf OPENMPCD_DEBUG is defined, throws if any of given pointers is NULL.
Template Parameters
ValueTypeThe types of the settings values.
settingsCountThe number of settings to read.
Parameters
[in,out]settingsAndValuesThe names of the settings to read, and the locations to store their values into.

Definition at line 523 of file Configuration.hpp.

◆ read() [2/3]

template<typename ValueType >
ValueType OpenMPCD::Configuration::read ( const std::string &  setting) const
inline

Returns the specified setting from the given configuration file.

Exceptions
std::runtime_errorThrows if the settings could not be read into the specified type.
Template Parameters
ValueTypeThe type of the settings value.
Parameters
[in]settingThe name of the setting to read.

Definition at line 564 of file Configuration.hpp.

◆ read() [3/3]

template<typename ValueType >
void OpenMPCD::Configuration::read ( const std::string &  setting,
ValueType *const  value 
) const
inline

Reads the specified setting from the given configuration file and stores them in the given location.

Exceptions
std::runtime_errorThrows if the settings could not be read into the specified type.
std::runtime_errorIf OPENMPCD_DEBUG is defined, throws if the given pointer is NULL.
Template Parameters
ValueTypeThe type of the settings value.
Parameters
[in]settingThe name of the setting to read.
[out]valueThe location to read the setting value into.

Definition at line 538 of file Configuration.hpp.

◆ set() [1/2]

template<>
void OpenMPCD::Configuration::set ( const std::string &  setting,
const unsigned int  value 
)
inline

Sets a setting's value.

Exceptions
OpenMPCD::InvalidArgumentExceptionThrows if the setting already exists, but is of the wrong type.
Parameters
[in]settingThe name of the setting to set.
[in]valueThe value to set the setting to.

Definition at line 839 of file Configuration.hpp.

◆ set() [2/2]

template<typename ValueType >
void OpenMPCD::Configuration::set ( const std::string &  setting,
const ValueType  value 
)
inline

Sets a setting's value.

Exceptions
InvalidArgumentExceptionThrows if the setting already exists, but is of the wrong type.
Template Parameters
ValueTypeThe type of the setting's value.
Parameters
[in]settingThe name of the setting to set.
[in]valueThe value to set the setting to.

Definition at line 661 of file Configuration.hpp.

◆ writeToFile()

void OpenMPCD::Configuration::writeToFile ( const std::string &  path) const
inline

Writes the configuration to the given path.

Parameters
[in]pathThe path to write to.

Definition at line 739 of file Configuration.hpp.


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