class EE::System::IniFile¶
Overview¶
#include <inifile.hpp> class IniFile { public: // enums enum errors; // structs struct key; // construction IniFile(std::string const iniPath = "", bool autoLoad = true); IniFile(const Uint8* RAWData, const Uint32& size, bool autoLoad = true); IniFile(Pack* Pack, std::string iniPackPath, bool autoLoad = true); IniFile(IOStream& stream, bool autoLoad = true); virtual ~IniFile(); // methods bool loadFromFile(const std::string& iniPath); bool loadFromMemory(const Uint8* RAWData, const Uint32& size); bool loadFromPack(Pack* Pack, std::string iniPackPath); bool loadFromStream(IOStream& stream); void caseSensitive(); void caseInsensitive(); void path(std::string const newPath); std::string path() const; bool readFile(); bool writeFile(); void clear(); long findKey(std::string const keyname) const; long findValue(unsigned const keyID, std::string const valuename) const; unsigned getNumKeys() const; unsigned addKeyName(std::string const keyname); std::string getKeyName(unsigned const keyID) const; unsigned getNumValues(unsigned const keyID); unsigned getNumValues(std::string const keyname); std::string getValueName(unsigned const keyID, unsigned const valueID) const; std::string getValueName(std::string const keyname, unsigned const valueID) const; std::string getValue(unsigned const keyID, unsigned const valueID, std::string const defValue = "") const; std::string getValue(std::string const keyname, std::string const valuename, std::string const defValue = "") const; int getValueI(std::string const keyname, std::string const valuename, int const defValue = 0) const; unsigned long getValueU(std::string const keyname, std::string const valuename, unsigned long const defValue = 0) const; bool getValueB(std::string const keyname, std::string const valuename, bool const defValue = false) const; double getValueF(std::string const keyname, std::string const valuename, double const defValue = 0.0) const; unsigned getValueV( std::string const keyname, std::string const valuename, char* format, void* v1 = 0, void* v2 = 0, void* v3 = 0, void* v4 = 0, void* v5 = 0, void* v6 = 0, void* v7 = 0, void* v8 = 0, void* v9 = 0, void* v10 = 0, void* v11 = 0, void* v12 = 0, void* v13 = 0, void* v14 = 0, void* v15 = 0, void* v16 = 0 ); bool setValue(unsigned const keyID, unsigned const valueID, std::string const value); bool setValue(std::string const keyname, std::string const valuename, std::string const value, bool create = true); bool setValueI(std::string const keyname, std::string const valuename, int const value, bool create = true); bool setValueU(std::string const keyname, std::string const valuename, unsigned long const value, bool create = true); bool setValueB(std::string const keyname, std::string const valuename, bool const value, bool create = true); bool setValueF(std::string const keyname, std::string const valuename, double const value, bool create = true); bool setValueV(std::string const keyname, std::string const valuename, char* format, ...); bool deleteValue(std::string const keyname, std::string const valuename); bool deleteKey(std::string keyname); unsigned numHeaderComments(); void addHeaderComment(std::string const comment); std::string getHeaderComment(unsigned const commentID) const; bool deleteHeaderComment(unsigned commentID); void deleteHeaderComments(); std::map<std::string, std::string> getKeyMap(const unsigned& keyID) const; std::map<std::string, std::string> getKeyMap(const std::string& keyname) const; std::unordered_map<std::string, std::string> getKeyUnorderedMap(const unsigned& keyID) const; std::unordered_map<std::string, std::string> getKeyUnorderedMap(const std::string& keyname) const; unsigned getNumKeyComments(unsigned const keyID) const; unsigned getNumKeyComments(std::string const keyname) const; bool addKeyComment(unsigned const keyID, std::string const comment); bool addKeyComment(std::string const keyname, std::string const comment); std::string getKeyComment(unsigned const keyID, unsigned const commentID) const; std::string getKeyComment(std::string const keyname, unsigned const commentID) const; bool deleteKeyComment(unsigned const keyID, unsigned const commentID); bool deleteKeyComment(std::string const keyname, unsigned const commentID); bool deleteKeyComments(unsigned const keyID); bool deleteKeyComments(std::string const keyname); bool iniParsed(); bool keyExists(const std::string& keyname) const; bool keyValueExists(const std::string& keyname, const std::string& valuename) const; };
Detailed Documentation¶
Construction¶
IniFile(std::string const iniPath = "", bool autoLoad = true)
Initialize and load the ini file from path
IniFile(const Uint8* RAWData, const Uint32& size, bool autoLoad = true)
Initialize and load the ini file from memory
IniFile(Pack* Pack, std::string iniPackPath, bool autoLoad = true)
Initialize and load the ini file from a pack file
IniFile(IOStream& stream, bool autoLoad = true)
Initialize and load the ini file from a stream
Methods¶
bool loadFromFile(const std::string& iniPath)
Loads an ini file from path
bool loadFromMemory(const Uint8* RAWData, const Uint32& size)
Loads an ini file from memory
bool loadFromPack(Pack* Pack, std::string iniPackPath)
Loads an ini file from a pack file
bool loadFromStream(IOStream& stream)
Loads an ini file from a stream
void caseSensitive()
Sets whether or not keynames and valuenames should be case sensitive. The default is case insensitive.
void caseInsensitive()
See also:
CaseSensitive()
void path(std::string const newPath)
Sets mPath of ini file to read and write from.
std::string path() const
Returns:
The ini file path
bool readFile()
Reads ini file specified using mPath.
Returns:
true if successful, false otherwise.
bool writeFile()
Writes data stored in class to ini file.
void clear()
Deletes all stored ini data.
long findKey(std::string const keyname) const
Returns:
index of specified key, or noID if not found.
long findValue(unsigned const keyID, std::string const valuename) const
Returns:
index of specified value, in the specified key, or noID if not found.
unsigned getNumKeys() const
Returns:
number of Keys currently in the ini.
unsigned addKeyName(std::string const keyname)
Add a key name.
std::string getKeyName(unsigned const keyID) const
Returns:
key Names by index.
unsigned getNumValues(unsigned const keyID)
Returns:
number of values stored for specified key.
unsigned getNumValues(std::string const keyname)
Returns:
number of values stored for specified key from its name.
std::string getValueName(unsigned const keyID, unsigned const valueID) const
Returns:
value name by index for a given keyname or keyID.
std::string getValueName(std::string const keyname, unsigned const valueID) const
Returns:
A value name from keyname and valueId
std::string getValue(unsigned const keyID, unsigned const valueID, std::string const defValue = "") const
Gets value of [keyname] valuename =. Overloaded to return std::string, int, and double.
Returns:
defValue if key/value not found otherwise the value obtained.
std::string getValue(std::string const keyname, std::string const valuename, std::string const defValue = "") const
Gets a value from a keyname and valuename
int getValueI(std::string const keyname, std::string const valuename, int const defValue = 0) const
Gets the value as integer
unsigned long getValueU(std::string const keyname, std::string const valuename, unsigned long const defValue = 0) const
Gets the value as an unsigned long
bool getValueB(std::string const keyname, std::string const valuename, bool const defValue = false) const
Gets the value as boolean
double getValueF(std::string const keyname, std::string const valuename, double const defValue = 0.0) const
Gets the value as double
unsigned getValueV( std::string const keyname, std::string const valuename, char* format, void* v1 = 0, void* v2 = 0, void* v3 = 0, void* v4 = 0, void* v5 = 0, void* v6 = 0, void* v7 = 0, void* v8 = 0, void* v9 = 0, void* v10 = 0, void* v11 = 0, void* v12 = 0, void* v13 = 0, void* v14 = 0, void* v15 = 0, void* v16 = 0 )
This is a variable length formatted GetValue routine. All these voids are required because there is no vsscanf() like there is a vsprintf(). Only a maximum of 8 variable can be read.
bool setValue(unsigned const keyID, unsigned const valueID, std::string const value)
Sets value of [keyname] valuename =. Specify the optional paramter as false (0) if you do not want it to create the key if it doesn’t exist.
Returns:
true if data entered, false otherwise. Overloaded to accept std::string, int, and double.
bool setValue(std::string const keyname, std::string const valuename, std::string const value, bool create = true)
Sets the value from a keyname and a valuename
Parameters:
keyname |
The key name |
valuename |
The value name |
value |
The value to assign |
create |
If true it will create the keyname if doesn’t exists |
bool setValueI(std::string const keyname, std::string const valuename, int const value, bool create = true)
Sets a integer value from a keyname and a valuename
Parameters:
keyname |
The key name |
valuename |
The value name |
value |
The value to assign |
create |
If true it will create the keyname if doesn’t exists |
bool setValueU(std::string const keyname, std::string const valuename, unsigned long const value, bool create = true)
Sets a unsigned long value from a keyname and a valuename
Parameters:
keyname |
The key name |
valuename |
The value name |
value |
The value to assign |
create |
If true it will create the keyname if doesn’t exists |
bool setValueB(std::string const keyname, std::string const valuename, bool const value, bool create = true)
Sets a boolean value from a keyname and a valuename
Parameters:
keyname |
The key name |
valuename |
The value name |
value |
The value to assign |
create |
If true it will create the keyname if doesn’t exists |
bool setValueF(std::string const keyname, std::string const valuename, double const value, bool create = true)
Sets a double value from a keyname and a valuename
Parameters:
keyname |
The key name |
valuename |
The value name |
value |
The value to assign |
create |
If true it will create the keyname if doesn’t exists |
bool setValueV(std::string const keyname, std::string const valuename, char* format, ...)
Sets a formated value from a keyname and a valuename
bool deleteValue(std::string const keyname, std::string const valuename)
Deletes specified value.
Returns:
true if value existed and deleted, false otherwise.
bool deleteKey(std::string keyname)
Deletes specified key and all values contained within.
Returns:
true if key existed and deleted, false otherwise.
unsigned numHeaderComments()
Header comment functions. Header comments are those comments before the first key. Number of header comments.
void addHeaderComment(std::string const comment)
Add a header comment.
std::string getHeaderComment(unsigned const commentID) const
Return a header comment.
bool deleteHeaderComment(unsigned commentID)
Delete a header comment.
void deleteHeaderComments()
Delete all header comments.
unsigned getNumKeyComments(unsigned const keyID) const
Key comment functions. Key comments are those comments within a key. Any comments defined within value Names will be added to this list. Therefore, these comments will be moved to the top of the key definition when the IniFile::writeFile() is called. Number of key comments.
bool addKeyComment(unsigned const keyID, std::string const comment)
Add a key comment.
std::string getKeyComment(unsigned const keyID, unsigned const commentID) const
Return a key comment.
bool deleteKeyComment(unsigned const keyID, unsigned const commentID)
Delete a key comment.
bool deleteKeyComments(unsigned const keyID)
Delete all comments for a key.