tunableConst.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef TUNABLE_CONST_H
00076 #define TUNABLE_CONST_H
00077
00078 #include <assert.h>
00079 #include "util/h/stringPool.h"
00080 #include "util/h/list.h"
00081
00082 typedef enum tunableUse { developerConstant, userConstant };
00083 typedef enum tunableType { tunableBoolean, tunableFloat };
00084
00085
00086
00087
00088 class tunableConstant {
00089 protected:
00090 char *desc;
00091 char *name;
00092 tunableType typeName;
00093 tunableUse use;
00094
00095 static stringPool *pool;
00096
00097 static List<tunableConstant*> *allConstants;
00098
00099 public:
00100 tunableConstant() {}
00101 virtual ~tunableConstant() {}
00102
00103 const char *getDesc() const {
00104 return desc;
00105 }
00106 const char *getName() const {
00107 return name;
00108 }
00109 tunableUse getUse() const {
00110 return use;
00111 }
00112 tunableType getType() const {
00113 return typeName;
00114 }
00115
00116 static tunableConstant *findTunableConstant(const char *name);
00117
00118
00119 static List<tunableConstant *> beginIteration() {
00120 assert(allConstants);
00121
00122 List <tunableConstant *> iterList = *allConstants;
00123
00124
00125
00126
00127 return iterList;
00128 }
00129
00130 static int numTunables() {
00131 assert(allConstants);
00132 return allConstants->count();
00133 }
00134
00135 virtual void print() = NULL;
00136 };
00137
00138
00139
00140
00141 typedef bool (*isValidFunc)(float newVal);
00142 typedef void (*booleanChangeValCallBackFunc)(bool value);
00143 typedef void (*floatChangeValCallBackFunc)(float value);
00144
00145 class tunableBooleanConstant : public tunableConstant {
00146 private:
00147 bool value;
00148 booleanChangeValCallBackFunc newValueCallBack;
00149
00150 public:
00151
00152 tunableBooleanConstant(bool initialValue,
00153 booleanChangeValCallBackFunc cb,
00154 tunableUse type,
00155 const char *name,
00156 const char *desc);
00157 bool getValue() { return value; }
00158 bool setValue(bool newVal) {
00159 value = newVal;
00160 if (newValueCallBack)
00161 newValueCallBack(newVal);
00162 return true;
00163 }
00164
00165 virtual void print();
00166 };
00167
00168 class tunableFloatConstant : public tunableConstant {
00169 private:
00170 float value;
00171 float min, max;
00172 isValidFunc isValidValue;
00173
00174 floatChangeValCallBackFunc newValueCallBack;
00175 bool simpleRangeCheck(float val);
00176
00177 public:
00178
00179 tunableFloatConstant(float initialValue,
00180 float min,
00181 float max,
00182 floatChangeValCallBackFunc cb,
00183 tunableUse type,
00184 const char *name,
00185 const char *desc);
00186 tunableFloatConstant(float initialValue,
00187 isValidFunc,
00188 floatChangeValCallBackFunc cb,
00189 tunableUse type,
00190 const char *name,
00191 const char *desc);
00192 float getValue() { return value; }
00193 bool setValue(float newVal) {
00194 if (isValidValue && isValidValue(newVal)) {
00195 value = newVal;
00196 if (newValueCallBack)
00197 newValueCallBack(newVal);
00198 return true;
00199 }
00200 else if (simpleRangeCheck(newVal)) {
00201 value = newVal;
00202 if (newValueCallBack)
00203 newValueCallBack(newVal);
00204 return true;
00205 }
00206 else
00207 return false;
00208 }
00209
00210 float getMin() {return min;}
00211 float getMax() {return max;}
00212
00213 virtual void print();
00214 };
00215
00216 #endif