Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
cIniFile Class Reference

#include <IniFile.h>

Inheritance diagram for cIniFile:
Inheritance graph
[legend]
Collaboration diagram for cIniFile:
Collaboration graph
[legend]

Classes

struct  key
 

Public Types

enum  { noID = Super::noID }
 
- Public Types inherited from cSettingsRepositoryInterface
enum  errors { noID = -1 }
 

Public Member Functions

void AddHeaderComment (const AString &comment)
 Adds a header comment. More...
 
bool AddKeyComment (const int keyID, const AString &comment)
 Add a key comment. More...
 
bool AddKeyComment (const AString &keyname, const AString &comment) override
 Add a key comment. More...
 
int AddKeyName (const AString &keyname) override
 Add a key name. More...
 
void AddValue (const AString &a_KeyName, const AString &a_ValueName, const AString &a_Value) override
 Adds a new value to the specified key. More...
 
void AddValueB (const AString &a_KeyName, const AString &a_ValueName, const bool a_Value)
 
void AddValueF (const AString &a_KeyName, const AString &a_ValueName, const double a_Value)
 
void AddValueI (const AString &a_KeyName, const AString &a_ValueName, const int a_Value)
 
void CaseInsensitive (void)
 
void CaseSensitive (void)
 
 cIniFile (void)
 Creates a new instance with no data. More...
 
void Clear (void)
 Deletes all stored ini data (but doesn't touch the file) More...
 
bool DeleteHeaderComment (int commentID)
 Deletes a header comment. More...
 
void DeleteHeaderComments (void)
 Deletes all header comments. More...
 
bool DeleteKey (const AString &keyname)
 
bool DeleteKeyComment (const int keyID, const int commentID)
 
bool DeleteKeyComment (const AString &keyname, const int commentID) override
 Delete a key comment, will always fail if the repository does not support comments. More...
 
bool DeleteKeyComments (const int keyID)
 
bool DeleteKeyComments (const AString &keyname)
 
bool DeleteValue (const AString &keyname, const AString &valuename) override
 Deletes the specified key, value pair. More...
 
bool DeleteValueByID (const int keyID, const int valueID)
 
int FindKey (const AString &keyname) const
 Returns index of specified key, or noID if not found. More...
 
int FindValue (const int keyID, const AString &valuename) const
 Returns index of specified value, in the specified key, or noID if not found. More...
 
virtual bool Flush () override
 Writes the changes to the backing store, if the repository has one. More...
 
AString GetHeaderComment (const int commentID) const
 Returns a header comment, or empty string if out of range. More...
 
AString GetKeyComment (const int keyID, const int commentID) const
 Return a key comment. More...
 
AString GetKeyComment (const AString &keyname, const int commentID) const override
 Return a key comment, returns "" for repositories that do not return comments. More...
 
AString GetKeyName (const int keyID) const
 
int GetNumHeaderComments (void)
 Returns the number of header comments. More...
 
int GetNumKeyComments (const int keyID) const
 Get number of key comments. More...
 
int GetNumKeyComments (const AString &keyname) const
 Get number of key comments. More...
 
int GetNumKeys (void) const
 Returns number of keys currently in the ini. More...
 
int GetNumValues (const AString &keyname) const
 
int GetNumValues (const int keyID) const
 
AString GetValue (const AString &keyname, const AString &valuename, const AString &defValue="") const override
 Get the value at the specified key and value, returns defValue on failure. More...
 
AString GetValue (const int keyID, const int valueID, const AString &defValue="") const
 
bool GetValueB (const AString &keyname, const AString &valuename, const bool defValue=false) const
 
double GetValueF (const AString &keyname, const AString &valuename, const double defValue=0) const
 
int GetValueI (const AString &keyname, const AString &valuename, const int defValue=0) const
 
AString GetValueName (const AString &keyname, const int valueID) const
 
AString GetValueName (const int keyID, const int valueID) const
 
virtual std::vector< std::pair< AString, AString > > GetValues (AString a_keyName) override
 returns a vector containing a name, value pair for each value under the key More...
 
AString GetValueSet (const AString &keyname, const AString &valuename, const AString &defValue="") override
 Gets the value; if not found, write the default to the repository. More...
 
bool GetValueSetB (const AString &keyname, const AString &valuename, const bool defValue=false) override
 
double GetValueSetF (const AString &keyname, const AString &valuename, const double defValue=0.0)
 
int GetValueSetI (const AString &keyname, const AString &valuename, const int defValue=0) override
 
Int64 GetValueSetI (const AString &keyname, const AString &valuename, const Int64 defValue=0) override
 
bool HasValue (const AString &a_KeyName, const AString &a_ValueName) const override
 Returns true iff the specified value exists. More...
 
virtual bool KeyExists (const AString a_keyName) const override
 Returns true iff the specified key exists. More...
 
bool ReadFile (const AString &a_FileName, bool a_AllowExampleRedirect=true)
 Reads the contents of the specified ini file If the file doesn't exist and a_AllowExampleRedirect is true, tries to read <basename>.example.ini, and writes its contents as <basename>.ini, if successful. More...
 
bool SetValue (const int keyID, const int valueID, const AString &value)
 
bool SetValue (const AString &a_KeyName, const AString &a_ValueName, const AString &a_Value, const bool a_CreateIfNotExists=true) override
 Overwrites the value of the key, value pair Specify the optional parameter as false if you do not want the value created if it doesn't exist. More...
 
bool SetValueB (const AString &a_KeyName, const AString &a_ValueName, const bool a_Value, const bool a_CreateIfNotExists=true)
 
bool SetValueF (const AString &a_KeyName, const AString &a_ValueName, const double a_Value, const bool a_CreateIfNotExists=true)
 
bool SetValueI (const AString &a_KeyName, const AString &a_ValueName, const int a_Value, const bool a_CreateIfNotExists=true) override
 
bool SetValueI (const AString &a_Keyname, const AString &a_ValueName, const Int64 a_Value, const bool a_CreateIfNotExists=true)
 
bool WriteFile (const AString &a_FileName) const
 Writes data stored in class to the specified ini file. More...
 
virtual ~cIniFile () override=default
 
- Public Member Functions inherited from cSettingsRepositoryInterface
virtual ~cSettingsRepositoryInterface ()=default
 

Private Types

typedef cSettingsRepositoryInterface Super
 

Private Member Functions

AString CheckCase (const AString &s) const
 If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is. More...
 
void RemoveBom (AString &a_line) const
 Removes the UTF-8 BOMs (Byte order makers), if present. More...
 

Private Attributes

std::vector< AStringm_Comments
 
AString m_Filename
 
bool m_IsCaseInsensitive
 
std::vector< keym_Keys
 
std::vector< AStringm_Names
 

Detailed Description

Definition at line 33 of file IniFile.h.

Member Typedef Documentation

Definition at line 36 of file IniFile.h.

Member Enumeration Documentation

anonymous enum
Enumerator
noID 

Definition at line 64 of file IniFile.h.

Constructor & Destructor Documentation

cIniFile::cIniFile ( void  )

Creates a new instance with no data.

Definition at line 41 of file IniFile.cpp.

virtual cIniFile::~cIniFile ( )
overridevirtualdefault

Member Function Documentation

void cIniFile::AddHeaderComment ( const AString comment)

Adds a header comment.

Definition at line 675 of file IniFile.cpp.

bool cIniFile::AddKeyComment ( const int  keyID,
const AString comment 
)

Add a key comment.

Definition at line 740 of file IniFile.cpp.

bool cIniFile::AddKeyComment ( const AString keyname,
const AString comment 
)
overridevirtual

Add a key comment.

Implements cSettingsRepositoryInterface.

Definition at line 754 of file IniFile.cpp.

int cIniFile::AddKeyName ( const AString keyname)
overridevirtual

Add a key name.

Implements cSettingsRepositoryInterface.

Definition at line 278 of file IniFile.cpp.

void cIniFile::AddValue ( const AString a_KeyName,
const AString a_ValueName,
const AString a_Value 
)
overridevirtual

Adds a new value to the specified key.

If a value of the same name already exists, creates another one

Implements cSettingsRepositoryInterface.

Definition at line 359 of file IniFile.cpp.

void cIniFile::AddValueB ( const AString a_KeyName,
const AString a_ValueName,
const bool  a_Value 
)
inline

Definition at line 154 of file IniFile.h.

void cIniFile::AddValueF ( const AString a_KeyName,
const AString a_ValueName,
const double  a_Value 
)

Definition at line 384 of file IniFile.cpp.

void cIniFile::AddValueI ( const AString a_KeyName,
const AString a_ValueName,
const int  a_Value 
)

Definition at line 375 of file IniFile.cpp.

void cIniFile::CaseInsensitive ( void  )
inline

Definition at line 85 of file IniFile.h.

void cIniFile::CaseSensitive ( void  )
inline

Definition at line 84 of file IniFile.h.

AString cIniFile::CheckCase ( const AString s) const
private

If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is.

Definition at line 852 of file IniFile.cpp.

void cIniFile::Clear ( void  )

Deletes all stored ini data (but doesn't touch the file)

Definition at line 646 of file IniFile.cpp.

bool cIniFile::DeleteHeaderComment ( int  commentID)

Deletes a header comment.

Returns true if successful

Definition at line 698 of file IniFile.cpp.

void cIniFile::DeleteHeaderComments ( void  )
inline

Deletes all header comments.

Definition at line 199 of file IniFile.h.

bool cIniFile::DeleteKey ( const AString keyname)

Definition at line 626 of file IniFile.cpp.

bool cIniFile::DeleteKeyComment ( const int  keyID,
const int  commentID 
)

Definition at line 795 of file IniFile.cpp.

bool cIniFile::DeleteKeyComment ( const AString keyname,
const int  commentID 
)
overridevirtual

Delete a key comment, will always fail if the repository does not support comments.

Implements cSettingsRepositoryInterface.

Definition at line 810 of file IniFile.cpp.

bool cIniFile::DeleteKeyComments ( const int  keyID)

Definition at line 824 of file IniFile.cpp.

bool cIniFile::DeleteKeyComments ( const AString keyname)

Definition at line 838 of file IniFile.cpp.

bool cIniFile::DeleteValue ( const AString keyname,
const AString valuename 
)
overridevirtual

Deletes the specified key, value pair.

Implements cSettingsRepositoryInterface.

Definition at line 605 of file IniFile.cpp.

bool cIniFile::DeleteValueByID ( const int  keyID,
const int  valueID 
)

Definition at line 587 of file IniFile.cpp.

int cIniFile::FindKey ( const AString keyname) const

Returns index of specified key, or noID if not found.

Definition at line 239 of file IniFile.cpp.

int cIniFile::FindValue ( const int  keyID,
const AString valuename 
) const

Returns index of specified value, in the specified key, or noID if not found.

Definition at line 256 of file IniFile.cpp.

virtual bool cIniFile::Flush ( )
inlineoverridevirtual

Writes the changes to the backing store, if the repository has one.

Implements cSettingsRepositoryInterface.

Definition at line 97 of file IniFile.h.

AString cIniFile::GetHeaderComment ( const int  commentID) const

Returns a header comment, or empty string if out of range.

Definition at line 685 of file IniFile.cpp.

AString cIniFile::GetKeyComment ( const int  keyID,
const int  commentID 
) const

Return a key comment.

Definition at line 768 of file IniFile.cpp.

AString cIniFile::GetKeyComment ( const AString keyname,
const int  commentID 
) const
overridevirtual

Return a key comment, returns "" for repositories that do not return comments.

Implements cSettingsRepositoryInterface.

Definition at line 781 of file IniFile.cpp.

AString cIniFile::GetKeyName ( const int  keyID) const

Definition at line 289 of file IniFile.cpp.

int cIniFile::GetNumHeaderComments ( void  )
inline

Returns the number of header comments.

Definition at line 187 of file IniFile.h.

int cIniFile::GetNumKeyComments ( const int  keyID) const

Get number of key comments.

Definition at line 713 of file IniFile.cpp.

int cIniFile::GetNumKeyComments ( const AString keyname) const

Get number of key comments.

Definition at line 726 of file IniFile.cpp.

int cIniFile::GetNumKeys ( void  ) const
inline

Returns number of keys currently in the ini.

Definition at line 112 of file IniFile.h.

int cIniFile::GetNumValues ( const AString keyname) const

Definition at line 318 of file IniFile.cpp.

int cIniFile::GetNumValues ( const int  keyID) const

Definition at line 305 of file IniFile.cpp.

AString cIniFile::GetValue ( const AString keyname,
const AString valuename,
const AString defValue = "" 
) const
overridevirtual

Get the value at the specified key and value, returns defValue on failure.

Implements cSettingsRepositoryInterface.

Definition at line 481 of file IniFile.cpp.

AString cIniFile::GetValue ( const int  keyID,
const int  valueID,
const AString defValue = "" 
) const

Definition at line 468 of file IniFile.cpp.

bool cIniFile::GetValueB ( const AString keyname,
const AString valuename,
const bool  defValue = false 
) const
inline

Definition at line 135 of file IniFile.h.

double cIniFile::GetValueF ( const AString keyname,
const AString valuename,
const double  defValue = 0 
) const

Definition at line 513 of file IniFile.cpp.

int cIniFile::GetValueI ( const AString keyname,
const AString valuename,
const int  defValue = 0 
) const

Definition at line 502 of file IniFile.cpp.

AString cIniFile::GetValueName ( const AString keyname,
const int  valueID 
) const

Definition at line 345 of file IniFile.cpp.

AString cIniFile::GetValueName ( const int  keyID,
const int  valueID 
) const

Definition at line 332 of file IniFile.cpp.

std::vector< std::pair< AString, AString > > cIniFile::GetValues ( AString  a_keyName)
overridevirtual

returns a vector containing a name, value pair for each value under the key

Implements cSettingsRepositoryInterface.

Definition at line 905 of file IniFile.cpp.

AString cIniFile::GetValueSet ( const AString keyname,
const AString valuename,
const AString defValue = "" 
)
overridevirtual

Gets the value; if not found, write the default to the repository.

Implements cSettingsRepositoryInterface.

Definition at line 524 of file IniFile.cpp.

bool cIniFile::GetValueSetB ( const AString keyname,
const AString valuename,
const bool  defValue = false 
)
inlineoverridevirtual

Implements cSettingsRepositoryInterface.

Definition at line 145 of file IniFile.h.

double cIniFile::GetValueSetF ( const AString keyname,
const AString valuename,
const double  defValue = 0.0 
)

Definition at line 547 of file IniFile.cpp.

int cIniFile::GetValueSetI ( const AString keyname,
const AString valuename,
const int  defValue = 0 
)
overridevirtual

Implements cSettingsRepositoryInterface.

Definition at line 558 of file IniFile.cpp.

Int64 cIniFile::GetValueSetI ( const AString keyname,
const AString valuename,
const Int64  defValue = 0 
)
overridevirtual

Implements cSettingsRepositoryInterface.

Definition at line 569 of file IniFile.cpp.

bool cIniFile::HasValue ( const AString a_KeyName,
const AString a_ValueName 
) const
overridevirtual

Returns true iff the specified value exists.

Implements cSettingsRepositoryInterface.

Definition at line 657 of file IniFile.cpp.

bool cIniFile::KeyExists ( const AString  keyname) const
overridevirtual

Returns true iff the specified key exists.

Implements cSettingsRepositoryInterface.

Definition at line 896 of file IniFile.cpp.

bool cIniFile::ReadFile ( const AString a_FileName,
bool  a_AllowExampleRedirect = true 
)

Reads the contents of the specified ini file If the file doesn't exist and a_AllowExampleRedirect is true, tries to read <basename>.example.ini, and writes its contents as <basename>.ini, if successful.

Returns true if successful, false otherwise.

Definition at line 50 of file IniFile.cpp.

void cIniFile::RemoveBom ( AString a_line) const
private

Removes the UTF-8 BOMs (Byte order makers), if present.

Definition at line 871 of file IniFile.cpp.

bool cIniFile::SetValue ( const int  keyID,
const int  valueID,
const AString value 
)

Definition at line 393 of file IniFile.cpp.

bool cIniFile::SetValue ( const AString a_KeyName,
const AString a_ValueName,
const AString a_Value,
const bool  a_CreateIfNotExists = true 
)
overridevirtual

Overwrites the value of the key, value pair Specify the optional parameter as false if you do not want the value created if it doesn't exist.

Returns true if value set, false otherwise.

Implements cSettingsRepositoryInterface.

Definition at line 407 of file IniFile.cpp.

bool cIniFile::SetValueB ( const AString a_KeyName,
const AString a_ValueName,
const bool  a_Value,
const bool  a_CreateIfNotExists = true 
)
inline

Definition at line 168 of file IniFile.h.

bool cIniFile::SetValueF ( const AString a_KeyName,
const AString a_ValueName,
const double  a_Value,
const bool  a_CreateIfNotExists = true 
)

Definition at line 459 of file IniFile.cpp.

bool cIniFile::SetValueI ( const AString a_KeyName,
const AString a_ValueName,
const int  a_Value,
const bool  a_CreateIfNotExists = true 
)
overridevirtual

Implements cSettingsRepositoryInterface.

Definition at line 441 of file IniFile.cpp.

bool cIniFile::SetValueI ( const AString a_Keyname,
const AString a_ValueName,
const Int64  a_Value,
const bool  a_CreateIfNotExists = true 
)

Definition at line 450 of file IniFile.cpp.

bool cIniFile::WriteFile ( const AString a_FileName) const

Writes data stored in class to the specified ini file.

Returns true on success, false on failure.

Definition at line 189 of file IniFile.cpp.

Member Data Documentation

std::vector<AString> cIniFile::m_Comments
private

Definition at line 52 of file IniFile.h.

AString cIniFile::m_Filename
private

Definition at line 41 of file IniFile.h.

bool cIniFile::m_IsCaseInsensitive
private

Definition at line 39 of file IniFile.h.

std::vector<key> cIniFile::m_Keys
private

Definition at line 50 of file IniFile.h.

std::vector<AString> cIniFile::m_Names
private

Definition at line 51 of file IniFile.h.


The documentation for this class was generated from the following files: