tunableConst.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 /*
00031  * tunableConstant - a constant that might be changed during execution.
00032  *
00033  * $Log: tunableConst.h,v $
00034  * Revision 1.10  1994/12/21 07:10:06  tamches
00035  * Made the "allConstants" variable protected and added a few member
00036  * functions to let outside code access it (safely) in a manner useful
00037  * for doing iterations through all tunable-constants.
00038  *
00039  * Revision 1.9  1994/12/21  00:31:44  tamches
00040  * Greatly cleaned up the interface; no data members are public any more.
00041  * Also some minor changes, such as using g++'s built-in "bool" instead
00042  * of "Boolean".
00043  *
00044  * Revision 1.8  1994/11/04  15:52:51  tamches
00045  * setValue() for boolean tc's now correctly invokes its callback function, if any.
00046  *
00047  * Revision 1.7  1994/11/01  16:07:35  markc
00048  * Added Object classes that provide os independent symbol tables.
00049  * Added stl-like container classes with iterators.
00050  *
00051  * Revision 1.6  1994/10/26  22:32:50  tamches
00052  * Defaulted min&max to 0 for floats with no min/max in constructor.
00053  * Wrote min() and max() functions.
00054  * Wrote use() function
00055  * other minor changes to get to work with new tclTunable code
00056  *
00057  * Revision 1.5  1994/09/22  03:15:59  markc
00058  * changed char* to const char *
00059  *
00060  * Revision 1.4  1994/08/05  16:01:55  hollings
00061  * More consistant use of stringHandle vs. char *.
00062  *
00063  * Revision 1.3  1994/08/03  18:37:30  hollings
00064  * split tunable constant into Boolean and Float sub-classes.
00065  *
00066  * Revision 1.2  1994/02/28  23:58:28  hollings
00067  * Changed global list to be a pointer to a list because I couldn't rely on
00068  * the order of global constructors.
00069  *
00070  * Revision 1.1  1994/02/25  00:25:58  hollings
00071  * added tunable constants.
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 // Note: this is an abstract class, and can NOT be directly created.
00087 //
00088 class tunableConstant {
00089  protected:
00090    char *desc;
00091    char *name;
00092    tunableType typeName;
00093    tunableUse use;
00094 
00095    static stringPool *pool; // made protected
00096 
00097    static List<tunableConstant*> *allConstants; // NEEDS TO BE MADE PROTECTED
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       // returns NULL if not found
00118 
00119    static List<tunableConstant *> beginIteration() {
00120       assert(allConstants);
00121 
00122       List <tunableConstant *> iterList = *allConstants;
00123          // make a copy of the list for iteration purposes
00124          // (actually, it just copies the head element, which itself
00125          // is merely a pointer)
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 // Shouldn't the string pools be made part of the base class?
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
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1