class EE::System::IniFile

Overview

#include <inifile.hpp>

class IniFile {
public:
    // enums

    enum errors;

    // structs

    struct key;
    struct value;

    // construction

    IniFile(std::string_view iniPath = {}, bool autoLoad = true);
    IniFile(const Uint8* RAWData, const Uint32& size, bool autoLoad = true);
    IniFile(Pack* Pack, std::string_view iniPackPath, bool autoLoad = true);
    IniFile(IOStream& stream, bool autoLoad = true);
    virtual ~IniFile();

    // methods

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

Detailed Documentation

Construction

IniFile(std::string_view 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_view 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(std::string_view 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_view iniPackPath)

Loads an ini file from a pack file

bool loadFromStream(IOStream& stream)

Loads an ini file from a stream

void path(std::string_view 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(std::string_view keyname) const

Returns:

index of specified key, or noID if not found.

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

Returns:

A value name from keyname and valueId

std::string getValue(unsigned const keyID, unsigned const valueID, std::string_view 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_view keyname, std::string_view valuename, std::string_view defValue = {}) const

Gets a value from a keyname and valuename

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

Gets the value as integer

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

Gets the value as an unsigned long

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

Gets the value as boolean

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

Gets the value as double

bool setValue(unsigned const keyID, unsigned const valueID, std::string_view value)

Sets value of [keyname] valuename =. Specify the optional parameter 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_view keyname, std::string_view valuename, std::string_view 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_view keyname, std::string_view 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_view keyname, std::string_view 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_view keyname, std::string_view 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_view keyname, std::string_view 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_view keyname, std::string_view valuename, char* format, ...)

Sets a formatted value from a keyname and a valuename

bool deleteValue(std::string_view keyname, std::string_view valuename)

Deletes specified value.

Returns:

true if value existed and deleted, false otherwise.

bool deleteKey(std::string_view 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_view 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_view 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.