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 AString &keyname, const AString &comment) override
 Add a key comment. More...
 
bool AddKeyComment (const int keyID, const AString &comment)
 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 AString &keyname, const int commentID) override
 Delete a key comment, will always fail if the repository does not support comments. More...
 
bool DeleteKeyComment (const int keyID, const int commentID)
 
bool DeleteKeyComments (const AString &keyname)
 
bool DeleteKeyComments (const int keyID)
 
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 AString &keyname, const int commentID) const override
 Return a key comment, returns "" for repositories that do not return comments. More...
 
AString GetKeyComment (const int keyID, const int commentID) const
 Return a key comment. More...
 
AString GetKeyName (const int keyID) const
 
int GetNumHeaderComments (void)
 Returns the number of header comments. More...
 
int GetNumKeyComments (const AString &keyname) const
 Get number of key comments. More...
 
int GetNumKeyComments (const int keyID) 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 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 SetValue (const int keyID, const int valueID, const AString &value)
 
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...
 
- Public Member Functions inherited from cSettingsRepositoryInterface
 cSettingsRepositoryInterface ()=default
 
 DISALLOW_COPY_AND_ASSIGN (cSettingsRepositoryInterface)
 
virtual ~cSettingsRepositoryInterface ()=default
 

Private Types

using Super = cSettingsRepositoryInterface
 

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

◆ Super

Definition at line 40 of file IniFile.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
noID 

Definition at line 70 of file IniFile.h.

Constructor & Destructor Documentation

◆ cIniFile()

cIniFile::cIniFile ( void  )

Creates a new instance with no data.

Definition at line 41 of file IniFile.cpp.

Member Function Documentation

◆ AddHeaderComment()

void cIniFile::AddHeaderComment ( const AString comment)

Adds a header comment.

Definition at line 675 of file IniFile.cpp.

◆ AddKeyComment() [1/2]

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

Add a key comment.

Implements cSettingsRepositoryInterface.

Definition at line 754 of file IniFile.cpp.

◆ AddKeyComment() [2/2]

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

Add a key comment.

Definition at line 740 of file IniFile.cpp.

◆ AddKeyName()

int cIniFile::AddKeyName ( const AString keyname)
overridevirtual

Add a key name.

Implements cSettingsRepositoryInterface.

Definition at line 278 of file IniFile.cpp.

◆ AddValue()

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.

◆ AddValueB()

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

Definition at line 159 of file IniFile.h.

◆ AddValueF()

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

Definition at line 384 of file IniFile.cpp.

◆ AddValueI()

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

Definition at line 375 of file IniFile.cpp.

◆ CaseInsensitive()

void cIniFile::CaseInsensitive ( void  )
inline

Definition at line 90 of file IniFile.h.

◆ CaseSensitive()

void cIniFile::CaseSensitive ( void  )
inline

Definition at line 89 of file IniFile.h.

◆ CheckCase()

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.

◆ Clear()

void cIniFile::Clear ( void  )

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

Definition at line 646 of file IniFile.cpp.

◆ DeleteHeaderComment()

bool cIniFile::DeleteHeaderComment ( int  commentID)

Deletes a header comment.

Returns true if successful

Definition at line 698 of file IniFile.cpp.

◆ DeleteHeaderComments()

void cIniFile::DeleteHeaderComments ( void  )
inline

Deletes all header comments.

Definition at line 204 of file IniFile.h.

◆ DeleteKey()

bool cIniFile::DeleteKey ( const AString keyname)

Definition at line 626 of file IniFile.cpp.

◆ DeleteKeyComment() [1/2]

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.

◆ DeleteKeyComment() [2/2]

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

Definition at line 795 of file IniFile.cpp.

◆ DeleteKeyComments() [1/2]

bool cIniFile::DeleteKeyComments ( const AString keyname)

Definition at line 838 of file IniFile.cpp.

◆ DeleteKeyComments() [2/2]

bool cIniFile::DeleteKeyComments ( const int  keyID)

Definition at line 824 of file IniFile.cpp.

◆ DeleteValue()

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.

◆ DeleteValueByID()

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

Definition at line 587 of file IniFile.cpp.

◆ FindKey()

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.

◆ FindValue()

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.

◆ Flush()

virtual bool cIniFile::Flush ( )
inlineoverridevirtual

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

Implements cSettingsRepositoryInterface.

Definition at line 102 of file IniFile.h.

◆ GetHeaderComment()

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.

◆ GetKeyComment() [1/2]

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.

◆ GetKeyComment() [2/2]

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

Return a key comment.

Definition at line 768 of file IniFile.cpp.

◆ GetKeyName()

AString cIniFile::GetKeyName ( const int  keyID) const

Definition at line 289 of file IniFile.cpp.

◆ GetNumHeaderComments()

int cIniFile::GetNumHeaderComments ( void  )
inline

Returns the number of header comments.

Definition at line 192 of file IniFile.h.

◆ GetNumKeyComments() [1/2]

int cIniFile::GetNumKeyComments ( const AString keyname) const

Get number of key comments.

Definition at line 726 of file IniFile.cpp.

◆ GetNumKeyComments() [2/2]

int cIniFile::GetNumKeyComments ( const int  keyID) const

Get number of key comments.

Definition at line 713 of file IniFile.cpp.

◆ GetNumKeys()

int cIniFile::GetNumKeys ( void  ) const
inline

Returns number of keys currently in the ini.

Definition at line 117 of file IniFile.h.

◆ GetNumValues() [1/2]

int cIniFile::GetNumValues ( const AString keyname) const

Definition at line 318 of file IniFile.cpp.

◆ GetNumValues() [2/2]

int cIniFile::GetNumValues ( const int  keyID) const

Definition at line 305 of file IniFile.cpp.

◆ GetValue() [1/2]

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.

◆ GetValue() [2/2]

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

Definition at line 468 of file IniFile.cpp.

◆ GetValueB()

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

Definition at line 140 of file IniFile.h.

◆ GetValueF()

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

Definition at line 513 of file IniFile.cpp.

◆ GetValueI()

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

Definition at line 502 of file IniFile.cpp.

◆ GetValueName() [1/2]

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

Definition at line 345 of file IniFile.cpp.

◆ GetValueName() [2/2]

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

Definition at line 332 of file IniFile.cpp.

◆ GetValues()

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.

◆ GetValueSet()

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.

◆ GetValueSetB()

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

Implements cSettingsRepositoryInterface.

Definition at line 150 of file IniFile.h.

◆ GetValueSetF()

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

Definition at line 547 of file IniFile.cpp.

◆ GetValueSetI() [1/2]

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

Implements cSettingsRepositoryInterface.

Definition at line 558 of file IniFile.cpp.

◆ GetValueSetI() [2/2]

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

Implements cSettingsRepositoryInterface.

Definition at line 569 of file IniFile.cpp.

◆ HasValue()

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.

◆ KeyExists()

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.

◆ ReadFile()

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.

◆ RemoveBom()

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.

◆ SetValue() [1/2]

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.

◆ SetValue() [2/2]

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

Definition at line 393 of file IniFile.cpp.

◆ SetValueB()

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

Definition at line 173 of file IniFile.h.

◆ SetValueF()

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.

◆ SetValueI() [1/2]

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.

◆ SetValueI() [2/2]

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.

◆ WriteFile()

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

◆ m_Comments

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

Definition at line 56 of file IniFile.h.

◆ m_Filename

AString cIniFile::m_Filename
private

Definition at line 45 of file IniFile.h.

◆ m_IsCaseInsensitive

bool cIniFile::m_IsCaseInsensitive
private

Definition at line 43 of file IniFile.h.

◆ m_Keys

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

Definition at line 54 of file IniFile.h.

◆ m_Names

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

Definition at line 55 of file IniFile.h.


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