Move the sources to trunk
[opencv] / otherlibs / _fltk / include / FL / Fl_Preferences.H
1 //
2 // "$Id: Fl_Preferences.H,v 1.1 2002/12/01 15:38:37 neurosurg Exp $"
3 //
4 // Preferences definitions for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 2002 by Matthias Melcher.
7 //
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.
12 //
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.
17 //
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
21 // USA.
22 //
23 // Please report all bugs and problems to "fltk-bugs@fltk.org".
24 //
25
26 #ifndef Fl_Preferences_H
27 #  define Fl_Preferences_H
28
29 #  ifdef WIN32
30 #    include <windows.h>
31 #  endif // WIN32
32
33 #  include <stdio.h>
34 #  include "Fl_Export.H"
35
36
37 /**
38  * Preferences are a data tree containing a root, branches and leafs
39  */
40 class FL_EXPORT Fl_Preferences 
41 {
42
43 public:
44
45   enum Root { SYSTEM=0, USER };
46   // enum Type { win32, macos, fltk };
47
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 );
52   ~Fl_Preferences();
53
54   int groups();
55   const char *group( int );
56   char groupExists( const char *group );
57   char deleteGroup( const char *group );
58
59   int entries();
60   const char *entry( int );
61   char entryExists( const char *entry );
62   char deleteEntry( const char *entry );
63
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 ); 
69
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 );
78
79   char getUserdataPath( char *path, int pathlen );
80
81   void flush();
82
83   // char export( const char *filename, Type fileFormat );
84   // char import( const char *filename );
85
86   class Name {
87     char *data_;
88   public:
89     Name( unsigned int n );
90     Name( const char *format, ... );
91     operator const char *() { return data_; }
92     ~Name();
93   };
94
95   struct Entry
96   {
97     char *name, *value;
98   };
99
100 private:
101
102   static char nameBuffer[128];
103
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_;
107     char *path_;
108     char dirty_;
109   public:
110     Node( const char *path );
111     ~Node();
112     // node methods
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 );
118     char remove();
119     char dirty();
120     // entry methods
121     int nChildren();
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 );
129     // public values
130     Entry *entry;
131     int nEntry, NEntry;
132     static int lastEntrySet;
133   };
134   friend class Node;
135
136   class RootNode  // the root node manages file paths and basic reading and writing
137   {
138     Fl_Preferences *prefs_;
139     char *filename_;
140     char *vendor_, *application_;
141   public:
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 );
144     ~RootNode();
145     int read();
146     int write();
147     char getPath( char *path, int pathlen );
148   };
149   friend class RootNode;
150
151   Node *node;
152   RootNode *rootNode;
153   
154 };
155
156
157 #endif // !Fl_Preferences_H
158
159 //
160 // End of "$Id: Fl_Preferences.H,v 1.1 2002/12/01 15:38:37 neurosurg Exp $".
161 //