82 explicit MapFile(
const Path & , std::string_view kind = {} ) ;
90 MapFile(
const Path & , std::string_view kind , std::nothrow_t ) ;
94 explicit MapFile( std::istream & ) ;
100 void add( std::string_view key , std::string_view
value ,
bool clear =
false ) ;
105 bool update( std::string_view key , std::string_view
value ) ;
109 bool remove( std::string_view key ) ;
112 void writeItem( std::ostream & , std::string_view key )
const ;
115 static void writeItem( std::ostream & , std::string_view key , std::string_view
value ) ;
118 Path
editInto(
const Path & path ,
bool make_backup ,
bool do_throw =
true )
const ;
123 bool contains( std::string_view key )
const ;
126 Path
pathValue( std::string_view key )
const ;
130 Path
pathValue( std::string_view key ,
const Path & default_ )
const ;
133 unsigned int numericValue( std::string_view key ,
unsigned int default_ )
const ;
136 std::string
value( std::string_view key , std::string_view default_ = {} )
const ;
140 bool valueContains( std::string_view key , std::string_view token , std::string_view default_ = {} )
const ;
144 bool booleanValue( std::string_view key ,
bool default_ )
const ;
152 void log(
const std::string & prefix = {} )
const ;
155 std::string
expand( std::string_view
value )
const ;
171 using List = std::vector<std::string> ;
172 void readFromFile(
const Path & , std::string_view ,
bool do_throw =
true ) ;
173 void readFromStream( std::istream & ss ) ;
174 List readLines(
const Path & , std::string_view ,
bool do_throw )
const ;
175 static std::pair<std::string_view,std::string_view> split( std::string_view ) ;
176 static std::string join( std::string_view , std::string_view ) ;
177 static std::string quote(
const std::string & ) ;
178 bool expand_( std::string & )
const ;
179 std::string mandatoryValue( std::string_view )
const ;
180 static bool valued(
const std::string & ) ;
181 static bool commentedOut(
const std::string & ) ;
182 static std::string strkind( std::string_view ) ;
183 static std::string strpath(
const Path & ) ;
184 static Error readError(
const Path & , std::string_view ) ;
185 static Error writeError(
const Path & , std::string_view = {} ) ;
186 static Error missingValueError(
const Path & ,
const std::string & ,
const std::string & ) ;
187 StringMap::const_iterator find( std::string_view )
const ;
188 StringMap::iterator find( std::string_view ) ;
189 static Path toPath( std::string_view ) ;
A general-purpose exception class derived from std::exception and containing an error message.
Exception(std::initializer_list< std::string_view >)
Constructor.
A class for reading, writing and editing key=value files, supporting variable expansion of percent-ke...
bool remove(std::string_view key)
Removes a value (if it exists).
unsigned int numericValue(std::string_view key, unsigned int default_) const
Returns a numeric value from the map.
Path expandedPathValue(std::string_view key) const
Returns a mandatory path value from the map with expand().
std::string value(std::string_view key, std::string_view default_={}) const
Returns a string value from the map.
bool valueContains(std::string_view key, std::string_view token, std::string_view default_={}) const
Returns true if value(key,default_) contains the given comma-separated token.
bool update(std::string_view key, std::string_view value)
Updates an existing value.
std::string expand(std::string_view value) const
Does one-pass variable substitution for the given string.
bool booleanValue(std::string_view key, bool default_) const
Returns a boolean value from the map.
const StringMap & map() const
Returns a reference to the internal map.
Path editInto(const Path &path, bool make_backup, bool do_throw=true) const
Edits an existing file so that its contents reflect this map.
void add(std::string_view key, std::string_view value, bool clear=false)
Adds or updates a single item in the map.
bool contains(std::string_view key) const
Returns true if the map contains the given key.
MapFile()
Constructor for an empty map.
const StringArray & keys() const
Returns a reference to the internal ordered list of keys.
void writeItem(std::ostream &, std::string_view key) const
Writes a single item from this map to the stream.
void log(const std::string &prefix={}) const
Logs the contents.
Path pathValue(std::string_view key) const
Returns a mandatory path value from the map.
A multimap-like container for command-line options and their values.
A Path object represents a file system path.
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.