30#ifndef __CLAW_CONFIGURATION_FILE_HPP__
31#define __CLAW_CONFIGURATION_FILE_HPP__
59 std::string
make_comment(
const std::string& value)
const;
61 const std::string& value)
const;
78 typedef std::multimap<std::string, std::string> section_content;
81 typedef std::map<std::string, section_content> file_content;
84 typedef section_content* section_content_ptr;
89 const file_content::key_type, file_content::const_iterator,
95 const section_content::key_type, section_content::const_iterator,
103 class const_field_iterator
107 typedef section_content::const_iterator wrapped_iterator_type;
110 typedef std::string value_type;
111 typedef const value_type& reference;
112 typedef const value_type* pointer;
113 typedef wrapped_iterator_type::difference_type difference_type;
115 typedef wrapped_iterator_type::iterator_category iterator_category;
118 const_field_iterator()
120 const_field_iterator(wrapped_iterator_type it)
124 bool operator==(
const const_field_iterator& that)
const
126 return m_iterator == that.m_iterator;
129 bool operator!=(
const const_field_iterator& that)
const
131 return m_iterator != that.m_iterator;
134 const_field_iterator& operator++()
140 const_field_iterator operator++(
int)
142 const_field_iterator tmp(*
this);
147 const_field_iterator& operator--()
153 const_field_iterator operator--(
int)
155 const_field_iterator tmp(*
this);
160 reference operator*()
const
162 return m_iterator->second;
165 pointer operator->()
const
167 return &m_iterator->second;
172 wrapped_iterator_type m_iterator;
181 bool open(std::istream& is,
183 void save(std::ostream& os,
186 const std::string&
operator()(
const std::string& section,
187 const std::string& field)
const;
189 const std::string&
operator()(
const std::string& field)
const;
191 bool has_field(
const std::string& section,
const std::string& field)
const;
192 bool has_field(
const std::string& field)
const;
194 void set_value(
const std::string& section,
const std::string& field,
195 const std::string& val);
196 void set_value(
const std::string& field,
const std::string& val);
198 void add_value(
const std::string& section,
const std::string& field,
199 const std::string& val);
200 void add_value(
const std::string& field,
const std::string& val);
205 const std::string& field)
const;
207 const std::string& field)
const;
223 std::string& line)
const;
224 bool process_line(
const std::string& line,
226 section_content_ptr& section);
229 std::string& line)
const;
232 std::string& str)
const;
234 void save_section_content(
const section_content& c, std::ostream& os,
239 section_content m_noname_section;
242 file_content m_sections;
245 static const std::string s_unknow_field_value;
This class is an iterator on the values set for a same field name.
const_section_iterator section_begin() const
Get an iterator on the field names of a section.
void add_value(const std::string §ion, const std::string &field, const std::string &val)
Add a value to a field.
const_file_iterator file_begin() const
Get an iterator on the first named section.
void set_value(const std::string §ion, const std::string &field, const std::string &val)
Set the value of a field.
void clear_section(const std::string §ion)
Remove a section and its fields.
const_field_iterator field_end(const std::string §ion, const std::string &field) const
Get an iterator past the last value set for a field.
void save(std::ostream &os, const syntax_description &syntax=syntax_description())
Write the configuration in a stream.
const_section_iterator section_end() const
Get an iterator past the last field name of a section.
claw::wrapped_iterator< constfile_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.
bool has_field(const std::string §ion, const std::string &field) const
Tell if a field exists.
claw::wrapped_iterator< constsection_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.
configuration_file()
Default constructor.
bool open(std::istream &is, const syntax_description &syntax=syntax_description())
Read the configuration from a stream.
const std::string & operator()(const std::string §ion, const std::string &field) const
Get the value of a field.
const_field_iterator field_begin(const std::string §ion, const std::string &field) const
Get an iterator on the first value set for a field.
const_file_iterator file_end() const
Get an iterator just past the last named section.
Fuction object to get the first element of a std::pair.
This class defines an iterator resulting of the appliance of a function to an effective iterator.
Some function object classes.
Some special kind of iterators. As an example: iterator on the keys of a map.
This is the main namespace.
This class tells us how to parse the input file.
std::string make_comment(const std::string &value) const
Create a comment from a string.
std::string make_assignment(const std::string &key, const std::string &value) const
Make an assignment of a value to a key.
std::string make_section_name(const std::string &name) const
Create a section name from a string.
std::pair< char, char > paired_symbol
Two symbols making a pair (like () or []).
paired_symbol section_name
Pair of symbols around a section name.
char comment
Symbol used to comment the rest of the line.
char assignment
Symbol used to assign a value to a field.
syntax_description()
Default constructor.