Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <IniFile.h>
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< AString > | m_Comments |
AString | m_Filename |
bool | m_IsCaseInsensitive |
std::vector< key > | m_Keys |
std::vector< AString > | m_Names |
|
private |
cIniFile::cIniFile | ( | void | ) |
Creates a new instance with no data.
Definition at line 41 of file IniFile.cpp.
|
overridevirtualdefault |
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.
Add a key comment.
Implements cSettingsRepositoryInterface.
Definition at line 754 of file IniFile.cpp.
|
overridevirtual |
Add a key name.
Implements cSettingsRepositoryInterface.
Definition at line 278 of file IniFile.cpp.
|
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::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.
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 | ) |
|
inline |
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.
|
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.
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.
|
inlineoverridevirtual |
Writes the changes to the backing store, if the repository has one.
Implements cSettingsRepositoryInterface.
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.
|
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.
|
inline |
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.
|
inline |
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.
|
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.
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.
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.
|
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.
|
overridevirtual |
Gets the value; if not found, write the default to the repository.
Implements cSettingsRepositoryInterface.
Definition at line 524 of file IniFile.cpp.
|
inlineoverridevirtual |
Implements cSettingsRepositoryInterface.
double cIniFile::GetValueSetF | ( | const AString & | keyname, |
const AString & | valuename, | ||
const double | defValue = 0.0 |
||
) |
Definition at line 547 of file IniFile.cpp.
|
overridevirtual |
Implements cSettingsRepositoryInterface.
Definition at line 558 of file IniFile.cpp.
|
overridevirtual |
Implements cSettingsRepositoryInterface.
Definition at line 569 of file IniFile.cpp.
|
overridevirtual |
Returns true iff the specified value exists.
Implements cSettingsRepositoryInterface.
Definition at line 657 of file IniFile.cpp.
|
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.
|
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.
|
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::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.
|
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.