class EE::System::IniFile

Overview

#include <inifile.hpp>

class IniFile {
public:
    // enums

    enum errors;

    // structs

    struct key;

    // construction

    IniFile(const std::string& iniPath = "", bool autoLoad = true);
    IniFile(const Uint8* RAWData, const Uint32& size, bool autoLoad = true);
    IniFile(Pack* Pack, const 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, const std::string& iniPackPath);
    bool loadFromStream(IOStream& stream);
    void path(const std::string& newPath);
    const std::string& path() const;
    bool readFile();
    bool writeFile();
    bool writeStream(IOStream& stream);
    void clear();
    long findKey(const std::string& keyname) const;
    long findKey(const std::string_view& keyname) const;
    long findValue(unsigned const keyID, const std::string& valuename) const;
    long findValue(unsigned const keyID, const std::string_view& valuename) const;
    unsigned getNumKeys() const;
    unsigned addKeyName(const std::string& keyname);
    unsigned addKeyName(const std::string_view& keyname);
    std::string getKeyName(unsigned const keyID) const;
    unsigned getNumValues(unsigned const keyID);
    unsigned getNumValues(const std::string& keyname);
    std::string getValueName(unsigned const keyID, unsigned const valueID) const;
    std::string getValueName(const std::string& keyname, unsigned const valueID) const;
    std::string getValue(unsigned const keyID, unsigned const valueID, const std::string& defValue = "") const;
    std::string getValue(const std::string& keyname, const std::string& valuename, const std::string& defValue = "") const;
    int getValueI(const std::string& keyname, const std::string& valuename, int const defValue = 0) const;
    unsigned long getValueU(const std::string& keyname, const std::string& valuename, unsigned long const defValue = 0) const;
    bool getValueB(const std::string& keyname, const std::string& valuename, bool const defValue = false) const;
    double getValueF(const std::string& keyname, const std::string& valuename, double const defValue = 0.0) const;
    bool setValue(unsigned const keyID, unsigned const valueID, const std::string& value);
    bool setValue(const std::string& keyname, const std::string& valuename, const std::string& value, bool create = true);
    bool setValue(const std::string_view& keyname, const std::string_view& valuename, const std::string_view& value, bool create = true);
    bool setValueI(const std::string& keyname, const std::string& valuename, int const value, bool create = true);
    bool setValueU(const std::string& keyname, const std::string& valuename, unsigned long const value, bool create = true);
    bool setValueB(const std::string& keyname, const std::string& valuename, bool const value, bool create = true);
    bool setValueF(const std::string& keyname, const std::string& valuename, double const value, bool create = true);
    bool setValueV(const std::string& keyname, const std::string& valuename, char* format, ...);
    bool deleteValue(const std::string& keyname, const std::string& valuename);
    bool deleteKey(const std::string& keyname);
    unsigned numHeaderComments();
    void addHeaderComment(const std::string& 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(const std::string& keyname) const;
    bool addKeyComment(unsigned const keyID, const std::string& comment);
    bool addKeyComment(unsigned const keyID, const std::string_view& comment);
    bool addKeyComment(const std::string& keyname, const std::string& comment);
    bool addKeyComment(const std::string_view& keyname, const std::string_view& comment);
    std::string getKeyComment(unsigned const keyID, unsigned const commentID) const;
    std::string getKeyComment(const std::string& keyname, unsigned const commentID) const;
    bool deleteKeyComment(unsigned const keyID, unsigned const commentID);
    bool deleteKeyComment(const std::string& keyname, unsigned const commentID);
    bool deleteKeyComments(unsigned const keyID);
    bool deleteKeyComments(const std::string& 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(const std::string& 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, const 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, const std::string& iniPackPath)

Loads an ini file from a pack file

bool loadFromStream(IOStream& stream)

Loads an ini file from a stream

void path(const std::string& newPath)

Sets mPath of ini file to read and write from.

const 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.

bool writeStream(IOStream& stream)

Writes data stored in class to a IOStream.

void clear()

Deletes all stored ini data.

long findKey(const std::string& keyname) const

Returns:

index of specified key, or noID if not found.

long findValue(unsigned const keyID, const std::string& 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(const std::string& 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(const std::string& 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(const std::string& keyname, unsigned const valueID) const

Returns:

A value name from keyname and valueId

std::string getValue(unsigned const keyID, unsigned const valueID, const std::string& 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(const std::string& keyname, const std::string& valuename, const std::string& defValue = "") const

Gets a value from a keyname and valuename

int getValueI(const std::string& keyname, const std::string& valuename, int const defValue = 0) const

Gets the value as integer

unsigned long getValueU(const std::string& keyname, const std::string& valuename, unsigned long const defValue = 0) const

Gets the value as an unsigned long

bool getValueB(const std::string& keyname, const std::string& valuename, bool const defValue = false) const

Gets the value as boolean

double getValueF(const std::string& keyname, const std::string& valuename, double const defValue = 0.0) const

Gets the value as double

bool setValue(unsigned const keyID, unsigned const valueID, const std::string& 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(const std::string& keyname, const std::string& valuename, const std::string& 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(const std::string& keyname, const std::string& 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(const std::string& keyname, const std::string& 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(const std::string& keyname, const std::string& 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(const std::string& keyname, const std::string& 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(const std::string& keyname, const std::string& valuename, char* format, ...)

Sets a formated value from a keyname and a valuename

bool deleteValue(const std::string& keyname, const std::string& valuename)

Deletes specified value.

Returns:

true if value existed and deleted, false otherwise.

bool deleteKey(const 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(const std::string& 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, const std::string& 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.