1 /*****************************************************************************/
2 /* */
3 /* SETTINGS.H */
4 /* */
5 /* (C) 1993-96 Ullrich von Bassewitz */
6 /* Zwehrenbuehlstrasse 33 */
7 /* D-72070 Tuebingen */
8 /* EMail: uz@ibb.schwaben.com */
9 /* */
10 /*****************************************************************************/
11
12
13
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19
20
21
22 #ifndef __SETTINGS_H
23 #define __SETTINGS_H
24
25
26
27 // This module declares functions to work with program options (settings).
28 // Settings are stored in a class derived from class ResourceFile that is
29 // used internally. The external interface is a procedural one - this allows
30 // the functions to check for a non existing or not open settings resource.
31 // A not existing file is transparent to the programmer, the functions behave
32 // as if the key did not exist (when calling StgGet...) and ignore the data
33 // (when calling StgPut).
34
35
36
37 #include "rect.h"
38 #include "str.h"
39
40
41
42 /*****************************************************************************/
43 /* Code */
44 /*****************************************************************************/
45
46
47
48 unsigned StgOpen (const String& Filename, int FlushAlways = 1);
49 // Filename is expanded (made absolute) and the function tries to open a
50 // settings database with this name. If the database does not exist, a new
51 // one is created. A ResourceFile error code is returned (which is zero if
52 // no error occured). If there is an error, the database is deleted and all
53 /// other functions just ignore the data as explained above.
54 // If FlushAlways is set != zero, the settings file is flushed after every
55 // write to prevent the file from becoming corrupted in case of a program
56 // crash.
57
58 void StgClose ();
59 // Close the settings database
60
61 int StgEmpty ();
62 // Return true if the settings file is empty, that is, it does not contain
63 // any resources
64
65 void StgFlush ();
66 // Flush the settings database to disk
67
68 Streamable* StgGet (const String& Name);
69 // Read an object from the settings database, returns NULL if the key was not
70 // found or the database does not exist.
71
72 Point StgGetPoint (const String& Name, const Point& Default);
73 // Return a point (position) or the default if there is no matching
74 // key in the resource.
75
76 Point StgGetPoint (const String& Name, int XDef, int YDef);
77 // Return a point (position) or the default if there is no matching
78 // key in the resource.
79
80 Rect StgGetRect (const String& Name, const Rect& Default);
81 // Return a rect or the default if there is no matching key
82 // in the resource.
83
84 String StgGetString (const String& Name, const String& Default);
85 // Return a String or the default if there is no matching key in the
86 // resource.
87
88 void StgPut (const Streamable* Obj, const String& Name);
89 // Put an object into the settings database
90
StgPut(const Streamable & Obj,const String & Name)91 inline void StgPut (const Streamable& Obj, const String& Name)
92 // Put an object into the settings database
93 {
94 StgPut (&Obj, Name);
95 }
96
97 void StgPutPoint (const Point& P, const String& Name);
98 // Write a Point object into the settings database
99
100 void StgPutRect (const Rect& R, const String& Name);
101 // Write a Rect object into the settings database
102
StgPutString(const String & S,const String & Name)103 inline void StgPutString (const String& S, const String& Name)
104 // Write a String object into the settings database
105 {
106 StgPut (S, Name);
107 }
108
109
110
111 // End of SETTINGS.H
112
113 #endif
114
115