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