![]() |
Humble Framework for SkyOS |
#include <HSettings.h>
Inheritance diagram for HSettings:

To write out the key/value pairs to a file, the HSettings class is derived from the HFile class, which wraps the UNIX standard file I/O routines and provides a little better error handing. The key/value pairs are written out to file using the format "key=value", which makes them easy to read and edit; this is also the format used by decades of ".ini" files. Future versions of the HSettings class will be able to categorize key/value pairs by using the [section] label, but for now they are written out to the file in alphabetical order.
One issue that must be dealt with is how to handle a setting that is missing; this is particularly crucial when an application is started for the first time, as the settings file may not exist at all! The HSettings class deals with missing values by requiring all Get() operations to specify a default value; if the setting isn't already present, then it is automatically added with the default value. Either way, calling the HSettings::Get() method is guaranteed to always return a value; HSettings does not, however, make any attempt to determine if the value is reasonable. In a solid and robust design, the value of every application setting should be sanity-checked before actually being acted upon...just in case.
Definition at line 53 of file HSettings.h.
Public Member Functions | |
| ErrCode | Load (const HFilename &fs) |
| Read in settings from an .ini file. | |
| ErrCode | Remove (StringPtr pstrKey) |
| Removes a setting from the file return NO_ERROR on success, error code otherwise. | |
| ErrCode | Save (const HFilename &fs) |
| Saves the settings to an .ini file. | |
| int32 | Get (StringPtr pstrKey, int32 nDefault) |
| Get an integer setting. | |
| StringPtr | Get (StringPtr pstrKey, StringPtr pstrDefault) |
| Get a string setting. | |
| bool | GetFlag (StringPtr pstrKey, const bool bDefault) |
| Get a boolean setting. | |
| int32 | Set (StringPtr pstrKey, const int32 nValue) |
| Set an integer setting. | |
| StringPtr | Set (StringPtr pstrKey, StringPtr pstrValue) |
| Set a string setting. | |
| bool | SetFlag (StringPtr pstrKey, const bool bValue) |
| Set a boolean flag. | |
| bool | IsEmpty (void) const |
| Evaluates if the settings dictionary is empty. | |
| bool | IsNotEmpty (void) const |
| Evaluates if the settings dictionary is not empty. | |
| ErrCode | RemoveAll (void) |
| Deletes ALL key:value pairs. | |
Protected Member Functions | |
| void | parseLine (const uint32 uLine, TextPtr pszLine) |
| Parse a line of text. | |
| ErrCode | writeToFile (void) |
| Writes out the settings to a file. | |
| StringPtr | getValue (StringPtr pstrKey) const |
| Gets a key:value pair from the underlying tree. | |
| ErrCode | setValue (StringPtr pstrKey, StringPtr pstrValue) |
| Sets a key/value pair in the data store. | |
Protected Attributes | |
| bool | m_bDirty |
| True if any settings have changed. | |
| HSettingsMap | m_map |
|
|
This method reads the contents of an .ini file; if the file is not found or cannot be parsed, a new data store is created.
Definition at line 87 of file HSettings.h. |
|
|
Definition at line 114 of file HSettings.h. |
|
|
This method writes out the current settings to an .ini file.
Definition at line 135 of file HSettings.h. |
|
||||||||||||
|
Definition at line 163 of file HSettings.h. |
|
|
Definition at line 198 of file HSettings.h. |
|
||||||||||||
|
Definition at line 225 of file HSettings.h. |
|
||||||||||||
|
Definition at line 242 of file HSettings.h. |
|
||||||||||||
|
Reads a boolean setting from the data repository. The following values are all considered true (case insensitive):
Definition at line 267 of file HSettings.h. |
|
||||||||||||
|
Definition at line 287 of file HSettings.h. |
|
||||||||||||
|
Definition at line 304 of file HSettings.h. |
|
||||||||||||
|
Saves a boolean setting to the data repository.
Definition at line 321 of file HSettings.h. |
|
|
Definition at line 336 of file HSettings.h. |
|
||||||||||||
|
Definition at line 362 of file HSettings.h. |
|
|
Definition at line 385 of file HSettings.h. |
|
|
Definition at line 389 of file HSettings.h. |
|
|
Definition at line 393 of file HSettings.h. |
2006.01.09-16:37