2 * Copyright (c) 1996-2009 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as "Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * By your use of Paradyn, you understand and agree that we (or any
12 * other person or entity with proprietary rights in Paradyn) are
13 * under no obligation to provide either maintenance services,
14 * update services, notices of latent defects, or correction of
15 * defects for Paradyn.
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 * tunableConstant - a constant that might be changed during execution.
34 * $Log: tunableConst.h,v $
35 * Revision 1.10 1994/12/21 07:10:06 tamches
36 * Made the "allConstants" variable protected and added a few member
37 * functions to let outside code access it (safely) in a manner useful
38 * for doing iterations through all tunable-constants.
40 * Revision 1.9 1994/12/21 00:31:44 tamches
41 * Greatly cleaned up the interface; no data members are public any more.
42 * Also some minor changes, such as using g++'s built-in "bool" instead
45 * Revision 1.8 1994/11/04 15:52:51 tamches
46 * setValue() for boolean tc's now correctly invokes its callback function, if any.
48 * Revision 1.7 1994/11/01 16:07:35 markc
49 * Added Object classes that provide os independent symbol tables.
50 * Added stl-like container classes with iterators.
52 * Revision 1.6 1994/10/26 22:32:50 tamches
53 * Defaulted min&max to 0 for floats with no min/max in constructor.
54 * Wrote min() and max() functions.
55 * Wrote use() function
56 * other minor changes to get to work with new tclTunable code
58 * Revision 1.5 1994/09/22 03:15:59 markc
59 * changed char* to const char *
61 * Revision 1.4 1994/08/05 16:01:55 hollings
62 * More consistant use of stringHandle vs. char *.
64 * Revision 1.3 1994/08/03 18:37:30 hollings
65 * split tunable constant into Boolean and Float sub-classes.
67 * Revision 1.2 1994/02/28 23:58:28 hollings
68 * Changed global list to be a pointer to a list because I couldn't rely on
69 * the order of global constructors.
71 * Revision 1.1 1994/02/25 00:25:58 hollings
72 * added tunable constants.
76 #ifndef TUNABLE_CONST_H
77 #define TUNABLE_CONST_H
80 #include "util/h/stringPool.h"
81 #include "util/h/list.h"
83 typedef enum tunableUse { developerConstant, userConstant };
84 typedef enum tunableType { tunableBoolean, tunableFloat };
87 // Note: this is an abstract class, and can NOT be directly created.
89 class tunableConstant {
96 static stringPool *pool; // made protected
98 static List<tunableConstant*> *allConstants; // NEEDS TO BE MADE PROTECTED
102 virtual ~tunableConstant() {}
104 const char *getDesc() const {
107 const char *getName() const {
110 tunableUse getUse() const {
113 tunableType getType() const {
117 static tunableConstant *findTunableConstant(const char *name);
118 // returns NULL if not found
120 static List<tunableConstant *> beginIteration() {
121 assert(allConstants);
123 List <tunableConstant *> iterList = *allConstants;
124 // make a copy of the list for iteration purposes
125 // (actually, it just copies the head element, which itself
126 // is merely a pointer)
131 static int numTunables() {
132 assert(allConstants);
133 return allConstants->count();
136 virtual void print() = NULL;
140 // Shouldn't the string pools be made part of the base class?
142 typedef bool (*isValidFunc)(float newVal);
143 typedef void (*booleanChangeValCallBackFunc)(bool value);
144 typedef void (*floatChangeValCallBackFunc)(float value);
146 class tunableBooleanConstant : public tunableConstant {
149 booleanChangeValCallBackFunc newValueCallBack;
153 tunableBooleanConstant(bool initialValue,
154 booleanChangeValCallBackFunc cb,
158 bool getValue() { return value; }
159 bool setValue(bool newVal) {
161 if (newValueCallBack)
162 newValueCallBack(newVal);
166 virtual void print();
169 class tunableFloatConstant : public tunableConstant {
173 isValidFunc isValidValue;
175 floatChangeValCallBackFunc newValueCallBack;
176 bool simpleRangeCheck(float val);
180 tunableFloatConstant(float initialValue,
183 floatChangeValCallBackFunc cb,
187 tunableFloatConstant(float initialValue,
189 floatChangeValCallBackFunc cb,
193 float getValue() { return value; }
194 bool setValue(float newVal) {
195 if (isValidValue && isValidValue(newVal)) {
197 if (newValueCallBack)
198 newValueCallBack(newVal);
201 else if (simpleRangeCheck(newVal)) {
203 if (newValueCallBack)
204 newValueCallBack(newVal);
211 float getMin() {return min;}
212 float getMax() {return max;}
214 virtual void print();