Fl_Preferences.H
//
// "$Id: Fl_Preferences.H 9228 2012-01-18 11:39:57Z AlbrechtS $"
//
// Preferences .
//
// Copyright 2002-2010 by Matthias Melcher.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
/* \file
Fl_Preferences class . */
#ifndef Fl_Preferences_H
# define Fl_Preferences_H
# include <stdio.h>
# include "Fl_Export.H"
class FL_EXPORT Fl_Preferences {
public:
enum Root {
SYSTEM=0,
USER
};
typedef void *ID;
static const char *newUUID();
Fl_Preferences( Root root, const char *vendor, const char *application );
Fl_Preferences( const char *path, const char *vendor, const char *application );
Fl_Preferences( Fl_Preferences &parent, const char *group );
Fl_Preferences( Fl_Preferences *parent, const char *group );
Fl_Preferences( Fl_Preferences &parent, int groupIndex );
Fl_Preferences( Fl_Preferences *parent, int groupIndex );
Fl_Preferences(const Fl_Preferences&);
Fl_Preferences( ID id );
virtual ~Fl_Preferences();
ID id() { return (ID)node; }
static char remove(ID id_) { return ((Node*)id_)->remove(); }
const char *name() { return node->name(); }
const char *path() { return node->path(); }
int groups();
const char *group( int num_group );
char groupExists( const char *key );
char deleteGroup( const char *group );
char deleteAllGroups();
int entries();
const char *entry( int index );
char entryExists( const char *key );
char deleteEntry( const char *entry );
char deleteAllEntries();
char clear();
char set( const char *entry, int value );
char set( const char *entry, float value );
char set( const char *entry, float value, int precision );
char set( const char *entry, double value );
char set( const char *entry, double value, int precision );
char set( const char *entry, const char *value );
char set( const char *entry, const void *value, int size );
char get( const char *entry, int &value, int defaultValue );
char get( const char *entry, float &value, float defaultValue );
char get( const char *entry, double &value, double defaultValue );
char get( const char *entry, char *&value, const char *defaultValue );
char get( const char *entry, char *value, const char *defaultValue, int maxSize );
char get( const char *entry, void *&value, const void *defaultValue, int defaultSize );
char get( const char *entry, void *value, const void *defaultValue, int defaultSize, int maxSize );
int size( const char *entry );
char getUserdataPath( char *path, int pathlen );
void flush();
// char export( const char *filename, Type fileFormat );
// char import( const char *filename );
class FL_EXPORT Name {
char *data_;
public:
Name( unsigned int n );
Name( const char *format, ... );
operator const char *() { return data_; }
~Name();
};
struct Entry {
char *name, *value;
};
private:
Fl_Preferences() : node(0), rootNode(0) { }
Fl_Preferences &operator=(const Fl_Preferences&);
static char nameBuffer[128];
static char uuidBuffer[40];
static Fl_Preferences *runtimePrefs;
class RootNode;
class FL_EXPORT Node { // a node contains a list to all its entries
// and all means to manage the tree structure
Node *child_, *next_;
union { // these two are mutually exclusive
Node *parent_; // top_ bit clear
RootNode *root_; // top_ bit set
};
char *path_;
Entry *entry_;
int nEntry_, NEntry_;
unsigned char dirty_:1;
unsigned char top_:1;
unsigned char indexed_:1;
// indexing routines
Node **index_;
int nIndex_, NIndex_;
void createIndex();
void updateIndex();
void deleteIndex();
public:
static int lastEntrySet;
public:
Node( const char *path );
~Node();
// node methods
int write( FILE *f );
const char *name();
const char *path() { return path_; }
Node *find( const char *path );
Node *search( const char *path, int offset=0 );
Node *childNode( int ix );
Node *addChild( const char *path );
void setParent( Node *parent );
Node *parent() { return top_?0L:parent_; }
void setRoot(RootNode *r) { root_ = r; top_ = 1; }
RootNode *findRoot();
char remove();
char dirty();
void deleteAllChildren();
// entry methods
int nChildren();
const char *child( int ix );
void set( const char *name, const char *value );
void set( const char *line );
void add( const char *line );
const char *get( const char *name );
int getEntry( const char *name );
char deleteEntry( const char *name );
void deleteAllEntries();
int nEntry() { return nEntry_; }
Entry &entry(int i) { return entry_[i]; }
};
friend class Node;
class FL_EXPORT RootNode { // the root node manages file paths and basic reading and writing
Fl_Preferences *prefs_;
char *filename_;
char *vendor_, *application_;
public:
RootNode( Fl_Preferences *, Root root, const char *vendor, const char *application );
RootNode( Fl_Preferences *, const char *path, const char *vendor, const char *application );
RootNode( Fl_Preferences * );
~RootNode();
int read();
int write();
char getPath( char *path, int pathlen );
};
friend class RootNode;
protected:
Node *node;
RootNode *rootNode;
};
#endif // !Fl_Preferences_H
//
// End of "$Id: Fl_Preferences.H 9228 2012-01-18 11:39:57Z AlbrechtS $".
//
- © 1998-2012 by Bill Spitzak and others.