PrevNextUpHome SophiaFramework UNIVERSE 5.3

20.5. SFXConfig Class: for managing the entries of (tag, value)

The SFXConfig class is used to save the entries of (tag, value) to file.

If the entries of (tag, value) are written into the SFXConfig instance when the applet ends or suspends, they can be restored from this instance when the applet starts or resumes.

When a entry of (tag, value) is written, any value from 0 to 65535 of the UInt16 type can be set as the tag and any numeric, string, or buffer can be set as the value.

By specifying the tag, the corresponding value can be read from the SFXConfig instance.

[Caution] About MIF File Setting

It is necessary to turn on the File option in the MIF file setting of privilege level when the SFXConfig class is used.

Example 20.20. Writing the entry of (tag, value)

SFXConfig config;

// write the entry of (tag: 1, value: "saving data") into SFXConfig
config.WriteSFXAnsiString(1, "saving data");

// save the SFXConfig instance to the configuration file
config.Save(SFXPath("/data/applet.cfg"));

Example 20.21. Reading the value of the entry with the specified tag

SFXConfig config;

// load the SFXConfig instance from the configuration file
config.Load(SFXPath("/data/applet.cfg"));

// get the value of the entry where tag is "1"
// * the second argument is the default value, 
//   which will be returned if the entry in question is not found
SFXAnsiString value = config.ReadSFXAnsiString(1, "default text");
// now, value is set to "saving data"

Example 20.22. Writing and reading various values

config.WriteSInt32(2, -17); // value of the SInt32 type
config.WriteUInt08(3, 'a'); // value of the UInt08 type
config.WriteBool(4, true);  // value of the Bool type


ByteConst data[] = {0x01, 0x11, 0x22, 0x33, 0x44};
SFXBuffer buffer(data, lengthof(data));
config.WriteSFXBuffer(5, buffer);        // value of the SFXBuffer type

// get the value of the entry with the specified tag
// * the second argument is the default value, 
//   which will be returned if the pair element in question is not found

SInt32 n1 = config.ReadSInt32(2, -9999); // value of the entry where tag is "2"
// n1 = -17 of the SInt32 type

AChar c = config.ReadUInt08(3, '\0');    // value of the entry where tag is "3"
// c = 'a' of the UInt08 type

Bool b = config.ReadBool(4, false);      // value of the entry where tag is "4"
// b = true of the Bool type

SFXBuffer buff = config.ReadSFXBuffer(5, SFXBuffer()); // value of the entry where tag is "5"
// buff = {0x01, 0x11, 0x22, 0x33, 0x44}