split tunable constant into Boolean and Float sub-classes.
[dyninst.git] / pdutil / h / tunableConst.h
1 /*
2  * tunableConstant - a constant that might be changed during execution.
3  *
4  * $Log: tunableConst.h,v $
5  * Revision 1.3  1994/08/03 18:37:30  hollings
6  * split tunable constant into Boolean and Float sub-classes.
7  *
8  * Revision 1.2  1994/02/28  23:58:28  hollings
9  * Changed global list to be a pointer to a list because I couldn't rely on
10  * the order of global constructors.
11  *
12  * Revision 1.1  1994/02/25  00:25:58  hollings
13  * added tunable constants.
14  *
15  *
16  */
17 #ifndef TUNABLE_CONST_H
18 #define TUNABLE_CONST_H
19
20 #include "util/h/stringPool.h"
21 #include "util/h/list.h"
22
23 typedef enum tunableUse { developerConstant, userConstant };
24 typedef enum tunableType { tunableBoolean, tunableFloat };
25
26 //
27 // Note: this is an abstract class, and can NOT be directly created.
28 //
29 class tunableConstant {
30     public:
31         char *getDesc() { return(desc); }
32         char *getName() { return(name); }
33         static List<tunableConstant*> *allConstants;
34         static stringPool *pool;
35         virtual void print() = NULL;
36         tunableType getType() { return(typeName); }
37     protected:
38         char *desc;
39         char *name;
40         tunableType typeName;
41         tunableUse use;
42 };
43
44 typedef Boolean (*isValidFunc)(float newVale);
45 typedef void (*booleanChangeValCallBackFunc)(Boolean value);
46 typedef void (*floatChangeValCallBackFunc)(float value);
47
48 class tunableBooleanConstant: public tunableConstant {
49     public:
50         tunableBooleanConstant(Boolean initialValue, 
51                                booleanChangeValCallBackFunc cb,
52                                tunableUse type,
53                                char *name,
54                                char *desc);
55         Boolean getValue() { return value; }
56         Boolean setValue(Boolean newVal) {
57             value = newVal;
58         }
59         virtual void print();
60     private:
61         Boolean value;
62         booleanChangeValCallBackFunc newValueCallBack;
63 };
64
65 class tunableFloatConstant: public tunableConstant {
66     public:
67         tunableFloatConstant(float initialValue, 
68                         float min, 
69                         float max, 
70                         floatChangeValCallBackFunc cb,
71                         tunableUse type,
72                         char *name,
73                         char *desc);
74         tunableFloatConstant(float initialValue, 
75                         isValidFunc, 
76                         floatChangeValCallBackFunc cb,
77                         tunableUse type,
78                         char *name,
79                         char *desc);
80         float getValue() { return value; }
81         Boolean setValue(float newVal) {
82             if ((isValidValue) && isValidValue(newVal)) {
83                 value = newVal;
84                 if (newValueCallBack) newValueCallBack(newVal);
85                 return(TRUE);
86             } else if (simpleRangeCheck(newVal)) {
87                 value = newVal;
88                 if (newValueCallBack) newValueCallBack(newVal);
89                 return(TRUE);
90             } else {
91                 return(FALSE);
92             }
93         }
94         virtual void print();
95     private:
96         float value;
97         float min, max;
98         isValidFunc isValidValue;
99         Boolean simpleRangeCheck(float val);
100         floatChangeValCallBackFunc newValueCallBack;
101 };
102
103 #endif