C12Adapter Opensource C++ Interface
|
Class that allows reading and writing the Windows-like INI files sequentially. More...
Public Types | |
enum | LineType { LineEof = 0, LineKey = 1, LineNameValue = 2 } |
Type of the current line that was read from the INI file. More... | |
enum | { MAX_LINE_LENGTH = 1024 } |
Maximum input line length. | |
Public Member Functions | |
MIniFile () | |
Create a new INI file object, whether for reading from it, or for writing. More... | |
MIniFile (const MStdString &fileName, bool modeWrite=false) | |
Create and initialize a new INI file object. More... | |
virtual | ~MIniFile () |
Object destructor. | |
void | Init (const MStdString &fileName, bool modeWrite=false) |
Initialize the INI file object to work on the file name specified. More... | |
void | ReInit () |
Reinitialize the INI file for a repeat operation. More... | |
void | Done () |
Frees the resources not needed after the object is being used. | |
LineType | ReadLine () |
Read the next record from the file. More... | |
const MStdString & | GetKey () const |
Returns the current key, as read. More... | |
const MStdString & | GetName () const |
Returns the current name, as read. More... | |
const MVariant & | GetValue () const |
Returns the current value, as read. More... | |
MStdString | GetStringValue () const |
Returns the current value as string. More... | |
MStdString | GetFileName () const |
Get file name of the INI file. More... | |
int | GetFileLineNumber () const |
Get the current line number. More... | |
void | WriteKey (const MStdString &key) |
Write the key string into the file. More... | |
void | WriteNameValue (const MStdString &name, const MVariant &value) |
Write the name-equals-value string into the file. More... | |
void | ThrowError (const MStdString &errorMessage) |
Throws an exception and use current file name and line number associated with the file. More... | |
void | Throw (MConstLocalChars errorMessage) |
Throws an internationalized exception and uses the current file name and line number associated with the file. More... | |
bool | GetRespectValueType () const |
void | SetRespectValueType (bool yes) |
![]() | |
virtual | ~MObject () |
Object destructor. | |
virtual const MClass * | GetClass () const =0 |
Get the final class of the object. More... | |
virtual unsigned | GetEmbeddedSizeof () const |
For embedded object types, return the size of the class. More... | |
bool | IsEmbeddedObject () const |
Tell if the object is of embedded kind. More... | |
SHOW_INTERNAL MVariant | Call (const MStdString &name, const MVariant ¶ms) |
Call the object service with parameters, given as variant. More... | |
MVariant | Call0 (const MStdString &name) |
Call the object service with no parameters. More... | |
MVariant | Call1 (const MStdString &name, const MVariant &p1) |
Call the object service with one parameter. More... | |
MVariant | Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2) |
Call the object service with two parameter. More... | |
MVariant | Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3) |
Call the object service with three parameter. More... | |
MVariant | Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4) |
Call the object service with four parameter. More... | |
MVariant | Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5) |
Call the object service with five parameter. More... | |
MVariant | Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6) |
Call the object service with six parameter. More... | |
virtual MVariant | CallV (const MStdString &name, const MVariant::VariantVector ¶ms) |
Call the object service with parameters, given as variant vector. More... | |
virtual bool | IsPropertyPresent (const MStdString &name) const |
Tell if the property with the given name exists. | |
virtual bool | IsServicePresent (const MStdString &name) const |
Tell if the service with the given name exists. | |
virtual MVariant | GetProperty (const MStdString &name) const |
Get the property value using name of the property. More... | |
virtual void | SetProperty (const MStdString &name, const MVariant &value) |
Set the property using name of the property, and value. More... | |
virtual MStdStringVector | GetAllPropertyNames () const |
Return the list of publicly available properties, persistent or not. More... | |
virtual MStdStringVector | GetAllPersistentPropertyNames () const |
Return the list of persistent properties. More... | |
virtual void | SetPersistentPropertiesToDefault () |
Set the persistent properties of the object to their default values. More... | |
virtual MVariant | GetPersistentPropertyDefaultValue (const MStdString &name) const |
Get the default value of persistent property with the name given. More... | |
virtual void | SetPersistentPropertyToDefault (const MStdString &name) |
Set the persistent property with the name given to default value. More... | |
virtual const char * | GetType () const |
Get the name of the type for the object (could be the same as class name). | |
virtual void | SetType (const MStdString &) |
Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More... | |
virtual void | Validate () |
Validate internal structures of the object. More... | |
Additional Inherited Members | |
![]() | |
static const MClass * | GetStaticClass () |
Get the declared class of this particular object. More... | |
static bool | IsClassPresent (const MStdString &name) |
Tells if the given class name is available. More... | |
![]() | |
static const MClass | s_class |
Class of MObject. | |
![]() | |
MObject () | |
Object constructor, protected as the class is abstract. | |
void | DoSetPersistentPropertiesToDefault (const MClass *staticClass) |
Set the persistent properties to their default values for one object provided the class for that object. More... | |
Class that allows reading and writing the Windows-like INI files sequentially.
Note that there is no searching through the file for certain key and value implemented, the file has to be read until a desired data is found.
The syntax of the INI file is as follows:
The characters after the semicolon to the end of the line are ignored, except in the case when semicolons are inside strings. Obviously, if the strings are not enclosed in quotes, such string cannot have semicolons.
Blanks around the equal sign are not significant (unlike in many Windows implementations of ini file). Leading and trailing blanks are always stripped down, including ones that precede the semicolon comment.
It is allowed to have multiple keys with the same name.
One cannot use the same object for both reading and writing simultaneously. Whether the reading or writing is to be performed is specified in the parameter to the Init service.
During the reading, the blank lines are skipped. During writing one single blank line is added before each key. The comments are not stored in the INI file, and because of it the output file will not have them.
The errors that can happen during handling of INI file are of MException type.
enum MIniFile::LineType |
MIniFile::MIniFile | ( | ) |
Create a new INI file object, whether for reading from it, or for writing.
The constructor does not specify the mode, and the object itself is useless until Init is called.
MIniFile::MIniFile | ( | const MStdString & | fileName, |
bool | modeWrite = false |
||
) |
Create and initialize a new INI file object.
fileName | File name to open for either reading or writing File can be absolute or relative path, file extension has to be present, no defaults are assumed. |
modeWrite | Whether this is for writing the ini file, otherwise read-only. |
|
inline |
Get the current line number.
|
inline |
Get file name of the INI file.
Full path is returned.
|
inline |
Returns the current key, as read.
Note that if the current line is the name-value line, the key returned is the nearest key above, or an empty string if there was no key read.
|
inline |
Returns the current name, as read.
Note that if the current line is the key line, the name returned relates to the previous name=value pair.
|
inline |
When reading ini, this option controls expected value types
This option allows handling some special ini file cases such a having values that are file names, possibly with back slashes, that are not enclosed in quotes.
MStdString MIniFile::GetStringValue | ( | ) | const |
Returns the current value as string.
Note that if the current line is the key line, the value returned relates to the previous name=value pair.
|
inline |
Returns the current value, as read.
Note that if the current line is the key line, the value returned relates to the previous name=value pair.
void MIniFile::Init | ( | const MStdString & | fileName, |
bool | modeWrite = false |
||
) |
Initialize the INI file object to work on the file name specified.
fileName | File name to open for either reading or writing File can be absolute or relative path, file extension has to be present, no defaults are assumed. |
modeWrite | Whether this is for writing the ini file, otherwise read-only. |
LineType MIniFile::ReadLine | ( | ) |
Read the next record from the file.
Skip empty lines. Note that the keys are also read through this service.
void MIniFile::ReInit | ( | ) |
Reinitialize the INI file for a repeat operation.
When reading the ini file start reading from the beginning of the file, and when writing truncate the file to zero size.
|
inline |
When reading ini, this option controls expected value types
This option allows handling some special ini file cases such a having values that are file names, possibly with back slashes, that are not enclosed in quotes.
void MIniFile::Throw | ( | MConstLocalChars | errorMessage | ) |
Throws an internationalized exception and uses the current file name and line number associated with the file.
errorMessage | Error message to throw |
void MIniFile::ThrowError | ( | const MStdString & | errorMessage | ) |
Throws an exception and use current file name and line number associated with the file.
errorMessage | Error message to throw |
void MIniFile::WriteKey | ( | const MStdString & | key | ) |
Write the key string into the file.
The file is added with [key] where key is the value of the given string, without quotes.
key | The key string, shall have no ']' in it or an exception is thrown |
void MIniFile::WriteNameValue | ( | const MStdString & | name, |
const MVariant & | value | ||
) |
Write the name-equals-value string into the file.