87 explicit MapFile( std::istream & ) ;
93 static void check(
const Path & , string_view kind = {} ) ;
98 void add( string_view key , string_view
value ,
bool clear =
false ) ;
103 void writeItem( std::ostream & , string_view key )
const ;
106 static void writeItem( std::ostream & , string_view key , string_view
value ) ;
109 void editInto(
const Path & path ,
bool make_backup ,
110 bool allow_read_error ,
bool allow_write_error )
const ;
114 bool contains( string_view key )
const ;
117 Path
pathValue( string_view key )
const ;
121 Path
pathValue( string_view key ,
const Path & default_ )
const ;
124 unsigned int numericValue( string_view key ,
unsigned int default_ )
const ;
127 std::string
value( string_view key , string_view default_ = {} )
const ;
131 bool booleanValue( string_view key ,
bool default_ )
const ;
136 void remove( string_view key ) ;
142 void log(
const std::string & prefix = {} )
const ;
161 using List = std::list<std::string> ;
162 void readFrom(
const Path & , string_view ) ;
163 void readFrom( std::istream & ss ) ;
164 static std::string quote(
const std::string & ) ;
165 List read(
const Path & , string_view ,
bool )
const ;
166 void commentOut( List & )
const ;
167 void replace( List & )
const ;
168 bool expand_( std::string & )
const ;
169 std::string expandAll( string_view )
const ;
170 static void backup(
const Path & ) ;
171 static void save(
const Path & , List & ,
bool ) ;
172 std::string mandatoryValue( string_view )
const ;
173 bool ignore(
const std::string & )
const ;
174 static std::string ekind( string_view ) ;
175 static std::string epath(
const Path & ) ;
176 static Error readError(
const Path & , string_view ) ;
177 static Error writeError(
const Path & , string_view = {} ) ;
178 static Error missingValueError(
const Path & ,
const std::string & ,
const std::string & ) ;
179 StringMap::const_iterator find( string_view )
const ;
180 StringMap::iterator find( string_view ) ;
A general-purpose exception class derived from std::exception and containing an error message.
Exception(std::initializer_list< string_view >)
Constructor.
A class for reading, writing and editing key=value files, supporting variable expansion of percent-ke...
static void check(const Path &, string_view kind={})
Throws if the file is invalid.
void writeItem(std::ostream &, string_view key) const
Writes a single item from this map to the stream.
std::string value(string_view key, string_view default_={}) const
Returns a string value from the map.
bool booleanValue(string_view key, bool default_) const
Returns a boolean value from the map.
void editInto(const Path &path, bool make_backup, bool allow_read_error, bool allow_write_error) const
Edits an existing file so that its contents reflect this map.
void add(string_view key, string_view value, bool clear=false)
Adds or updates a single item in the map.
unsigned int numericValue(string_view key, unsigned int default_) const
Returns a numeric value from the map.
const StringMap & map() const
Returns a reference to the internal map.
bool contains(string_view key) const
Returns true if the map contains the given key.
std::string expand(string_view value) const
Does one-pass variable substitution for the given string.
Path expandedPathValue(string_view key) const
Returns a mandatory path value from the map with expand().
void remove(string_view key)
Removes a value (if it exists).
MapFile()
Constructor for an empty map.
Path pathValue(string_view key) const
Returns a mandatory path value from the map.
const StringArray & keys() const
Returns a reference to the internal ordered list of keys.
void log(const std::string &prefix={}) const
Logs the contents.
A multimap-like container for command-line options and their values.
A Path object represents a file system path.
A class like c++17's std::string_view.
std::vector< std::string > StringArray
A std::vector of std::strings.
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Exception class for G::MapFile.