CSettings Documentation

using namespace CSettings;

typedef unsigned int uint;

Public Methods

CSettings(const char*);

The only constructor available needs a filename to use for storing the settings. It's best to make sure that the filename is program-specific, because if a file with the same name exists and is not a valid settings file, it will be deleted and replaced with the settings manager's file. The constructor will not load the data from the file. It will be done on demand when calling a Get* function. If you want to load the data at a given time, please use the LoadData function.

~CSettings();

This is the deconstructor. Frees memory, closes file handles, etc.

void ClearMemory();

Use this function to free all the memory the CSettings object has allocated. New memory will need to be allocated if there will be a request in the form of a Get* function call. This function will call Sync().

void DropData();

This function can be used to drop all data stored by the object. This function does not call Sync(). This means that the memory is cleared, but the data will remain in the file until Set(...) or SetPointerData(...) is called or until Sync() is called explicitly. If none of the above has been done, the data can still be retrieved by calling LoadData().

void LoadData();

This is the function you can use to load the settings data into memory at any time. If the data has already been loaded, nothing will happen.

void Sync();

You can use this function to make the CSettings object write it's memory to the settings file. This will also get called automatically by the deconstructor.

uint GetSize();

This small function will return the number of string data types currently stored in memory. This function will call LoadData().

uint GetSize(uint d_type);

This will return the number of data types of the given size in bytes being held in memory. This function will call LoadData().

uint SetPointerData(const void *data, uint size, int setting = -1);

This function is used to set any amount of pointer data. This can be a memory block you want to be able to recover the next time your program loads, etc. The first argument is a pointer to the data you want to safe. The second is the size of the data in bytes. The third argument is the setting's number. If not set a new settings number will be allocated and returned. It is important to use enum values as setting values. This is because setting is actually an index of an internal table holding the data. This function will call LoadData().

example:
    typedef enum {
        WELCOME_STRING = 0,
        INIT_DATA,
        MONSTER_TEXT,
        USER_INPUT0
        USER_INPUT1
        USER_INPUT2
        USER_INPUT3
        USER_INPUT4
    } my_settings;
template < class tName >
uint Set(tName val, int setting = -1);

This function is used to set data of any size. Individual indexes are kept for every size class. The first argument is the value, the second one is an optional index number. If it's not set, a new index will be allocated and returned. Same rules apply in using setting's values as with uint SetPointerData(void *data, uint size, int setting = -1);. This function will call LoadData().

const void* GetPointerData(uint setting, uint *sizeReturn = 0);

This used to retrieve a previously set pointer data. The first argument is the setting number. The second optional argument is a pointer to an unsigned int where the size of the data will be returned. This function will call LoadData().

template < class tName >
bool Get(tName& type, uint setting);

This will function is used to return data of any size that has been previously set. The first argument is reference to the variable where the data is to be copied. This variable will also be used to match the sizeof() with the correct data inside CSettings. The second argument is the setting number. This function will call LoadData(). If the the requested setting is found under the index number you specified type will be set to the appropriate value and true will be returned. If the value is not found, type is set to 0 and false is returned.


"The paradox of poverty amongst the paradise of plenty."

Last update: Wednesday, 11th October, 2023
Copyright © 2001-2024 by Lukasz Tomicki