walberla::config::Config::Block Class Reference

Detailed Description

Parameter block.

Author
Klaus Iglberger

A parameter block contains all parameters of one section of the input parameter file. A single parameter block can again contain other parameter blocks.

#include <Config.h>

Public Member Functions

 Block (const std::string &key="")
 Standard constructor for the Block class. More...
 
 Block (const Block &b)=default
 
 ~Block ()
 Default destructor of the Block class. More...
 
BlockcreateBlock (const std::string &key)
 Adding a new block within the parameter block. More...
 
template<typename Type >
Config::Parameter< Type > getParameter (std::string key) const
 
template<typename T >
Config::Parameter< T > getParameter (const std::string &key, const T &def) const
 
template<>
Config::Parameter< bool > getParameter (std::string key) const
 
template<>
Config::Parameter< unsigned int > getParameter (std::string key) const
 
Operators
Blockoperator= (const Block &b)
 The copy assignment operator for the Block class. More...
 
std::string & operator[] (std::string key)
 Returns a reference to the value of the specified key. More...
 
Get functions
const std::string & getKey () const
 Returns the key of the block. More...
 
bool isDefined (std::string key) const
 Checks if a parameter was defined in the parameter file. More...
 
template<typename T >
Parameter< T > getParameter (std::string key) const
 Returns an extracted parameter. More...
 
template<typename T >
Parameter< T > getParameter (const std::string &key, const T &defaultValue) const
 Returns an extracted parameter. More...
 
bool setParameter (const std::string &key, const std::string &value)
 Sets a given parameter to a given value. More...
 
void setOrAddParameter (const std::string &key, const std::string &value)
 Sets a given parameter to a given value (adds the parameter if it does not yet exist). More...
 
iterator begin ()
 Returns an iterator to the first parameter of the block. More...
 
const_iterator begin () const
 Returns an iterator to the first parameter of the block. More...
 
iterator end ()
 Returns an iterator one past the last parameter of the block. More...
 
const_iterator end () const
 Returns an iterator one past the last parameter of the block. More...
 
size_type getNumBlocks () const
 Returns the number of contained parameter blocks. More...
 
size_type getNumBlocks (const std::string &key) const
 Returns the number of contained parameter blocks corresponding to given key. More...
 
BlockHandle getBlock (const std::string &key) const
 Returns one or none block that matches with key. More...
 
BlockHandle getOneBlock (const std::string &key) const
 Returns exactly one block that matches with key. More...
 
void getBlocks (const std::string &key, Blocks &blocks, size_t min=0, size_t max=std::numeric_limits< size_t >::max()) const
 Adds to the given blocks all extracted blocks with key key. More...
 
void getBlocks (Blocks &blocks) const
 Adds to the given blocks all blocks contained in this block. More...
 
void getWritableBlocks (std::vector< Block * > &blocks)
 Adds to the given blocks all blocks contained in this block. More...
 
void getWritableBlocks (const std::string &key, std::vector< Block * > &blocks, size_t min=0, size_t max=std::numeric_limits< size_t >::max())
 Adds to the given blocks all extracted blocks with key key. More...
 

Private Attributes

Member variables
Key key_
 Key of the block. More...
 
List blocks_
 List of contained blocks. More...
 
Map params_
 The parameters of the block. More...
 

Friends

class Config
 

Utility functions

bool addParameter (const std::string &key, const std::string &value)
 Adding a parameter to a parameter block. More...
 
void listParameters () const
 Output function for the contained parameters. More...
 
std::string getString () const
 Returns Config-internal string to use for communication. More...
 

Constructor & Destructor Documentation

walberla::config::Config::Block::Block ( const std::string &  key = "")

Standard constructor for the Block class.

Parameters
keyThe key of the block (default argument = "").
walberla::config::Config::Block::Block ( const Block b)
default
walberla::config::Config::Block::~Block ( )
default

Default destructor of the Block class.

Member Function Documentation

bool walberla::config::Config::Block::addParameter ( const std::string &  key,
const std::string &  value 
)

Adding a parameter to a parameter block.

Parameters
keyThe key of the new parameter.
valueThe value of the new parameter.
Returns
true if a new parameter was added, false if duplicate key is present.
Config::iterator walberla::config::Config::Block::begin ( )
inline

Returns an iterator to the first parameter of the block.

Returns
Iterator to the first parameter of the block.
Config::const_iterator walberla::config::Config::Block::begin ( ) const
inline

Returns an iterator to the first parameter of the block.

Returns
Iterator to the first parameter of the block.
Config::Block & walberla::config::Config::Block::createBlock ( const std::string &  key)

Adding a new block within the parameter block.

Parameters
keyThe key of the new block.
Returns
Reference to the new block.
Config::iterator walberla::config::Config::Block::end ( )
inline

Returns an iterator one past the last parameter of the block.

Returns
Iterator one past the last parameter of the block.
Config::const_iterator walberla::config::Config::Block::end ( ) const
inline

Returns an iterator one past the last parameter of the block.

Returns
Iterator one past the last parameter of the block.
Config::BlockHandle walberla::config::Config::Block::getBlock ( const std::string &  key) const

Returns one or none block that matches with key.

Parameters
keyThe key of the extracted block.
Returns
One or none block that matches with key.
void walberla::config::Config::Block::getBlocks ( const std::string &  key,
Blocks blocks,
size_t  min = 0,
size_t  max = std::numeric_limits< size_t >::max() 
) const

Adds to the given blocks all extracted blocks with key key.

Parameters
keyThe key of the extracted blocks.
[out]blocksReference to the vector of blocks
minminimum number of blocks the caller expects
maxmaximum number of blocks the caller can handle
Returns
void.
void walberla::config::Config::Block::getBlocks ( Blocks blocks) const

Adds to the given blocks all blocks contained in this block.

Parameters
[out]blocksReference to the vector of blocks
Returns
void.
const std::string & walberla::config::Config::Block::getKey ( ) const
inline

Returns the key of the block.

Returns
The block key.
Config::size_type walberla::config::Config::Block::getNumBlocks ( ) const
inline

Returns the number of contained parameter blocks.

Returns
The number of contained parameter blocks.
Config::size_type walberla::config::Config::Block::getNumBlocks ( const std::string &  key) const

Returns the number of contained parameter blocks corresponding to given key.

Parameters
keyThe key of the blocks to count.
Returns
The number of contained parameter blocks corresponding to given key.
Config::BlockHandle walberla::config::Config::Block::getOneBlock ( const std::string &  key) const

Returns exactly one block that matches with key.

Parameters
keyThe key of the extracted block.
Returns
One block that matches with key.
template<typename T >
Config::Parameter< unsigned int > walberla::config::Config::Block::getParameter< unsigned int > ( std::string  key) const
inline

Returns an extracted parameter.

Returns an extracted unsigned integer parameter.

Returns an extracted bool parameter.

Returns an extracted string parameter.

Parameters
keyThe key of the parameter.
Returns
The extracted parameter.
Parameters
keyThe key of the string parameter.
Returns
The extracted string parameter.
Parameters
keyThe key of the bool parameter.
Returns
The extracted bool parameter.
Parameters
keyThe key of the unsigned integer parameter.
Returns
The extracted unsigned integer parameter.
template<typename T >
Config::Parameter< T > walberla::config::Config::Block::getParameter ( const std::string &  key,
const T &  def 
) const
inline

Returns an extracted parameter.

Parameters
keyThe key of the extracted parameter.
defThe default value, if the key does not exist
Returns
The extracted parameter if key is defined, otherwise default value
template<typename Type >
Config::Parameter<Type> walberla::config::Config::Block::getParameter ( std::string  key) const
inline
template<>
Config::Parameter<bool> walberla::config::Config::Block::getParameter ( std::string  key) const
inline
template<typename T >
Config::Parameter<T> walberla::config::Config::Block::getParameter ( const std::string &  key,
const T &  def 
) const
inline
template<>
Config::Parameter<unsigned int> walberla::config::Config::Block::getParameter ( std::string  key) const
inline
std::string walberla::config::Config::Block::getString ( ) const
private

Returns Config-internal string to use for communication.

Returns
void
void walberla::config::Config::Block::getWritableBlocks ( std::vector< Block * > &  blocks)

Adds to the given blocks all blocks contained in this block.

Parameters
[out]blocksReference to the vector of blocks
Returns
void.
void walberla::config::Config::Block::getWritableBlocks ( const std::string &  key,
std::vector< Block * > &  blocks,
size_t  min = 0,
size_t  max = std::numeric_limits< size_t >::max() 
)

Adds to the given blocks all extracted blocks with key key.

Parameters
keyThe key of the extracted blocks.
[out]blocksReference to the vector of blocks
minminimum number of blocks the caller expects
maxmaximum number of blocks the caller can handle
Returns
void.
bool walberla::config::Config::Block::isDefined ( std::string  key) const
inline

Checks if a parameter was defined in the parameter file.

Returns
true if the parameter was defined, false if the parameter wasn't defined.
void walberla::config::Config::Block::listParameters ( ) const

Output function for the contained parameters.

Returns
void
Config::Block & walberla::config::Config::Block::operator= ( const Block b)

The copy assignment operator for the Block class.

Parameters
bThe Block object to be copied.
Returns
Reference to the Config object.
std::string & walberla::config::Config::Block::operator[] ( std::string  key)
inline

Returns a reference to the value of the specified key.

Parameters
keyThe key of the parameter.
Returns
Reference to the value of the specified key.

If the key has not been defined before, a new parameter is added. The return value is a reference to the value of the (new) key.

void walberla::config::Config::Block::setOrAddParameter ( const std::string &  key,
const std::string &  value 
)
inline

Sets a given parameter to a given value (adds the parameter if it does not yet exist).

Parameters
keyThe key of the parameter.
valueThe value of the parameter.
bool walberla::config::Config::Block::setParameter ( const std::string &  key,
const std::string &  value 
)
inline

Sets a given parameter to a given value.

Parameters
keyThe key of the parameter.
valueThe value of the parameter.
Returns
True for success, False for failure.

Friends And Related Function Documentation

friend class Config
friend

Member Data Documentation

List walberla::config::Config::Block::blocks_
private

List of contained blocks.

Key walberla::config::Config::Block::key_
private

Key of the block.

Map walberla::config::Config::Block::params_
private

The parameters of the block.


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