allpix::ConfigReader

Reader of configuration files. More…

#include <ConfigReader.hpp>

Public Functions

Name
ConfigReader(const ConfigReader & other)
Implement correct copy behaviour.
ConfigReader & operator=(const ConfigReader & other)
Implement correct copy behaviour.
ConfigReader(ConfigReader && ) =default
Use default move behaviour.
ConfigReader & operator=(ConfigReader && ) =default
Use default move behaviour.
ConfigReader()
Constructs a config reader without any attached streams.
ConfigReader(std::istream & stream, std::filesystem::path file_name ="")
Constructs a config reader with a single attached stream.
void add(std::istream & stream, std::filesystem::path file_name ="")
Adds a configuration stream to read.
void addConfiguration(Configuration config)
Directly add a configuration object to the reader.
void clear()
Removes all streams and all configurations.
bool hasConfiguration(std::string name) const
Check if a configuration exists.
unsigned int countConfigurations(std::string name) const
Count the number of configurations with a particular name.
Configuration getHeaderConfiguration() const
Get combined configuration of all empty sections (usually the header)
std::vector< Configuration > getConfigurations(std::string name) const
Get all configurations with a particular header.
std::vector< Configuration > getConfigurations() const
Get all configurations.
std::pair< std::string, std::string > parseKeyValue(std::string line)
Parse a line as key-value pair.

Detailed Description

class allpix::ConfigReader;

Reader of configuration files.

Read the internal configuration file format used in the framework. The format contains

  • A set of section header between [ and ] brackets
  • Key/value pairs linked to the last defined section (or the empty section if none has been defined yet)

Public Functions Documentation

function ConfigReader

ConfigReader(
    const ConfigReader & other
)

Implement correct copy behaviour.

function operator=

ConfigReader & operator=(
    const ConfigReader & other
)

Implement correct copy behaviour.

function ConfigReader

ConfigReader(
    ConfigReader && 
) =default

Use default move behaviour.

function operator=

ConfigReader & operator=(
    ConfigReader && 
) =default

Use default move behaviour.

function ConfigReader

ConfigReader()

Constructs a config reader without any attached streams.

function ConfigReader

explicit ConfigReader(
    std::istream & stream,
    std::filesystem::path file_name =""
)

Constructs a config reader with a single attached stream.

Parameters:

  • stream Stream to read configuration from
  • file_name Name of the file related to the stream or empty if not linked to a file

function add

void add(
    std::istream & stream,
    std::filesystem::path file_name =""
)

Adds a configuration stream to read.

Parameters:

  • stream Stream to read configuration from
  • file_name Name of the file related to the stream or empty if not linked to a file

Exceptions:

The configuration is immediately parsed and all of its configurations are available after the functions returns.

function addConfiguration

void addConfiguration(
    Configuration config
)

Directly add a configuration object to the reader.

Parameters:

function clear

void clear()

Removes all streams and all configurations.

function hasConfiguration

bool hasConfiguration(
    std::string name
) const

Check if a configuration exists.

Parameters:

  • name Name of a configuration header to search for

Return: True if at least a single configuration with this name exists, false otherwise

function countConfigurations

unsigned int countConfigurations(
    std::string name
) const

Count the number of configurations with a particular name.

Parameters:

  • name Name of a configuration header

Return: The number of configurations with the given name

function getHeaderConfiguration

Configuration getHeaderConfiguration() const

Get combined configuration of all empty sections (usually the header)

Return: Configuration object for the empty section

Note:

  • Typically this is only the section at the top of the file
  • An empty configuration is returned if no empty section is found

Warning: This will have the file path of the first header section

function getConfigurations

std::vector< Configuration > getConfigurations(
    std::string name
) const

Get all configurations with a particular header.

Parameters:

  • name Header name of the configurations to return

Return: List of configurations with the given name

function getConfigurations

std::vector< Configuration > getConfigurations() const

Get all configurations.

Return: List of all configurations

function parseKeyValue

static std::pair< std::string, std::string > parseKeyValue(
    std::string line
)

Parse a line as key-value pair.

Parameters:

  • line Line to interpret

Exceptions:

Return: Pair of the key and the value

The key / value pair is split according to the format specifications


Updated on 2024-12-13 at 08:31:36 +0000