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...
 
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
 
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 &def) 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
 
iterator end ()
 Returns an iterator one past the last parameter of the block. More...
 
const_iterator end () const
 
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...
 
BlockcreateBlock (const std::string &key)
 Adding a new block within the parameter block. More...
 
std::string getString () const
 Returns Config-internal string to use for communication. More...
 

Constructor & Destructor Documentation

◆ Block() [1/2]

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

Standard constructor for the Block class.

Parameters
keyThe key of the block (default argument = "").

◆ Block() [2/2]

walberla::config::Config::Block::Block ( const Block b)
default

◆ ~Block()

walberla::config::Config::Block::~Block ( )
default

Default destructor of the Block class.

Member Function Documentation

◆ addParameter()

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.

◆ begin() [1/2]

Config::const_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.

◆ begin() [2/2]

const_iterator walberla::config::Config::Block::begin ( ) const
inline

◆ createBlock()

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.

◆ end() [1/2]

Config::const_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.

◆ end() [2/2]

const_iterator walberla::config::Config::Block::end ( ) const
inline

◆ getBlock()

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.

◆ getBlocks() [1/2]

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.

◆ getBlocks() [2/2]

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.

◆ getKey()

const std::string & walberla::config::Config::Block::getKey ( ) const
inline

Returns the key of the block.

Returns
The block key.

◆ getNumBlocks() [1/2]

Config::size_type walberla::config::Config::Block::getNumBlocks ( ) const
inline

Returns the number of contained parameter blocks.

Returns
The number of contained parameter blocks.

◆ getNumBlocks() [2/2]

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.

◆ getOneBlock()

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.

◆ getParameter() [1/5]

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

◆ getParameter() [2/5]

template<typename T >
Config::Parameter<T> walberla::config::Config::Block::getParameter ( const std::string &  key,
const T &  def 
) const
inline

◆ getParameter() [3/5]

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.

◆ getParameter() [4/5]

template<typename Type >
Config::Parameter<Type> walberla::config::Config::Block::getParameter ( std::string  key) const
inline

◆ getParameter() [5/5]

Config::Parameter< unsigned int > walberla::config::Config::Block::getParameter< unsigned int > ( std::string  key) const
inline

◆ getString()

std::string walberla::config::Config::Block::getString ( ) const
private

Returns Config-internal string to use for communication.

Returns
void

◆ getWritableBlocks() [1/2]

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.

◆ getWritableBlocks() [2/2]

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.

◆ isDefined()

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.

◆ listParameters()

void walberla::config::Config::Block::listParameters ( ) const

Output function for the contained parameters.

Returns
void

◆ operator=()

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.

◆ operator[]()

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.

◆ setOrAddParameter()

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.

◆ setParameter()

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

◆ Config

friend class Config
friend

Member Data Documentation

◆ blocks_

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

List of contained blocks.

◆ key_

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

Key of the block.

◆ params_

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

The parameters of the block.


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