PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

19.5. Config File

SFXConfig is the class for reading and writing data such as numeric or string to be stored in specified file.

To store information on the application settings etc., use the SFXConfig class.

In the SFXConfig class, tag number (UInt32) and data (numeric or string) are managed in pair. And data is read or written by specifying tag number.

[Caution] About MIF File Setting

Never forget to turn on the File option in the MIF file setting of privilege level.

Example 19.17. Write to the config file

SFXConfig config;

// write string data (tag number is 1)
config.WriteSFXAnsiString(1, "saving data");

// save file
config.Save("data/def.txt");

Example 19.18. Read from the config file

SFXConfig config;

// read from file
config.Load("data/def.txt");

// read string data (tag number is 1)
// 2nd argument is default value
SFXAnsiString str = config.ReadSFXAnsiString(1, "default text");
// str = "saving data" 

Example 19.19. read, write with various data 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());