Class CConfigFile
Defined in File CConfigFile.h
Inheritance Relationships
Base Type
public mrpt::config::CConfigFileBase(Class CConfigFileBase)
Class Documentation
-
class CConfigFile : public mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from “.ini” files easily. The contents of the file will be modified by “write” operations in memory, and will be saved back to the file at the destructor, and only if at least one write operation has been applied.
Use base class
CConfigFileBase’s methodsread_{int,float,double,string,...}()andwrite()to actually read and write values.See: config_file_format
Public Functions
-
CConfigFile(const std::string &fileName)
Constructor associating with a given configuration filename. If the file exists, it loads and parses its contents; otherwise, it silently just start with an empty configuration file in memory. The file will be written upon destruction, or at any time using writeNow()
-
CConfigFile()
Constructor, does not open any file. You should call “setFileName” before reading or writing or otherwise nothing will be read and write operations will be eventually lost. However, it’s perfectly right to use this object without an associated file, in which case it will behave as an “in-memory” file.
-
void setFileName(const std::string &fil_path)
Associate this object with the given file, reading its contents right now. Upon destruction, the updated contents will be written to that file.
-
void writeNow()
Dumps the changes to the physical configuration file now, not waiting until destruction.
- Throws:
std::runtime_error – Upon error writing.
-
void discardSavingChanges()
Discard saving (current) changes to physical file upon destruction
-
inline std::string getAssociatedFile() const
Returns the file currently open by this object.
-
~CConfigFile() override
Destructor
-
virtual void getAllSections(std::vector<std::string> §ions) const override
Returns a list with all the section names.
-
virtual void clear() override
Empties the “config file”
-
virtual void getAllKeys(const std::string §ion, std::vector<std::string> &keys) const override
Returns a list with all the keys into a section.
Protected Functions
-
virtual void writeString(const std::string §ion, const std::string &name, const std::string &str) override
A virtual method to write a generic string
-
virtual std::string readString(const std::string §ion, const std::string &name, const std::string &defaultStr, bool failIfNotFound = false) const override
A virtual method to read a generic string.
- Throws:
std::exception – If the key name is not found and “failIfNotFound” is true. Otherwise the “defaultValue” is returned.
-
CConfigFile(const std::string &fileName)