2 // "$Id: Fl_Preferences.H,v 1.1 2002/12/01 15:38:37 neurosurg Exp $"
4 // Preferences definitions for the Fast Light Tool Kit (FLTK).
6 // Copyright 2002 by Matthias Melcher.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems to "fltk-bugs@fltk.org".
26 #ifndef Fl_Preferences_H
27 # define Fl_Preferences_H
34 # include "Fl_Export.H"
38 * Preferences are a data tree containing a root, branches and leafs
40 class FL_EXPORT Fl_Preferences
45 enum Root { SYSTEM=0, USER };
46 // enum Type { win32, macos, fltk };
48 Fl_Preferences( Root root, const char *vendor, const char *application );
49 Fl_Preferences( const char *path, const char *vendor, const char *application );
50 Fl_Preferences( Fl_Preferences&, const char *group );
51 Fl_Preferences( Fl_Preferences*, const char *group );
55 const char *group( int );
56 char groupExists( const char *group );
57 char deleteGroup( const char *group );
60 const char *entry( int );
61 char entryExists( const char *entry );
62 char deleteEntry( const char *entry );
64 char set( const char *entry, int value );
65 char set( const char *entry, float value );
66 char set( const char *entry, double value );
67 char set( const char *entry, const char *value );
68 char set( const char *entry, const void *value, int size );
70 char get( const char *entry, int &value, int defaultValue );
71 char get( const char *entry, float &value, float defaultValue );
72 char get( const char *entry, double &value, double defaultValue );
73 char get( const char *entry, char *&value, const char *defaultValue );
74 char get( const char *entry, char *value, const char *defaultValue, int maxSize );
75 char get( const char *entry, void *&value, const void *defaultValue, int defaultSize );
76 char get( const char *entry, void *value, const void *defaultValue, int defaultSize, int maxSize );
77 int size( const char *entry );
79 char getUserdataPath( char *path, int pathlen );
83 // char export( const char *filename, Type fileFormat );
84 // char import( const char *filename );
89 Name( unsigned int n );
90 Name( const char *format, ... );
91 operator const char *() { return data_; }
102 static char nameBuffer[128];
104 class Node // a node contains a list to all its entries
105 { // and all means to manage the tree structure
106 Node *child_, *next_, *parent_;
110 Node( const char *path );
113 int write( FILE *f );
114 Node *find( const char *path );
115 Node *search( const char *path, int offset=0 );
116 Node *addChild( const char *path );
117 void setParent( Node *parent );
122 const char *child( int ix );
123 void set( const char *name, const char *value );
124 void set( const char *line );
125 void add( const char *line );
126 const char *get( const char *name );
127 int getEntry( const char *name );
128 char deleteEntry( const char *name );
132 static int lastEntrySet;
136 class RootNode // the root node manages file paths and basic reading and writing
138 Fl_Preferences *prefs_;
140 char *vendor_, *application_;
142 RootNode( Fl_Preferences *, Root root, const char *vendor, const char *application );
143 RootNode( Fl_Preferences *, const char *path, const char *vendor, const char *application );
147 char getPath( char *path, int pathlen );
149 friend class RootNode;
157 #endif // !Fl_Preferences_H
160 // End of "$Id: Fl_Preferences.H,v 1.1 2002/12/01 15:38:37 neurosurg Exp $".