1 /**********************************************************************
2 * File: varable.h (Formerly variable.h)
3 * Description: Class definitions of the *_VAR classes for tunable constants.
4 * Author: Ray Smith
5 * Created: Fri Feb 22 11:26:25 GMT 1991
6 *
7 * (C) Copyright 1991, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #ifndef VARABLE_H
21 #define VARABLE_H
22
23 #include <stdio.h>
24
25 #include "clst.h"
26 #include "strngs.h"
27
28 class DLLSYM INT_VARIABLE;
29
30 // Read config file.
31 extern DLLSYM BOOL8 read_variables_file(
32 const char *file, // filename to read
33 bool global_only); // only set variables starting with "global_"
34
35 // Read variables from the given file pointer (stop at end_offset).
36 bool read_variables_from_fp(FILE *fp, inT64 end_offset, bool global_only);
37
38 // Set a variable to have the given value.
39 bool set_variable(const char *variable, const char* value);
40
41 // Print variables to a file.
42 extern DLLSYM void print_variables(FILE *fp);
43
44 const char kGlobalVariablePrefix[] = "global_";
45
CLISTIZEH(INT_VARIABLE)46 CLISTIZEH (INT_VARIABLE)
47 class DLLSYM INT_VAR_FROM
48 {
49 friend class INT_VAR_TO;
50 public:
51 INT_VAR_FROM(); //constructor
52 private:
53 INT_VARIABLE_CLIST list; //copy of list
54 };
55
56 class DLLSYM INT_VAR_TO
57 {
58 public:
59 INT_VAR_TO(); //constructor
60 private:
61 INT_VARIABLE_CLIST dummy;
62 };
63
64 class DLLSYM INT_VARIABLE
65 {
66 friend class INT_VAR_TO;
67 friend class INT_VAR_FROM;
68 //for setting values
69 friend bool set_variable(const char *variable, const char* value);
70
71 public:
72 INT_VARIABLE(inT32 v, // initial value
73 const char *vname, // name of variable
74 const char *comment); // info on variable
75
INT_VARIABLE()76 INT_VARIABLE() { // for elist only
77 value = 0;
78 name = "NONAME";
79 info = "Uninitialized";
80 }
81 ~INT_VARIABLE(); // for elist only
82
inT32()83 operator inT32() { // conversion
84 return value; // access as int
85 }
86
set_value(inT32 v)87 void set_value(inT32 v) { // value to set
88 value = v;
89 }
90
name_str()91 const char *name_str() { // access name
92 return name;
93 }
94
info_str()95 const char *info_str() { // access name
96 return info;
97 }
98
99 // access list head
100 static INT_VARIABLE_CLIST *get_head();
101
102 static void print(FILE *fp); // file to print on
103
104 private:
105 inT32 value; // the variable
106 const char *name; // name of variable
107 const char *info; // for menus
108 static INT_VAR_FROM copy; // pre constructor
109 // start of list
110 static INT_VARIABLE_CLIST head;
111 static INT_VAR_TO replace; // post constructor
112 };
113
114 class DLLSYM BOOL_VARIABLE;
115
CLISTIZEH(BOOL_VARIABLE)116 CLISTIZEH(BOOL_VARIABLE)
117 class DLLSYM BOOL_VAR_FROM {
118 friend class BOOL_VAR_TO;
119 public:
120 BOOL_VAR_FROM(); // constructor
121 private:
122 BOOL_VARIABLE_CLIST list; // copy of list
123 };
124
125 class DLLSYM BOOL_VAR_TO {
126 public:
127 BOOL_VAR_TO(); // constructor
128 private:
129 BOOL_VARIABLE_CLIST dummy;
130 };
131
132 class DLLSYM BOOL_VARIABLE {
133 friend class BOOL_VAR_FROM;
134 friend class BOOL_VAR_TO;
135 //for setting values
136 friend bool set_variable(const char *variable, const char* value);
137
138 public:
139 BOOL_VARIABLE( //constructor
140 BOOL8 v, //initial value
141 const char *vname, //name of variable
142 const char *comment); //info on variable
143
BOOL_VARIABLE()144 BOOL_VARIABLE() { //for elist only
145 value = FALSE;
146 name = "NONAME";
147 info = "Uninitialized";
148 }
149 ~BOOL_VARIABLE (); //for elist only
150
BOOL8()151 operator BOOL8() { //conversion
152 return value; //access as int
153 }
154
set_value(BOOL8 v)155 void set_value( //assign to value
156 BOOL8 v) { //value to set
157 value = v;
158 }
159
name_str()160 const char *name_str() { //access name
161 return name;
162 }
163
info_str()164 const char *info_str() { //access name
165 return info;
166 }
167
168 //access list head
169 static BOOL_VARIABLE_CLIST *get_head();
170
171 static void print( //print whole list
172 FILE *fp); //file to print on
173
174 private:
175 BOOL8 value; //the variable
176 const char *name; //name of variable
177 const char *info; //for menus
178 static BOOL_VAR_FROM copy; //pre constructor
179 //start of list
180 static BOOL_VARIABLE_CLIST head;
181 static BOOL_VAR_TO replace; //post constructor
182 };
183
184 class DLLSYM STRING_VARIABLE;
185
CLISTIZEH(STRING_VARIABLE)186 CLISTIZEH (STRING_VARIABLE)
187 class DLLSYM STRING_VAR_FROM
188 {
189 friend class STRING_VAR_TO;
190 public:
191 STRING_VAR_FROM(); //constructor
192 private:
193 STRING_VARIABLE_CLIST list; //copy of list
194 };
195
196 class DLLSYM STRING_VAR_TO
197 {
198 public:
199 STRING_VAR_TO(); //constructor
200 private:
201 STRING_VARIABLE_CLIST dummy;
202 };
203
204 class DLLSYM STRING_VARIABLE
205 {
206 friend class STRING_VAR_TO;
207 friend class STRING_VAR_FROM;
208 //for setting values
209 friend bool set_variable(const char *variable, const char* value);
210
211 public:
212 STRING_VARIABLE( //constructor
213 const char *v, //initial value
214 const char *vname, //name of variable
215 const char *comment); //info on variable
216
STRING_VARIABLE()217 STRING_VARIABLE() { //for elist only
218 name = "NONAME";
219 info = "Uninitialized";
220 }
221 ~STRING_VARIABLE (); //for elist only
222
223 //conversion
224 operator const STRING &() {
225 return value; //access as int
226 }
227
set_value(STRING v)228 void set_value( //assign to value
229 STRING v) { //value to set
230 value = v;
231 }
232
string()233 const char *string() const { //get string
234 return value.string ();
235 }
236
name_str()237 const char *name_str() { //access name
238 return name;
239 }
240
info_str()241 const char *info_str() { //access name
242 return info;
243 }
244
245 //access list head
246 static STRING_VARIABLE_CLIST *get_head();
247
248 static void print( //print whole list
249 FILE *fp); //file to print on
250
251 private:
252 STRING value; //the variable
253 const char *name; //name of variable
254 const char *info; //for menus
255 static STRING_VAR_FROM copy; //pre constructor
256 //start of list
257 static STRING_VARIABLE_CLIST head;
258 static STRING_VAR_TO replace;//post constructor
259 };
260
261 class DLLSYM double_VARIABLE;
262
CLISTIZEH(double_VARIABLE)263 CLISTIZEH (double_VARIABLE)
264 class DLLSYM double_VAR_FROM
265 {
266 friend class double_VAR_TO;
267 public:
268 double_VAR_FROM(); //constructor
269 private:
270 double_VARIABLE_CLIST list; //copy of list
271 };
272
273 class DLLSYM double_VAR_TO
274 {
275 public:
276 double_VAR_TO(); //constructor
277 private:
278 double_VARIABLE_CLIST dummy;
279 };
280
281 class DLLSYM double_VARIABLE
282 {
283 friend class double_VAR_TO;
284 friend class double_VAR_FROM;
285 //for setting values
286 friend bool set_variable(const char *variable, const char* value);
287
288 public:
289 double_VARIABLE( //constructor
290 double v, //initial value
291 const char *vname, //name of variable
292 const char *comment); //info on variable
293
double_VARIABLE()294 double_VARIABLE() { //for elist only
295 value = 0.0;
296 name = "NONAME";
297 info = "Uninitialized";
298 }
299 ~double_VARIABLE (); //for elist only
300
301 operator double() { //conversion
302 return value; //access as int
303 }
304
set_value(double v)305 void set_value( //assign to value
306 double v) { //value to set
307 value = v;
308 }
309
name_str()310 const char *name_str() { //access name
311 return name;
312 }
313
info_str()314 const char *info_str() { //access name
315 return info;
316 }
317
318 //access list head
319 static double_VARIABLE_CLIST *get_head();
320
321 static void print( //print whole list
322 FILE *fp); //file to print on
323
324 private:
325 double value; //the variable
326 const char *name; //name of variable
327 const char *info; //for menus
328 static double_VAR_FROM copy; //pre constructor
329 //start of list
330 static double_VARIABLE_CLIST head;
331 static double_VAR_TO replace;//post constructor
332 };
333
334 /*************************************************************************
335 * NOTE ON DEFINING VARIABLES
336 *
337 * For our normal code, the ***_VAR and ***_EVAR macros for variable
338 * definitions are identical. HOWEVER, for the code version to ship to NEVADA
339 * (or anywhere else where we want to hide the majority of variables) the
340 * **_VAR macros are changed so that the "#name" and "comment" parameters
341 * to the variable constructor are changed to empty strings. This prevents the
342 * variable name or comment string appearing in the object code file (after it
343 * has gone through strip).
344 *
345 * Certain variables can remain EXPOSED and hence be used in config files given
346 * to UNLV. These are variable which have been declared with the ***_EVAR
347 * macros.
348 *
349 *************************************************************************/
350
351 /* SECURE_NAMES is defined in senames.h when necessary */
352 #ifdef SECURE_NAMES
353
354 #define INT_VAR(name,val,comment) /*make INT_VARIABLE*/\
355 INT_VARIABLE name(val,"","")
356
357 #define BOOL_VAR(name,val,comment) /*make BOOL_VARIABLE*/\
358 BOOL_VARIABLE name(val,"","")
359
360 #define STRING_VAR(name,val,comment) /*make STRING_VARIABLE*/\
361 STRING_VARIABLE name(val,"","")
362
363 #define double_VAR(name,val,comment) /*make double_VARIABLE*/\
364 double_VARIABLE name(val,"","")
365
366 #else
367
368 #define INT_VAR(name,val,comment) /*make INT_VARIABLE*/\
369 INT_VARIABLE name(val,#name,comment)
370
371 #define BOOL_VAR(name,val,comment) /*make BOOL_VARIABLE*/\
372 BOOL_VARIABLE name(val,#name,comment)
373
374 #define STRING_VAR(name,val,comment) /*make STRING_VARIABLE*/\
375 STRING_VARIABLE name(val,#name,comment)
376
377 #define double_VAR(name,val,comment) /*make double_VARIABLE*/\
378 double_VARIABLE name(val,#name,comment)
379 #endif
380
381 #define INT_VAR_H(name,val,comment) /*declare one*/\
382 INT_VARIABLE name
383
384 #define BOOL_VAR_H(name,val,comment) /*declare one*/\
385 BOOL_VARIABLE name
386
387 #define STRING_VAR_H(name,val,comment) /*declare one*/\
388 STRING_VARIABLE name
389
390 #define double_VAR_H(name,val,comment) /*declare one*/\
391 double_VARIABLE name
392
393 #define INT_MEMBER(name, val, comment) /*make INT_VARIABLE*/\
394 name(val, #name, comment)
395
396 #define BOOL_MEMBER(name, val, comment) /*make BOOL_VARIABLE*/\
397 name(val, #name, comment)
398
399 #define STRING_MEMBER(name, val, comment) /*make STRING_VARIABLE*/\
400 name(val, #name, comment)
401
402 #define double_MEMBER(name, val, comment) /*make double_VARIABLE*/\
403 name(val, #name, comment)
404
405 #define INT_EVAR(name,val,comment) /*make INT_VARIABLE*/\
406 INT_VARIABLE name(val,#name,comment)
407
408 #define INT_EVAR_H(name,val,comment) /*declare one*/\
409 INT_VARIABLE name
410
411 #define BOOL_EVAR(name,val,comment) /*make BOOL_VARIABLE*/\
412 BOOL_VARIABLE name(val,#name,comment)
413
414 #define BOOL_EVAR_H(name,val,comment) /*declare one*/\
415 BOOL_VARIABLE name
416
417 #define STRING_EVAR(name,val,comment) /*make STRING_VARIABLE*/\
418 STRING_VARIABLE name(val,#name,comment)
419
420 #define STRING_EVAR_H(name,val,comment) /*declare one*/\
421 STRING_VARIABLE name
422
423 #define double_EVAR(name,val,comment) /*make double_VARIABLE*/\
424 double_VARIABLE name(val,#name,comment)
425
426 #define double_EVAR_H(name,val,comment) /*declare one*/\
427 double_VARIABLE name
428 #endif
429