claw::configuration_file Class Reference

A class to get the content of a configuration file. More...

`#include <configuration_file.hpp>`

## Classes

class | const_field_iterator
| This class is an iterator on the values set for a same field name. More...
struct | syntax_description
| This class tells us how to parse the input file. More...

## Public Types

typedef claw::wrapped_iterator< const file_content::key_type, file_content::const_iterator, const_pair_first< file_content::value_type > >::iterator_type | const_file_iterator
| Iterator on the name of the sections.
typedef claw::wrapped_iterator< const section_content::key_type, section_content::const_iterator, const_pair_first< section_content::value_type > >::iterator_type | const_section_iterator
| Iterator on the fields of a section.

## Public Member Functions

| configuration_file ()
| Default constructor.
| configuration_file (std::istream &is, const syntax_description &syntax=syntax_description())
| Constructor. More...
bool | open (std::istream &is, const syntax_description &syntax=syntax_description())
| Read the configuration from a stream. More...
void | save (std::ostream &os, const syntax_description &syntax=syntax_description())
| Write the configuration in a stream. More...
const std::string & | operator() (const std::string &section, const std::string &field) const
| Get the value of a field. More...
const std::string & | operator() (const std::string &field) const
| Get the value of a field. More...
bool | has_field (const std::string &section, const std::string &field) const
| Tell if a field exists. More...
bool | has_field (const std::string &field) const
| Tell if a field exists. More...
void | set_value (const std::string &section, const std::string &field, const std::string &val)
| Set the value of a field. More...
void | set_value (const std::string &field, const std::string &val)
| Set the value of a field. More...
void | add_value (const std::string &section, const std::string &field, const std::string &val)
| Add a value to a field. More...
void | add_value (const std::string &field, const std::string &val)
| Set the value of a field. More...
void | clear_section (const std::string &section)
| Remove a section and its fields. More...
const_field_iterator | field_begin (const std::string &section, const std::string &field) const
| Get an iterator on the first value set for a field. More...
const_field_iterator | field_end (const std::string &section, const std::string &field) const
| Get an iterator past the last value set for a field. More...
const_field_iterator | field_begin (const std::string &field) const
| Get an iterator on the first value set for a field. More...
const_field_iterator | field_end (const std::string &field) const
| Get an iterator past the last value set for a field. More...
const_section_iterator | section_begin () const
| Get an iterator on the field names of a section. More...
const_section_iterator | section_end () const
| Get an iterator past the last field name of a section. More...
const_section_iterator | section_begin (const std::string &section) const
| Get an iterator on the field names of a section. More...
const_section_iterator | section_end (const std::string &section) const
| Get an iterator past the last field name of a section. More...
const_file_iterator | file_begin () const
| Get an iterator on the first named section.
const_file_iterator | file_end () const
| Get an iterator just past the last named section.

## Detailed Description

A class to get the content of a configuration file.

Author
  Julien Jorge.

Definition at line 46 of file configuration_file.hpp.

## Constructor & Destructor Documentation

## configuration_file()

claw::configuration_file::configuration_file | ( | std::istream & | is,
|  | const syntax_description & | syntax = `syntax_description()`
| ) |  |

Constructor.

Parameters

  is | The stream to read from.
  syntax | Description of the file's syntax.

Definition at line 101 of file configuration_file.cpp.

References open().

## Member Function Documentation

## add_value() [1/2]

void claw::configuration_file::add_value | ( | const std::string & | section,
|  | const std::string & | field,
|  | const std::string & | val
| ) |  |

Add a value to a field.

Parameters

  section | The name of the section containing the field.
  field | The name of the field to add.
  val | The value.

This method keeps all previous values for the given field.

Definition at line 267 of file configuration_file.cpp.

Referenced by set_value().

## add_value() [2/2]

void claw::configuration_file::add_value | ( | const std::string & | field,
|  | const std::string & | val
| ) |  |

Set the value of a field.

Parameters

  field | The name of the field to Set.
  val | The value.

This method keeps all previous values for the given field.

Definition at line 281 of file configuration_file.cpp.

## clear_section()

void claw::configuration_file::clear_section | ( | const std::string & | section | ) |

Remove a section and its fields.

Parameters

  section | The name of the section to remove.

Definition at line 291 of file configuration_file.cpp.

References field_begin().

## field_begin() [1/2]

claw::configuration_file::const_field_iterator claw::configuration_file::field_begin | ( | const std::string & | section,
|  | const std::string & | field
| ) |  | const

Get an iterator on the first value set for a field.

Parameters

  section | The name of the section in which is the field.
  field | The name of the field to get.

Definition at line 304 of file configuration_file.cpp.

References field_end().

Referenced by clear_section(), and has_field().

## field_begin() [2/2]

claw::configuration_file::const_field_iterator claw::configuration_file::field_begin | ( | const std::string & | field | ) | const

Get an iterator on the first value set for a field.

Parameters

  field | The name of the field to get.

Remarks
  The field is searched in the fields declared outside any section.

Definition at line 340 of file configuration_file.cpp.

## field_end() [1/2]

claw::configuration_file::const_field_iterator claw::configuration_file::field_end | ( | const std::string & | section,
|  | const std::string & | field
| ) |  | const

Get an iterator past the last value set for a field.

Parameters

  section | The name of the section in which is the field.
  field | The name of the field to get.

Definition at line 322 of file configuration_file.cpp.

Referenced by field_begin(), and has_field().

## field_end() [2/2]

claw::configuration_file::const_field_iterator claw::configuration_file::field_end | ( | const std::string & | field | ) | const

Get an iterator past the last value set for a field.

Parameters

  field | The name of the field to get.

Remarks
  The field is searched in the fields declared outside any section.

Definition at line 353 of file configuration_file.cpp.

## has_field() [1/2]

bool claw::configuration_file::has_field | ( | const std::string & | section,
|  | const std::string & | field
| ) |  | const

Tell if a field exists.

Parameters

  section | The name of the section containing the field.
  field | The name of the field to test.

Definition at line 203 of file configuration_file.cpp.

References field_begin(), and field_end().

Referenced by operator()().

## has_field() [2/2]

bool claw::configuration_file::has_field | ( | const std::string & | field | ) | const

Tell if a field exists.

Parameters

  field | The name of the field to test.

Remarks
  The field is searched outside any section.

Definition at line 215 of file configuration_file.cpp.

References field_begin(), field_end(), and set_value().

## open()

bool claw::configuration_file::open | ( | std::istream & | is,
|  | const syntax_description & | syntax = `syntax_description()`
| ) |  |

Read the configuration from a stream.

Parameters

  is | The stream to read from.
  syntax | Description of the file's syntax.

Definition at line 113 of file configuration_file.cpp.

References save().

Referenced by configuration_file().

## operator()() [1/2]

const std::string & claw::configuration_file::operator() | ( | const std::string & | section,
|  | const std::string & | field
| ) |  | const

Get the value of a field.

Parameters

  section | The name of the section in which is the field.
  field | The name of the field to get.

Definition at line 161 of file configuration_file.cpp.

## operator()() [2/2]

const std::string & claw::configuration_file::operator() | ( | const std::string & | field | ) | const

Get the value of a field.

Parameters

  field | The name of the field to get.

Remarks
  The field is searched in the fields declared outside any section.

Definition at line 186 of file configuration_file.cpp.

References has_field().

## save()

void claw::configuration_file::save | ( | std::ostream & | os,
|  | const syntax_description & | syntax = `syntax_description()`
| ) |  |

Write the configuration in a stream.

Parameters

  os | The stream to write in.
  syntax | Description of the file's syntax.

Definition at line 137 of file configuration_file.cpp.

References claw::configuration_file::syntax_description::make_section_name().

Referenced by open().

## section_begin() [1/2]

claw::configuration_file::const_section_iterator claw::configuration_file::section_begin | ( |  | ) | const

Get an iterator on the field names of a section.

Remarks
  The names are searched in the fields declared outside any section.

Definition at line 365 of file configuration_file.cpp.

## section_begin() [2/2]

claw::configuration_file::const_section_iterator claw::configuration_file::section_begin | ( | const std::string & | section | ) | const

Get an iterator on the field names of a section.

Parameters

  section | The name of the section in which the fields are searched.

Definition at line 388 of file configuration_file.cpp.

## section_end() [1/2]

claw::configuration_file::const_section_iterator claw::configuration_file::section_end | ( |  | ) | const

Get an iterator past the last field name of a section.

Remarks
  The names are searched in the fields declared outside any section.

Definition at line 377 of file configuration_file.cpp.

## section_end() [2/2]

claw::configuration_file::const_section_iterator claw::configuration_file::section_end | ( | const std::string & | section | ) | const

Get an iterator past the last field name of a section.

Parameters

  section | The name of the section in which the fields are searched.

Definition at line 404 of file configuration_file.cpp.

## set_value() [1/2]

void claw::configuration_file::set_value | ( | const std::string & | section,
|  | const std::string & | field,
|  | const std::string & | val
| ) |  |

Set the value of a field.

Parameters

  section | The name of the section containing the field.
  field | The name of the field to set.
  val | The value.

This method removes all previous values for the given field.

Definition at line 230 of file configuration_file.cpp.

References add_value().

Referenced by has_field().

## set_value() [2/2]

void claw::configuration_file::set_value | ( | const std::string & | field,
|  | const std::string & | val
| ) |  |

Set the value of a field.

Parameters

  field | The name of the field to Set.
  val | The value.

This method removes all previous values for the given field.

Remarks
  The value is inserted in the fields declared outside any section.

Definition at line 251 of file configuration_file.cpp.

References add_value().

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

- configuration_file.hpp
- code/configuration_file.cpp