summaryrefslogtreecommitdiff
path: root/FL/Fl_Preferences.H
blob: 5f2b1d7efaf30c2aa5ff1ffa46a37a388f04c66f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// "$Id: Fl_Preferences.H,v 1.1.2.8 2002/05/31 19:27:56 easysw Exp $"
//
// Preferences definitions for the Fast Light Tool Kit (FLTK).
//
// Copyright 2002 by Matthias Melcher.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//

#ifndef Fl_Preferences_H
#  define Fl_Preferences_H

#  ifdef WIN32
#    include <windows.h>
#  endif // WIN32

#include <stdio.h>



/**
 * Preferences are a data tree containing a root, branches and leafs
 */
class Fl_Preferences 
{

public:

  enum Root { SYSTEM=0, USER };
  // enum Type { win32, macos, fltk };

  FL_EXPORT Fl_Preferences( Root root, const char *vendor, const char *application );
  FL_EXPORT Fl_Preferences( Fl_Preferences&, const char *group );
  FL_EXPORT Fl_Preferences( Fl_Preferences*, const char *group );
  FL_EXPORT ~Fl_Preferences();

  FL_EXPORT int groups();
  FL_EXPORT const char *group( int );
  FL_EXPORT char groupExists( const char *group );
  FL_EXPORT char deleteGroup( const char *group );

  FL_EXPORT int entries();
  FL_EXPORT const char *entry( int );
  FL_EXPORT char entryExists( const char *entry );
  FL_EXPORT char deleteEntry( const char *entry );

  FL_EXPORT char set( const char *entry, int value );
  FL_EXPORT char set( const char *entry, float value );
  FL_EXPORT char set( const char *entry, double value );
  FL_EXPORT char set( const char *entry, const char *value );
  FL_EXPORT char set( const char *entry, const void *value, int size ); 

  FL_EXPORT char get( const char *entry, int &value,    int defaultValue );
  FL_EXPORT char get( const char *entry, float &value,  float defaultValue );
  FL_EXPORT char get( const char *entry, double &value, double defaultValue );
  FL_EXPORT char get( const char *entry, char *&value,  const char *defaultValue );
  FL_EXPORT char get( const char *entry, char *value,   const char *defaultValue, int maxSize );
  FL_EXPORT char get( const char *entry, void *&value,  const void *defaultValue, int defaultSize );
  FL_EXPORT char get( const char *entry, void *value,   const void *defaultValue, int defaultSize, int maxSize );
  FL_EXPORT int size( const char *entry );

  FL_EXPORT char getUserdataPath( char *path, int pathlen );

  FL_EXPORT void flush();

  // FL_EXPORT char export( const char *filename, Type fileFormat );
  // FL_EXPORT char import( const char *filename );

  class Name {
    char *data_;
  public:
    FL_EXPORT Name( unsigned int n );
    FL_EXPORT Name( const char *format, ... );
    FL_EXPORT operator const char *() { return data_; }
    FL_EXPORT ~Name();
  };

  struct Entry
  {
    char *name, *value;
  };

private:

  static char nameBuffer[128];

  class Node // a node contains a list to all its entries 
  {          // and all means to manage the tree structure
    Node *child_, *next_, *parent_;
    char *path_;
    char dirty_;
  public:
    Node( const char *path );
    ~Node();
    // node methods
    int write( FILE *f );
    Node *find( const char *path );
    Node *search( const char *path );
    Node *addChild( const char *path );
    void setParent( Node *parent );
    char remove();
    char dirty();
    // 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 );
    // public values
    Entry *entry;
    int nEntry, NEntry;
    static int lastEntrySet;
  };
  friend class Node;

  class 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();
    int read();
    int write();
    char getPath( char *path, int pathlen );
  };
  friend class RootNode;

  Node *node;
  RootNode *rootNode;
  
};


#endif // !Fl_Preferences_H

//
// End of "$Id: Fl_Preferences.H,v 1.1.2.8 2002/05/31 19:27:56 easysw Exp $".
//