Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
ConfigFileReader Class Reference

Simple INI-style configuration file reader. More...

#include <mitkConfigFileReader.h>

Collaboration diagram for ConfigFileReader:

Public Member Functions

 ConfigFileReader (std::string const &configFile)
 Construct a ConfigFileReader and immediately parse the given file. More...
 
void ReadFile (std::string const &filePath)
 Read and parse a configuration file from disk. More...
 
void ReadStream (std::istream &stream)
 Parse configuration data from an input stream. More...
 
std::string Value (std::string const &section, std::string const &entry) const
 Retrieve a string value from the configuration. More...
 
std::string Value (const std::string &section, const std::string &entry, const std::string &standard)
 Retrieve a string value, returning a default if the entry does not exist. More...
 
int IntValue (const std::string &section, const std::string &entry) const
 Retrieve an integer value from the configuration. More...
 
int IntValue (const std::string &section, const std::string &entry, int standard)
 Retrieve an integer value, returning a default if the entry does not exist. More...
 
std::vector< std::string > Vector (std::string const &section, unsigned int index) const
 Retrieve a list block's content lines by section name and index. More...
 
unsigned int ListSize (std::string const &section) const
 Get the number of list blocks with the given section name. More...
 
unsigned int ListSize (std::string const &section, unsigned int standard)
 Get the number of list blocks, returning a default if none exist. More...
 

Protected Types

typedef std::map< std::string, std::string > ContentType
 
typedef std::map< std::string, std::vector< std::string > > ListContentType
 

Protected Member Functions

std::string Trim (std::string const &source, char const *delim=" \t\r\n")
 
std::string RemoveComment (std::string const &source, char const *delim="#;")
 
std::string ListIndex (std::string const &section, unsigned int index) const
 
std::string ContentIndex (std::string const &section, std::string const &entry) const
 
std::string ListSizeIndex (std::string const &section) const
 

Protected Attributes

ContentType m_ConfigContent
 
ListContentType m_ListContent
 
std::map< std::string, unsigned int > m_ListSize
 

Detailed Description

Simple INI-style configuration file reader.

Reads configuration files that contain sections enclosed in square brackets, key=value pairs within those sections, and list blocks enclosed in curly braces. Comments beginning with '#' are stripped. Lookups are case-insensitive.

Example file format:

[SectionName]
key = value
{ListName}
item1
item2
See also
ConfigurationHolder

Definition at line 42 of file mitkConfigFileReader.h.

Member Typedef Documentation

◆ ContentType

typedef std::map<std::string, std::string> ConfigFileReader::ContentType
protected

Definition at line 47 of file mitkConfigFileReader.h.

◆ ListContentType

typedef std::map<std::string, std::vector<std::string> > ConfigFileReader::ListContentType
protected

Definition at line 48 of file mitkConfigFileReader.h.

Constructor & Destructor Documentation

◆ ConfigFileReader()

ConfigFileReader::ConfigFileReader ( std::string const &  configFile)
inline

Construct a ConfigFileReader and immediately parse the given file.

Parameters
[in]configFilePath to the configuration file to read.

Definition at line 108 of file mitkConfigFileReader.h.

References ReadFile().

Member Function Documentation

◆ ContentIndex()

std::string ConfigFileReader::ContentIndex ( std::string const &  section,
std::string const &  entry 
) const
inlineprotected

Definition at line 86 of file mitkConfigFileReader.h.

Referenced by IntValue(), ReadStream(), and Value().

◆ IntValue() [1/2]

int ConfigFileReader::IntValue ( const std::string &  section,
const std::string &  entry 
) const
inline

Retrieve an integer value from the configuration.

Parameters
[in]sectionThe section name.
[in]entryThe key name within the section.
Returns
The integer value parsed from the entry.
Exceptions
std::stringIf the entry does not exist.

Definition at line 219 of file mitkConfigFileReader.h.

References Value().

Referenced by IntValue().

◆ IntValue() [2/2]

int ConfigFileReader::IntValue ( const std::string &  section,
const std::string &  entry,
int  standard 
)
inline

Retrieve an integer value, returning a default if the entry does not exist.

Parameters
[in]sectionThe section name.
[in]entryThe key name within the section.
[in]standardDefault value to return and store if the entry is missing.
Returns
The integer value, or the default.

Definition at line 235 of file mitkConfigFileReader.h.

References ContentIndex(), IntValue(), and m_ConfigContent.

◆ ListIndex()

std::string ConfigFileReader::ListIndex ( std::string const &  section,
unsigned int  index 
) const
inlineprotected

Definition at line 77 of file mitkConfigFileReader.h.

Referenced by ReadStream(), and Vector().

◆ ListSize() [1/2]

unsigned int ConfigFileReader::ListSize ( std::string const &  section) const
inline

Get the number of list blocks with the given section name.

Parameters
[in]sectionThe list section name.
Returns
The number of list blocks.
Exceptions
std::stringIf no list blocks with the given section exist.

Definition at line 273 of file mitkConfigFileReader.h.

References ListSizeIndex(), and m_ListSize.

Referenced by ListSize(), and ReadStream().

◆ ListSize() [2/2]

unsigned int ConfigFileReader::ListSize ( std::string const &  section,
unsigned int  standard 
)
inline

Get the number of list blocks, returning a default if none exist.

Parameters
[in]sectionThe list section name.
[in]standardDefault count to return and store if no blocks exist.
Returns
The number of list blocks, or the default.

Definition at line 289 of file mitkConfigFileReader.h.

References ListSize(), ListSizeIndex(), and m_ListSize.

◆ ListSizeIndex()

std::string ConfigFileReader::ListSizeIndex ( std::string const &  section) const
inlineprotected

Definition at line 94 of file mitkConfigFileReader.h.

Referenced by ListSize(), and ReadStream().

◆ ReadFile()

void ConfigFileReader::ReadFile ( std::string const &  filePath)
inline

Read and parse a configuration file from disk.

Parameters
[in]filePathPath to the configuration file.

Definition at line 118 of file mitkConfigFileReader.h.

References ReadStream().

Referenced by ConfigFileReader().

◆ ReadStream()

void ConfigFileReader::ReadStream ( std::istream &  stream)
inline

Parse configuration data from an input stream.

Processes sections ([...]), list blocks ({...}), and key=value pairs. Comments starting with '#' are removed.

Parameters
[in]streamThe input stream to read from.

Definition at line 133 of file mitkConfigFileReader.h.

References ContentIndex(), ListIndex(), ListSize(), ListSizeIndex(), m_ConfigContent, m_ListContent, m_ListSize, RemoveComment(), and Trim().

Referenced by ReadFile().

◆ RemoveComment()

std::string ConfigFileReader::RemoveComment ( std::string const &  source,
char const *  delim = "#;" 
)
inlineprotected

Definition at line 68 of file mitkConfigFileReader.h.

References Trim().

Referenced by ReadStream().

◆ Trim()

std::string ConfigFileReader::Trim ( std::string const &  source,
char const *  delim = " \t\r\n" 
)
inlineprotected

Definition at line 54 of file mitkConfigFileReader.h.

Referenced by ReadStream(), and RemoveComment().

◆ Value() [1/2]

std::string ConfigFileReader::Value ( const std::string &  section,
const std::string &  entry,
const std::string &  standard 
)
inline

Retrieve a string value, returning a default if the entry does not exist.

Parameters
[in]sectionThe section name.
[in]entryThe key name within the section.
[in]standardDefault value to return and store if the entry is missing.
Returns
The value associated with section::entry, or the default.

Definition at line 199 of file mitkConfigFileReader.h.

References ContentIndex(), m_ConfigContent, and Value().

◆ Value() [2/2]

std::string ConfigFileReader::Value ( std::string const &  section,
std::string const &  entry 
) const
inline

Retrieve a string value from the configuration.

Parameters
[in]sectionThe section name.
[in]entryThe key name within the section.
Returns
The value associated with section::entry.
Exceptions
std::stringIf the entry does not exist.

Definition at line 182 of file mitkConfigFileReader.h.

References ContentIndex(), and m_ConfigContent.

Referenced by IntValue(), and Value().

◆ Vector()

std::vector<std::string> ConfigFileReader::Vector ( std::string const &  section,
unsigned int  index 
) const
inline

Retrieve a list block's content lines by section name and index.

Parameters
[in]sectionThe list section name.
[in]indexZero-based index of the list block (multiple blocks with the same name are indexed sequentially).
Returns
A vector of strings, one per line in the list block.
Exceptions
std::stringIf the entry does not exist.

Definition at line 257 of file mitkConfigFileReader.h.

References ListIndex(), and m_ListContent.

Member Data Documentation

◆ m_ConfigContent

ContentType ConfigFileReader::m_ConfigContent
protected

Definition at line 50 of file mitkConfigFileReader.h.

Referenced by IntValue(), ReadStream(), and Value().

◆ m_ListContent

ListContentType ConfigFileReader::m_ListContent
protected

Definition at line 51 of file mitkConfigFileReader.h.

Referenced by ReadStream(), and Vector().

◆ m_ListSize

std::map<std::string, unsigned int > ConfigFileReader::m_ListSize
protected

Definition at line 52 of file mitkConfigFileReader.h.

Referenced by ListSize(), and ReadStream().


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