00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef Fl_Preferences_H
00023 # define Fl_Preferences_H
00024
00025 # include <stdio.h>
00026 # include "Fl_Export.H"
00027
00060 class FL_EXPORT Fl_Preferences {
00061
00062 public:
00066 enum Root {
00067 SYSTEM=0,
00068 USER
00069 };
00070
00078 typedef void *ID;
00079
00080 static const char *newUUID();
00081
00082 Fl_Preferences( Root root, const char *vendor, const char *application );
00083 Fl_Preferences( const char *path, const char *vendor, const char *application );
00084 Fl_Preferences( Fl_Preferences &parent, const char *group );
00085 Fl_Preferences( Fl_Preferences *parent, const char *group );
00086 Fl_Preferences( Fl_Preferences &parent, int groupIndex );
00087 Fl_Preferences( Fl_Preferences *parent, int groupIndex );
00088 Fl_Preferences(const Fl_Preferences&);
00089 Fl_Preferences( ID id );
00090 virtual ~Fl_Preferences();
00091
00094 ID id() { return (ID)node; }
00095
00098 static char remove(ID id_) { return ((Node*)id_)->remove(); }
00099
00102 const char *name() { return node->name(); }
00103
00106 const char *path() { return node->path(); }
00107
00108 int groups();
00109 const char *group( int num_group );
00110 char groupExists( const char *key );
00111 char deleteGroup( const char *group );
00112 char deleteAllGroups();
00113
00114 int entries();
00115 const char *entry( int index );
00116 char entryExists( const char *key );
00117 char deleteEntry( const char *entry );
00118 char deleteAllEntries();
00119
00120 char clear();
00121
00122 char set( const char *entry, int value );
00123 char set( const char *entry, float value );
00124 char set( const char *entry, float value, int precision );
00125 char set( const char *entry, double value );
00126 char set( const char *entry, double value, int precision );
00127 char set( const char *entry, const char *value );
00128 char set( const char *entry, const void *value, int size );
00129
00130 char get( const char *entry, int &value, int defaultValue );
00131 char get( const char *entry, float &value, float defaultValue );
00132 char get( const char *entry, double &value, double defaultValue );
00133 char get( const char *entry, char *&value, const char *defaultValue );
00134 char get( const char *entry, char *value, const char *defaultValue, int maxSize );
00135 char get( const char *entry, void *&value, const void *defaultValue, int defaultSize );
00136 char get( const char *entry, void *value, const void *defaultValue, int defaultSize, int maxSize );
00137
00138 int size( const char *entry );
00139
00140 char getUserdataPath( char *path, int pathlen );
00141
00142 void flush();
00143
00144
00145
00146
00159 class FL_EXPORT Name {
00160
00161 char *data_;
00162
00163 public:
00164 Name( unsigned int n );
00165 Name( const char *format, ... );
00166
00171 operator const char *() { return data_; }
00172 ~Name();
00173 };
00174
00176 struct Entry {
00177 char *name, *value;
00178 };
00179
00180 private:
00181 Fl_Preferences() : node(0), rootNode(0) { }
00182 Fl_Preferences &operator=(const Fl_Preferences&);
00183
00184 static char nameBuffer[128];
00185 static char uuidBuffer[40];
00186 static Fl_Preferences *runtimePrefs;
00187
00188 public:
00189 class RootNode;
00190
00191 class FL_EXPORT Node {
00192
00193 Node *child_, *next_;
00194 union {
00195 Node *parent_;
00196 RootNode *root_;
00197 };
00198 char *path_;
00199 Entry *entry_;
00200 int nEntry_, NEntry_;
00201 unsigned char dirty_:1;
00202 unsigned char top_:1;
00203 unsigned char indexed_:1;
00204
00205 Node **index_;
00206 int nIndex_, NIndex_;
00207 void createIndex();
00208 void updateIndex();
00209 void deleteIndex();
00210 public:
00211 static int lastEntrySet;
00212 public:
00213 Node( const char *path );
00214 ~Node();
00215
00216 int write( FILE *f );
00217 const char *name();
00218 const char *path() { return path_; }
00219 Node *find( const char *path );
00220 Node *search( const char *path, int offset=0 );
00221 Node *childNode( int ix );
00222 Node *addChild( const char *path );
00223 void setParent( Node *parent );
00224 Node *parent() { return top_?0L:parent_; }
00225 void setRoot(RootNode *r) { root_ = r; top_ = 1; }
00226 RootNode *findRoot();
00227 char remove();
00228 char dirty();
00229 void deleteAllChildren();
00230
00231 int nChildren();
00232 const char *child( int ix );
00233 void set( const char *name, const char *value );
00234 void set( const char *line );
00235 void add( const char *line );
00236 const char *get( const char *name );
00237 int getEntry( const char *name );
00238 char deleteEntry( const char *name );
00239 void deleteAllEntries();
00240 int nEntry() { return nEntry_; }
00241 Entry &entry(int i) { return entry_[i]; }
00242 };
00243 friend class Node;
00244
00245 class FL_EXPORT RootNode {
00246 Fl_Preferences *prefs_;
00247 char *filename_;
00248 char *vendor_, *application_;
00249 public:
00250 RootNode( Fl_Preferences *, Root root, const char *vendor, const char *application );
00251 RootNode( Fl_Preferences *, const char *path, const char *vendor, const char *application );
00252 RootNode( Fl_Preferences * );
00253 ~RootNode();
00254 int read();
00255 int write();
00256 char getPath( char *path, int pathlen );
00257 };
00258 friend class RootNode;
00259
00260 protected:
00261 Node *node;
00262 RootNode *rootNode;
00263 };
00264
00265 #endif // !Fl_Preferences_H
00266
00267
00268
00269