split tunable constant into Boolean and Float sub-classes.
[dyninst.git] / common / src / tunableConst.C
1 /*
2  * tunableConst - a system parameter that we might one to change during 
3  *    execution of the system.
4  *
5  * $Log: tunableConst.C,v $
6  * Revision 1.3  1994/08/03 18:37:39  hollings
7  * split tunable constant into Boolean and Float sub-classes.
8  *
9  * Revision 1.2  1994/02/28  23:58:38  hollings
10  * Changed global list to be a pointer to a list because I couldn't rely on
11  * the order of global constructors.
12  *
13  * Revision 1.1  1994/02/25  00:26:17  hollings
14  * added tuntable constants
15  *
16  *
17  */
18
19 #include "util/h/stringPool.h"
20 #include "util/h/tunableConst.h"
21
22 List<tunableConstant*> *tunableConstant::allConstants;
23 stringPool *tunableConstant::pool;
24
25 tunableBooleanConstant::tunableBooleanConstant(Boolean initialValue,
26                                                booleanChangeValCallBackFunc cb,
27                                                tunableUse u,
28                                                char *n,
29                                                char *d)
30 {
31     value = initialValue;
32     desc = d;
33     use = u;
34     typeName = tunableBoolean;
35
36     if (!pool) pool = new(stringPool);
37     name = pool->findAndAdd(n);
38     newValueCallBack = cb;
39     if (!allConstants) allConstants = new(List<tunableConstant*>);
40     allConstants->add(this, name);
41 }
42
43 void tunableBooleanConstant::print()
44 {
45    cout << name << " = ";
46    if (value == TRUE) {
47        cout << "True\n";
48    } else {
49        cout << "False\n";
50    }
51 }
52
53 Boolean tunableFloatConstant::simpleRangeCheck(float val)
54 {
55     return((val >= min) && (val <= max));
56 }
57
58 tunableFloatConstant::tunableFloatConstant(float initialValue, 
59                                          float low, 
60                                          float high, 
61                                          floatChangeValCallBackFunc cb,
62                                          tunableUse u,
63                                          char *n,
64                                          char *d)
65
66 {
67     value = initialValue;
68     min = low;
69     max = high;
70     desc = d;
71     use = u;
72     typeName = tunableFloat;
73     newValueCallBack = cb;
74
75     if (!pool) pool = new(stringPool);
76     name = pool->findAndAdd(n);
77     if (!allConstants) allConstants = new(List<tunableConstant*>);
78     allConstants->add(this, name);
79 }
80
81 tunableFloatConstant::tunableFloatConstant(float initialValue, 
82                                            isValidFunc func, 
83                                            floatChangeValCallBackFunc cb,
84                                            tunableUse u,
85                                            char *n,
86                                            char *d)
87 {
88     desc = d;
89     use = u;
90     typeName = tunableFloat;
91     isValidValue = func;
92     value = initialValue;
93     newValueCallBack = cb;
94
95     if (!pool) pool = new(stringPool);
96     name = pool->findAndAdd(n);
97     if (!allConstants) allConstants = new(List<tunableConstant*>);
98     allConstants->add(this, name);
99 }
100
101 void tunableFloatConstant::print()
102 {
103     cout << name << " = " << value << "\n";
104 }