From 184ca1b832796f4c81beae0a404c08f523712be8 Mon Sep 17 00:00:00 2001 From: hollings Date: Wed, 3 Aug 1994 18:37:30 +0000 Subject: [PATCH] split tunable constant into Boolean and Float sub-classes. --- common/h/tunableConst.h | 67 ++++++++++++++++++++++++++++++++--------- common/src/tunableConst.C | 77 +++++++++++++++++++++++++++++++++++++---------- pdutil/h/tunableConst.h | 67 ++++++++++++++++++++++++++++++++--------- pdutil/src/tunableConst.C | 77 +++++++++++++++++++++++++++++++++++++---------- 4 files changed, 228 insertions(+), 60 deletions(-) diff --git a/common/h/tunableConst.h b/common/h/tunableConst.h index e3e6946..6d4a957 100644 --- a/common/h/tunableConst.h +++ b/common/h/tunableConst.h @@ -2,7 +2,10 @@ * tunableConstant - a constant that might be changed during execution. * * $Log: tunableConst.h,v $ - * Revision 1.2 1994/02/28 23:58:28 hollings + * Revision 1.3 1994/08/03 18:37:30 hollings + * split tunable constant into Boolean and Float sub-classes. + * + * Revision 1.2 1994/02/28 23:58:28 hollings * Changed global list to be a pointer to a list because I couldn't rely on * the order of global constructors. * @@ -17,25 +20,64 @@ #include "util/h/stringPool.h" #include "util/h/list.h" -typedef Boolean (*isValidFunc)(float newVale); -typedef void (*changeValCallBackFunc)(float value); +typedef enum tunableUse { developerConstant, userConstant }; +typedef enum tunableType { tunableBoolean, tunableFloat }; +// +// Note: this is an abstract class, and can NOT be directly created. +// class tunableConstant { public: - tunableConstant(float initialValue, + char *getDesc() { return(desc); } + char *getName() { return(name); } + static List *allConstants; + static stringPool *pool; + virtual void print() = NULL; + tunableType getType() { return(typeName); } + protected: + char *desc; + char *name; + tunableType typeName; + tunableUse use; +}; + +typedef Boolean (*isValidFunc)(float newVale); +typedef void (*booleanChangeValCallBackFunc)(Boolean value); +typedef void (*floatChangeValCallBackFunc)(float value); + +class tunableBooleanConstant: public tunableConstant { + public: + tunableBooleanConstant(Boolean initialValue, + booleanChangeValCallBackFunc cb, + tunableUse type, + char *name, + char *desc); + Boolean getValue() { return value; } + Boolean setValue(Boolean newVal) { + value = newVal; + } + virtual void print(); + private: + Boolean value; + booleanChangeValCallBackFunc newValueCallBack; +}; + +class tunableFloatConstant: public tunableConstant { + public: + tunableFloatConstant(float initialValue, float min, float max, - changeValCallBackFunc cb, + floatChangeValCallBackFunc cb, + tunableUse type, char *name, char *desc); - tunableConstant(float initialValue, + tunableFloatConstant(float initialValue, isValidFunc, - changeValCallBackFunc cb, + floatChangeValCallBackFunc cb, + tunableUse type, char *name, char *desc); float getValue() { return value; } - char *getDesc() { return(desc); } - char *getName() { return(name); } Boolean setValue(float newVal) { if ((isValidValue) && isValidValue(newVal)) { value = newVal; @@ -49,16 +91,13 @@ class tunableConstant { return(FALSE); } } - static List *allConstants; - static stringPool *pool; + virtual void print(); private: - char *desc; - char *name; float value; float min, max; isValidFunc isValidValue; Boolean simpleRangeCheck(float val); - changeValCallBackFunc newValueCallBack; + floatChangeValCallBackFunc newValueCallBack; }; #endif diff --git a/common/src/tunableConst.C b/common/src/tunableConst.C index 36634f1..1c50b05 100644 --- a/common/src/tunableConst.C +++ b/common/src/tunableConst.C @@ -3,7 +3,10 @@ * execution of the system. * * $Log: tunableConst.C,v $ - * Revision 1.2 1994/02/28 23:58:38 hollings + * Revision 1.3 1994/08/03 18:37:39 hollings + * split tunable constant into Boolean and Float sub-classes. + * + * Revision 1.2 1994/02/28 23:58:38 hollings * Changed global list to be a pointer to a list because I couldn't rely on * the order of global constructors. * @@ -19,41 +22,83 @@ List *tunableConstant::allConstants; stringPool *tunableConstant::pool; -Boolean tunableConstant::simpleRangeCheck(float val) +tunableBooleanConstant::tunableBooleanConstant(Boolean initialValue, + booleanChangeValCallBackFunc cb, + tunableUse u, + char *n, + char *d) +{ + value = initialValue; + desc = d; + use = u; + typeName = tunableBoolean; + + if (!pool) pool = new(stringPool); + name = pool->findAndAdd(n); + newValueCallBack = cb; + if (!allConstants) allConstants = new(List); + allConstants->add(this, name); +} + +void tunableBooleanConstant::print() +{ + cout << name << " = "; + if (value == TRUE) { + cout << "True\n"; + } else { + cout << "False\n"; + } +} + +Boolean tunableFloatConstant::simpleRangeCheck(float val) { return((val >= min) && (val <= max)); } -tunableConstant::tunableConstant(float initialValue, - float low, - float high, - changeValCallBackFunc cb, - char *n, - char *d) +tunableFloatConstant::tunableFloatConstant(float initialValue, + float low, + float high, + floatChangeValCallBackFunc cb, + tunableUse u, + char *n, + char *d) + { value = initialValue; min = low; max = high; desc = d; + use = u; + typeName = tunableFloat; + newValueCallBack = cb; + if (!pool) pool = new(stringPool); name = pool->findAndAdd(n); - newValueCallBack = cb; if (!allConstants) allConstants = new(List); allConstants->add(this, name); } -tunableConstant::tunableConstant(float initialValue, - isValidFunc func, - changeValCallBackFunc cb, - char *n, - char *d) +tunableFloatConstant::tunableFloatConstant(float initialValue, + isValidFunc func, + floatChangeValCallBackFunc cb, + tunableUse u, + char *n, + char *d) { desc = d; - if (!pool) pool = new(stringPool); - name = pool->findAndAdd(n); + use = u; + typeName = tunableFloat; isValidValue = func; value = initialValue; newValueCallBack = cb; + + if (!pool) pool = new(stringPool); + name = pool->findAndAdd(n); if (!allConstants) allConstants = new(List); allConstants->add(this, name); } + +void tunableFloatConstant::print() +{ + cout << name << " = " << value << "\n"; +} diff --git a/pdutil/h/tunableConst.h b/pdutil/h/tunableConst.h index e3e6946..6d4a957 100644 --- a/pdutil/h/tunableConst.h +++ b/pdutil/h/tunableConst.h @@ -2,7 +2,10 @@ * tunableConstant - a constant that might be changed during execution. * * $Log: tunableConst.h,v $ - * Revision 1.2 1994/02/28 23:58:28 hollings + * Revision 1.3 1994/08/03 18:37:30 hollings + * split tunable constant into Boolean and Float sub-classes. + * + * Revision 1.2 1994/02/28 23:58:28 hollings * Changed global list to be a pointer to a list because I couldn't rely on * the order of global constructors. * @@ -17,25 +20,64 @@ #include "util/h/stringPool.h" #include "util/h/list.h" -typedef Boolean (*isValidFunc)(float newVale); -typedef void (*changeValCallBackFunc)(float value); +typedef enum tunableUse { developerConstant, userConstant }; +typedef enum tunableType { tunableBoolean, tunableFloat }; +// +// Note: this is an abstract class, and can NOT be directly created. +// class tunableConstant { public: - tunableConstant(float initialValue, + char *getDesc() { return(desc); } + char *getName() { return(name); } + static List *allConstants; + static stringPool *pool; + virtual void print() = NULL; + tunableType getType() { return(typeName); } + protected: + char *desc; + char *name; + tunableType typeName; + tunableUse use; +}; + +typedef Boolean (*isValidFunc)(float newVale); +typedef void (*booleanChangeValCallBackFunc)(Boolean value); +typedef void (*floatChangeValCallBackFunc)(float value); + +class tunableBooleanConstant: public tunableConstant { + public: + tunableBooleanConstant(Boolean initialValue, + booleanChangeValCallBackFunc cb, + tunableUse type, + char *name, + char *desc); + Boolean getValue() { return value; } + Boolean setValue(Boolean newVal) { + value = newVal; + } + virtual void print(); + private: + Boolean value; + booleanChangeValCallBackFunc newValueCallBack; +}; + +class tunableFloatConstant: public tunableConstant { + public: + tunableFloatConstant(float initialValue, float min, float max, - changeValCallBackFunc cb, + floatChangeValCallBackFunc cb, + tunableUse type, char *name, char *desc); - tunableConstant(float initialValue, + tunableFloatConstant(float initialValue, isValidFunc, - changeValCallBackFunc cb, + floatChangeValCallBackFunc cb, + tunableUse type, char *name, char *desc); float getValue() { return value; } - char *getDesc() { return(desc); } - char *getName() { return(name); } Boolean setValue(float newVal) { if ((isValidValue) && isValidValue(newVal)) { value = newVal; @@ -49,16 +91,13 @@ class tunableConstant { return(FALSE); } } - static List *allConstants; - static stringPool *pool; + virtual void print(); private: - char *desc; - char *name; float value; float min, max; isValidFunc isValidValue; Boolean simpleRangeCheck(float val); - changeValCallBackFunc newValueCallBack; + floatChangeValCallBackFunc newValueCallBack; }; #endif diff --git a/pdutil/src/tunableConst.C b/pdutil/src/tunableConst.C index 36634f1..1c50b05 100644 --- a/pdutil/src/tunableConst.C +++ b/pdutil/src/tunableConst.C @@ -3,7 +3,10 @@ * execution of the system. * * $Log: tunableConst.C,v $ - * Revision 1.2 1994/02/28 23:58:38 hollings + * Revision 1.3 1994/08/03 18:37:39 hollings + * split tunable constant into Boolean and Float sub-classes. + * + * Revision 1.2 1994/02/28 23:58:38 hollings * Changed global list to be a pointer to a list because I couldn't rely on * the order of global constructors. * @@ -19,41 +22,83 @@ List *tunableConstant::allConstants; stringPool *tunableConstant::pool; -Boolean tunableConstant::simpleRangeCheck(float val) +tunableBooleanConstant::tunableBooleanConstant(Boolean initialValue, + booleanChangeValCallBackFunc cb, + tunableUse u, + char *n, + char *d) +{ + value = initialValue; + desc = d; + use = u; + typeName = tunableBoolean; + + if (!pool) pool = new(stringPool); + name = pool->findAndAdd(n); + newValueCallBack = cb; + if (!allConstants) allConstants = new(List); + allConstants->add(this, name); +} + +void tunableBooleanConstant::print() +{ + cout << name << " = "; + if (value == TRUE) { + cout << "True\n"; + } else { + cout << "False\n"; + } +} + +Boolean tunableFloatConstant::simpleRangeCheck(float val) { return((val >= min) && (val <= max)); } -tunableConstant::tunableConstant(float initialValue, - float low, - float high, - changeValCallBackFunc cb, - char *n, - char *d) +tunableFloatConstant::tunableFloatConstant(float initialValue, + float low, + float high, + floatChangeValCallBackFunc cb, + tunableUse u, + char *n, + char *d) + { value = initialValue; min = low; max = high; desc = d; + use = u; + typeName = tunableFloat; + newValueCallBack = cb; + if (!pool) pool = new(stringPool); name = pool->findAndAdd(n); - newValueCallBack = cb; if (!allConstants) allConstants = new(List); allConstants->add(this, name); } -tunableConstant::tunableConstant(float initialValue, - isValidFunc func, - changeValCallBackFunc cb, - char *n, - char *d) +tunableFloatConstant::tunableFloatConstant(float initialValue, + isValidFunc func, + floatChangeValCallBackFunc cb, + tunableUse u, + char *n, + char *d) { desc = d; - if (!pool) pool = new(stringPool); - name = pool->findAndAdd(n); + use = u; + typeName = tunableFloat; isValidValue = func; value = initialValue; newValueCallBack = cb; + + if (!pool) pool = new(stringPool); + name = pool->findAndAdd(n); if (!allConstants) allConstants = new(List); allConstants->add(this, name); } + +void tunableFloatConstant::print() +{ + cout << name << " = " << value << "\n"; +} -- 1.8.3.1