Preferences Class Reference

List of all members.

Public Types

enum  Root { SYSTEM, USER }

Public Member Functions

 Preferences (Root root, const char *vendor, const char *application)
 Preferences (const char *path, const char *vendor, const char *application)
 Preferences (Preferences &, const char *group)
 Preferences (Preferences *, const char *group)
 ~Preferences ()
int groups ()
const char * group (int)
bool groupExists (const char *group)
bool deleteGroup (const char *group)
int entries ()
const char * entry (int)
bool entryExists (const char *entry)
bool deleteEntry (const char *entry)
bool set (const char *entry, int value)
bool set (const char *entry, float value)
bool set (const char *entry, double value)
bool set (const char *entry, const char *value)
bool set (const char *entry, const void *value, int size)
bool get (const char *entry, int &value, int defaultValue)
bool get (const char *entry, float &value, float defaultValue)
bool get (const char *entry, double &value, double defaultValue)
bool get (const char *entry, char *&value, const char *defaultValue)
bool get (const char *entry, char *value, const char *defaultValue, int maxSize)
bool get (const char *entry, void *&value, const void *defaultValue, int defaultSize)
bool get (const char *entry, void *value, const void *defaultValue, int defaultSize, int maxSize)
int size (const char *entry)
bool getUserdataPath (char *path, int pathlen)
void flush ()

Friends

class Node
class RootNode

Detailed Description

Preferences are a data tree containing a root, branches and leafs


Constructor & Destructor Documentation

Preferences::Preferences Root  root,
const char *  vendor,
const char *  application
 

create the initial preferences base

  • root: machine or user preferences
  • vendor: unique identification of author or vendor of application Must be a valid directory name.
  • application: vendor unique application name, i.e. "PreferencesTest" multiple preferences files can be created per application. Must be a valid file name. example: Preferences base( Preferences::USER, "fltk.org", "test01");

Preferences::Preferences const char *  path,
const char *  vendor,
const char *  application
 

create the initial preferences base

  • path: an application-supplied path example: Preferences base( "/usr/foo" );

Preferences::Preferences Preferences parent,
const char *  key
 

create a Preferences node in relation to a parent node for reading and writing

  • parent: base name for group
  • group: group name (can contain '/' seperated group names) example: Preferences colors( base, "setup/colors" );

Preferences::Preferences Preferences parent,
const char *  key
 

create a Preferences node in relation to a parent node for reading and writing

  • parent: base name for group
  • group: group name (can contain '/' seperated group names) example: Preferences colors( base, "setup/colors" );

Preferences::~Preferences  ) 
 

destroy individual keys

  • destroying the base preferences will flush changes to the prefs file
  • after destroying the base, none of the depending preferences must be read or written


Member Function Documentation

bool Preferences::deleteEntry const char *  key  ) 
 

remove a single entry (name/value pair) example: buttonColor.deleteEntry( "red" );

bool Preferences::deleteGroup const char *  key  ) 
 

delete a group example: setup.deleteGroup( "colors/buttons" );

int Preferences::entries  ) 
 

return the number of entries (name/value) pairs for a group example: int n = buttonColor.entries();

const char * Preferences::entry int  ix  ) 
 

return the name of an entry

  • there is no guaranteed order of entry names
  • the index must be within the range given by entries() example: printf( "Entry(%d)='%s'\n", ix, buttonColor.entry(ix) );

bool Preferences::entryExists const char *  key  ) 
 

return 1, if an entry with this name exists example: if ( buttonColor.entryExists( "red" ) ) ...

void Preferences::flush  ) 
 

write all preferences to disk

  • this function works only with the base preference group
  • this function is rarely used as deleting the base preferences flushes automatically

bool Preferences::get const char *  key,
void *  data,
const void *  defaultValue,
int  defaultSize,
int  maxSize
 

read a binary entry from the group the data will be moved into the given destination buffer data will be clipped to the buffer size

bool Preferences::get const char *  key,
void *&  data,
const void *  defaultValue,
int  defaultSize
 

read a binary entry from the group 'data' will be changed to point to a new data buffer the data buffer must be deleted with "delete[] (char*)data" by the user.

bool Preferences::get const char *  key,
char *  text,
const char *  defaultValue,
int  maxSize
 

read a text entry from the group the text will be moved into the given text buffer text will be clipped to the buffer size

bool Preferences::get const char *  key,
char *&  text,
const char *  defaultValue
 

read a text entry from the group 'text' will be changed to point to a new text buffer the text buffer must be freed with "delete[] text" by the user.

bool Preferences::get const char *  key,
double &  value,
double  defaultValue
 

read an entry from the group

bool Preferences::get const char *  key,
float &  value,
float  defaultValue
 

read an entry from the group

bool Preferences::get const char *  key,
int &  value,
int  defaultValue
 

read an entry from the group

bool Preferences::getUserdataPath char *  path,
int  pathlen
 

creates a path that is related to the preferences file and that is usable for application data beyond what is covered by Preferences.

  • 'getUserdataPath' actually creates the directory
  • 'path' must be large enough to receive a complete file path example: Preferences prefs( USER, "matthiasm.com", "test" ); char path[PATH_MAX]; prefs.getUserdataPath( path ); sample returns: Win32: c:/Documents and Settings/matt/Application Data/matthiasm.com/test/ prefs: c:/Documents and Settings/matt/Application Data/matthiasm.com/test.prefs

const char * Preferences::group int  ix  ) 
 

return the group name of the n'th group

  • there is no guaranteed order of group names
  • the index must be within the range given by groups() example: printf( "Group(%d)='%s'\n", ix, base.group(ix) );

bool Preferences::groupExists const char *  key  ) 
 

return 1, if a group with this name exists example: if ( base.groupExists( "setup/colors" ) ) ...

int Preferences::groups  ) 
 

return the number of groups that are contained within a group example: int n = base.groups();

bool Preferences::set const char *  key,
const void *  data,
int  dsize
 

set an entry (name/value pair)

bool Preferences::set const char *  key,
const char *  text
 

set an entry (name/value pair)

bool Preferences::set const char *  key,
double  value
 

set an entry (name/value pair)

bool Preferences::set const char *  key,
float  value
 

set an entry (name/value pair)

bool Preferences::set const char *  key,
int  value
 

set an entry (name/value pair)

int Preferences::size const char *  key  ) 
 

return the size of the value part of an entry


The documentation for this class was generated from the following files:
Sun Jan 7 00:55:18 2007. FLTK ©2006 Bill Spitzak and others.
Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.