![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |

The SFXConfig class is used to save various application information in file when the application terminates or suspends so as to restore it the next time the application starts or resumes.
Information stored in file is managed by a pair of 'tag number' and its corresponding 'value'. (If a tag number is specified, its corresponding value can be obtained.)
A 'tag number' is a number from 0 to 60000 of the UInt32 type, and its corresponding 'value' is a value of any numerical or string type.
![]() |
About MIF File Setting |
|---|---|
Never forget to turn on the File option in the MIF file setting of privilege level. | |
Example 462. Write to the configuration file
SFXConfig config; // write string (tag number: 1) config.WriteSFXAnsiString(1, "saving data"); // save to file config.Save("data/def.txt");
Example 463. Read from the configuration file
SFXConfig config; // load file config.Load("data/def.txt"); // read string (tag number: 1) // second argument is default value SFXAnsiString str = config.ReadSFXAnsiString(1, "default text"); // str = "saving data"
Example 464. read and write data of various types
config.WriteSInt32(2, -17); // write data of SInt32 type config.WriteUInt08(3, 'a'); // write data of UInt08 type config.WriteBool(4, true); // write data of Bool type // buffer ByteConst data[] = {0x01, 0x11, 0x22, 0x33, 0x44}; SFXBuffer buffer(data, lengthof(data)); config.WriteSFXBuffer(5, buffer); // write data of SFXBuffer type SInt32 n1 = config.ReadSInt32(2, -9999); // read data of SInt32 type // n1 = -17 // second argument is default value AChar c = config.ReadUInt08(3, '\0'); // read data of UInt08 type // c = 'a' Bool b = config.ReadBool(4, false); // read data of Bool type // b = true // read data of SFXBuffer type SFXBuffer buff = config.ReadSFXBuffer(5, SFXBuffer());
| Constructor/Destructor |
|---|
|
SFXConfig( Void ) Constructor of SFXConfig class.
|
|
~SFXConfig( Void ) Destructor of SFXConfig class.
|
| Public Functions | |
|---|---|
| Void |
Clear( Void ) Delete all the entries in the SFXConfig instance.
|
| static SFXConfigConstRef |
EmptyInstance( Void ) Get an empty instance of the SFXConfig class.
|
| SInt32 |
GetSize( Void ) Get the number of the entries in the SFXConfig instance.
|
| SFCError |
Load(
SFXPathConstRef path
) Load the specified configuration file.
|
| SFCError |
ReadBinary(
UInt16 tag
, VoidConstHandle value
, UInt16Ptr length
) Read binary data from the entry with a specified tag.
|
| Bool |
ReadBool(
UInt16 tag
, Bool initial
) Read a value of Bool type from the entry with a specified tag.
|
| Float32 |
ReadFloat32(
UInt16 tag
, Float32 initial
) Read a value of Float32 type from the entry with a specified tag.
|
| Float64 |
ReadFloat64(
UInt16 tag
, Float64 initial
) Read a value of Float64 type from the entry with a specified tag.
|
| SFXAnsiString |
ReadSFXAnsiString(
UInt16 tag
, SFXAnsiStringConstRef initial
) Read an AChar string from the entry with a specified tag.
|
| SFXBuffer |
ReadSFXBuffer(
UInt16 tag
, SFXBufferConstRef initial
) Read a SFXBuffer data from the entry with a specified tag.
|
| SFXWideString |
ReadSFXWideString(
UInt16 tag
, SFXWideStringConstRef initial
) Read a string of WChar type from the entry with a specified tag.
|
| SInt08 |
ReadSInt08(
UInt16 tag
, SInt08 initial
) Read a value of SInt08 type from the entry with a specified tag.
|
| SInt16 |
ReadSInt16(
UInt16 tag
, SInt16 initial
) Read a value of SInt16 type from the entry with a specified tag.
|
| SInt32 |
ReadSInt32(
UInt16 tag
, SInt32 initial
) Read a value of SInt32 type from the entry with a specified tag.
|
| SInt64 |
ReadSInt64(
UInt16 tag
, SInt64 initial
) Read a value of SInt64 type from the entry with a specified tag.
|
| UInt08 |
ReadUInt08(
UInt16 tag
, UInt08 initial
) Read a value of UInt08 type from the entry with a specified tag.
|
| UInt16 |
ReadUInt16(
UInt16 tag
, UInt16 initial
) Read a value of UInt16 type from the entry with a specified tag.
|
| UInt32 |
ReadUInt32(
UInt16 tag
, UInt32 initial
) Read a value of UInt32 type from the entry with a specified tag.
|
| UInt64 |
ReadUInt64(
UInt16 tag
, UInt64 initial
) Read a value of UInt64 type from the entry with a specified tag.
|
| Void |
Remove(
UInt16 tag
) Delete a specified entry.
|
| SFCError |
Save(
SFXPathConstRef path
) Save( Void ) Save the settings in the configuration file.
|
| SFCError |
WriteBinary(
UInt16 tag
, VoidConstPtr value
, UInt16 length
) Write binary data to the entry with a specified tag.
|
| SFCError |
WriteBool(
UInt16 tag
, Bool value
) Write a value of Bool type to the entry with a specified tag.
|
| SFCError |
WriteFloat32(
UInt16 tag
, Float32 value
) Write a value of Float32 type to the entry with a specified tag.
|
| SFCError |
WriteFloat64(
UInt16 tag
, Float64 value
) Write a value of Float64 type to the entry with a specified tag.
|
| SFCError |
WriteSFXAnsiString(
UInt16 tag
, SFXAnsiStringConstRef value
) Write an AChar string to the entry with a specified tag.
|
| SFCError |
WriteSFXBuffer(
UInt16 tag
, SFXBufferConstRef value
) Write a SFXBuffer data to the entry with a specified tag.
|
| SFCError |
WriteSFXWideString(
UInt16 tag
, SFXWideStringConstRef value
) Write a WChar string to the entry with a specified tag.
|
| SFCError |
WriteSInt08(
UInt16 tag
, SInt08 value
) Write a value of SInt08 type to the entry with a specified tag.
|
| SFCError |
WriteSInt16(
UInt16 tag
, SInt16 value
) Write a value of SInt16 type to the entry with a specified tag.
|
| SFCError |
WriteSInt32(
UInt16 tag
, SInt32 value
) Write a value of SInt32 type to the entry with a specified tag.
|
| SFCError |
WriteSInt64(
UInt16 tag
, SInt64 value
) Write a value of SInt64 type to the entry with a specified tag.
|
| SFCError |
WriteUInt08(
UInt16 tag
, UInt08 value
) Write a value of UInt08 type to the entry with a specified tag.
|
| SFCError |
WriteUInt16(
UInt16 tag
, UInt16 value
) Write a value of UInt16 type to the entry with a specified tag.
|
| SFCError |
WriteUInt32(
UInt16 tag
, UInt32 value
) Write a value of UInt32 type to the entry with a specified tag.
|
| SFCError |
WriteUInt64(
UInt16 tag
, UInt64 value
) Write a value of UInt64 type to the entry with a specified tag.
|
[ public, explicit ] SFXConfig(Void);
The constructor does not read any data from the file.
[ public ] ~SFXConfig(Void);
The destructor calls the SFXConfig::Clear function, and deletes all the entries in the SFXConfig instance.
[ public ] Void Clear(Void);
The content of the SFXConfig instance updated by the SFXConfig::Clear function is not reflected to the configuration file until the SFXConfig::Save function is called.
SFXConfig config; // load configuration file config.Load("config.cfg"); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false); // delete all entries config.Clear();
[ public, static ] SFXConfigConstRef EmptyInstance(Void);
Get an instance that represents an empty configuration file.
[ public, const ] SInt32 GetSize(Void);
SFXConfig config; UInt32 entryNum = 0; // load configuration file config.Load("config.cfg"); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false); // get number of entries in SFXConfig instance entryNum = config.GetSize();
[ public ] SFCError Load( SFXPathConstRef path // path of configuration file );
Load the configuration file, and set the name of configuration file to the SFXConfig instance. And the SFXConfig::Save function creates the configuration file using the file name set to the SFXConfig instance.
![]() |
Note |
|---|---|
| Before using the SFXConfig class, the SFXConfig::Load function needs to be called. | |
![]() |
Note |
|---|---|
| When loading more than one configuration file, only the content of the configuration file loaded last will be valid. And the contents of the other configuration files will be destroyed. | |
SFXConfig config; // load configuration file config.Load(SFXPath("config.cfg")); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false);
[ public, const ] SFCError ReadBinary( UInt16 tag // tag VoidConstHandle value // handle of data to store UInt16Ptr length // length of data );
SFXConfig config; VoidConstPtr data; UInt16 len; // load configuration file config.Load("config.cfg"); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false); // save various application settings in configuration file config.Save(); // load configuration file config.Load("config.cfg"); // read binary data from entry with specified tag config.ReadBinary(100, &data, &len);
Read a value of Bool type written by the SFXConfig::WriteBool function from the entry with the specified tag.
SFXConfig config; Bool tmpBool; // load configuration file config.Load("config.cfg"); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false); // save application settings in configuration file config.Save(); // load configuration file config.Load("config.cfg"); // read value of Bool type tmpBool = config.ReadBool(100, false);
Read a value of Float32 type written by the SFXConfig::WriteFloat32 function from the entry with the specified tag.
Read a value of Float64 type written by the SFXConfig::WriteFloat64 function from the entry with the specified tag.
SFXConfig config; Float64 float64_1(0.12345), float64_2(0.000000), float64_3(-1.234); Float64 tmpFloat64; // load configuration file config.Load("config.cfg"); // write Float64 value config.WriteFloat64(100, float64_1); config.WriteFloat64(101, float64_2); config.WriteFloat64(102, float64_3); // save various application settings in configuration file config.Save(); // load configuration file config.Load("config.cfg"); // read value of Float64 type from entry with specified tag tmpFloat64 == config.ReadFloat64(100, float64_1);
[ public, const ] SFXAnsiString ReadSFXAnsiString( UInt16 tag // tag SFXAnsiStringConstRef initial // default value );
Read an AChar string written by the SFXConfig::WriteSFXAnsiString function from the entry with the specified tag.
An AChar string includes a null character. If the length of value is 1 byte, a SFXAnsiString instance including the null string is returned.
SFXConfig config; SFXAnsiString astr; // load configuration file config.Load("config.cfg"); // write AChar string config.WriteSFXAnsiString(100, "Config"); config.WriteSFXAnsiString(101, "Sample"); config.WriteSFXAnsiString(102, "SophiaFramework"); // save various application settings in configuration file config.Save(); // load configuration file config.Load("config.cfg"); // read AChar string astr = config.ReadSFXAnsiString(100, "Read Config");
[ public, const ] SFXBuffer ReadSFXBuffer( UInt16 tag // tag SFXBufferConstRef initial // default value );
Read a value of SFXBuffer type written by the SFXConfig::WriteSFXBuffer function from the entry with the specified tag.
[ public, const ] SFXWideString ReadSFXWideString( UInt16 tag // tag SFXWideStringConstRef initial // default value );
Read a string of WChar type written by the SFXConfig::WriteSFXWideString function from the entry with the specified tag.
A string of WChar type includes a null character. If the length of value is 2 bytes, a SFXWideString instance including the null string is returned.
SFXConfig config; SFXWideString wstr; // load configuration file config.Load("config.cfg"); // write WChar string config.WriteSFXWideString(100, "Config"); config.WriteSFXWideString(101, "Sample"); config.WriteSFXWideString(102, "SophiaFramework"); // save various application settings in configuration file config.Save(); // load configuration file config.Load("config.cfg"); // Read WChar string wstr = config.WriteSFXWideString(100, "Read Config");
Read a value of SInt08 type written by the SFXConfig::WriteSInt08 function from the entry with the specified tag.
Read a value of SInt16 type written by the SFXConfig::WriteSInt16 function from the entry with the specified tag.
Read a value of SInt32 type written by the SFXConfig::WriteSInt32 function from the entry with the specified tag.
SFXConfig config; SInt32 tmpInt; // load configuration file config.Load("config.cfg"); // write value of SInt32 type config.WriteSInt32(100, 0x00000000); config.WriteSInt32(101, 0x00005678); config.WriteSInt32(102, 0xffffffff); // save various application settings in configuration file config.Save(); // load the configuration file config.Load("config.cfg"); // read value of SInt32 type tmpInt = config.ReadSInt32(100, 0x12340000);
Read a value of SInt64 type written by the SFXConfig::WriteSInt64 function from the entry with the specified tag.
Read a value of UInt08 type written by the SFXConfig::WriteUInt08 function from the entry with the specified tag.
Read a value of UInt16 type written by the SFXConfig::WriteUInt16 function from the entry with the specified tag.
Read a value of UInt32 type written by the SFXConfig::WriteUInt32 function from the entry with the specified tag.
Read a value of UInt64 type written by the SFXConfig::WriteUInt64 function from the entry with the specified tag.
Delete the specified entry if it exists in the SFXConfig instance.
The content of the SFXConfig instance updated by the SFXConfig::Remove function is not reflected in the configuration file until the SFXConfig::Save function is called.
SFXConfig config; // load configuration file config.Load("config.cfg"); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false); // delete specified entry config.Remove(101);
[ public ] SFCError Save( SFXPathConstRef path // file path );
[ public ] SFCError Save(Void);
If the file path is not specified, the file path specified as an argument of the SFXConfig::Load function is used.
The configuration file is saved only if its content differs from the content of the SFXConfig instance.
SFXConfig config; // load configuration file config.Load(SFXPath("config.cfg")); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false); // save various application settings in configuration file config.Save();
[ public ] SFCError WriteBinary( UInt16 tag // tag VoidConstPtr value // pointer to binary data UInt16 length // length of binary data );
If the entry with the specified tag exists in the SFXConfig instance, overwrite specified lenghth of binary data to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write specified lenghth of binary data to this entry.
To read binary data from this entry, use the SFXConfig::ReadBinary function .
SFXConfig config;
AChar moji[] = {"abcdefghijk"};
// load configuration file
config.Load("config.cfg");
// write binary data
config.WriteBinary(100, SFXHelper::strlen(moji), (VoidConstPtr)moji);
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of Bool type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of Bool type to this entry.
To read a value of Bool type from this entry, use the SFXConfig::ReadBool function .
SFXConfig config; // load configuration file config.Load("config.cfg"); // write value of Bool type config.WriteBool(100, true); config.WriteBool(101, false);
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of Float32 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of Float32 type to this entry.
To read a value of Float32 type from this entry, use the SFXConfig::ReadFloat32 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of Float64 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of Float64 type to this entry.
To read a value of Float64 type from this entry, use the SFXConfig::ReadFloat64 function .
SFXConfig config; Float64 float64_1(0.12345), float64_2(0.000000), float64_3(-1.234); // load configuration file config.Load("config.cfg"); // write value of Float64 type config.WriteFloat64(100, float64_1); config.WriteFloat64(101, float64_2); config.WriteFloat64(102, float64_3);
[ public ] SFCError WriteSFXAnsiString( UInt16 tag // tag SFXAnsiStringConstRef value // AChar string to be written );
If the entry with the specified tag exists in the SFXConfig instance, overwrite an AChar string to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write an AChar string to this entry.
If the string is empty (null string), write a null string to this entry.
To read an AChar string from this entry, use the SFXConfig::ReadSFXAnsiString function .
SFXConfig config; // load configuration file config.Load("config.cfg"); // write AChar string config.WriteSFXAnsiString(100, "Config"); config.WriteSFXAnsiString(101, "Sample"); config.WriteSFXAnsiString(102, "SophiaFramework");
[ public ] SFCError WriteSFXBuffer( UInt16 tag // tag SFXBufferConstRef value // data of SFXBuffer type );
If the entry with the specified tag exists in the SFXConfig instance, overwrite a data of SFXBuffer type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a data of SFXBuffer type to this entry.
To read a data of SFXBuffer type from this entry, use the SFXConfig::ReadSFXBuffer function .
[ public ] SFCError WriteSFXWideString( UInt16 tag // tag SFXWideStringConstRef value // WChar string to be written );
If the entry with the specified tag exists in the SFXConfig instance, overwrite a WChar string to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a WChar string to this entry.
If the string is empty (null string), write a null string to this entry.
To read a WChar string from this entry, use the SFXConfig::ReadSFXWideString function .
SFXConfig config; // load configuration file config.Load("config.cfg"); // write WChar string config.WriteWideString(100, "Config"); config.WriteWideString(101, "Sample"); config.WriteWideString(102, "SophiaFramework");
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of SInt08 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of SInt08 type to this entry.
To read a value of SInt08 type from this entry, use the SFXConfig::ReadSInt08 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of SInt16 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of SInt16 type to this entry.
To read a value of SInt16 type from this entry, use the SFXConfig::ReadSInt16 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of SInt32 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of SInt32 type to this entry.
To read a value of SInt32 type from this entry, use the SFXConfig::ReadSInt32 function .
SFXConfig config;
// load configuration file
config.Load("config.cfg");
// write value of SInt32 type
config.WriteSInt32(100, 0x00000000);
config.WriteSInt32(101, 0x00005678);
config.WriteSInt32(102, 0xffffffff);
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of SInt64 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of SInt64 type to this entry.
To read a value of SInt64 type from this entry, use the SFXConfig::ReadSInt64 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of UInt08 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of UInt08 type to this entry.
To read a value of UInt08 type from this entry, use the SFXConfig::ReadUInt08 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of UInt16 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of UInt16 type to this entry.
To read a value of UInt16 type from this entry, use the SFXConfig::ReadUInt16 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of UInt32 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of UInt32 type to this entry.
To read a value of UInt32 type from this entry, use the SFXConfig::ReadUInt32 function .
If the entry with the specified tag exists in the SFXConfig instance, overwrite a value of UInt64 type to this entry.
If the entry with the specified tag does not exist in the SFXConfig instance, create a new entry and write a value of UInt64 type to this entry.
To read a value of UInt64 type from this entry, use the SFXConfig::ReadUInt64 function .
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|