paramTable.h

00001 /*  _________________________________________________________________________
00002  *
00003  *  UTILIB: A utility library for developing portable C++ codes.
00004  *  Copyright (c) 2001, Sandia National Laboratories.
00005  *  This software is distributed under the GNU Lesser General Public License.
00006  *  For more information, see the README file in the top UTILIB directory.
00007  *  _________________________________________________________________________
00008  */
00009 
00010 //
00011 // paramTable.H
00012 //
00025 #ifndef __paramTable_H
00026 #define __paramTable_H
00027 
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031 
00032 
00033 class parameter
00034 {
00035 public:
00036 
00038   double operator()() { return value; };
00046   static void readAll(int argc,char** argv,int minArgs = 0,int maxArgs = 1);
00048   void changeValue(double newValue);
00050   int hasBeenChanged() { return changeCounter > 0; };
00052   static int howMany() { return numParameters; };
00053 
00055   parameter(const char* name_,double minValue_,double value_,double maxValue_);
00057   ~parameter();
00058 
00060   enum { tableSize=101 };     // Define local constant.
00061 
00062 private:
00063 
00065   double     value;
00067   double     maxValue;
00069   double     minValue;
00071   const char*      name;
00073   int        changeCounter;
00074 
00076   parameter* next;
00078   parameter* prev;
00079 
00081   static int numParameters;
00083   static parameter* hashHeader[tableSize];
00084 
00086   static unsigned int hash(const char* name_);
00088   static parameter* lookup(const char* name_,int hashValue_);
00090   static parameter* lookup(const char* name_) { return lookup(name_,hash(name_)); };
00092   static void parseLine(int argc,char** arv,int minArgs = 0,int maxArgs = 1);
00094   static void readFromFile(const char* fileName);
00096   static double convert(const char* buffer, const char* errorKey);
00097   
00098 };
00099 
00100 
00102 #define CLASS_PARAMETER(name) \
00103    static parameter name
00104 
00106 #define GLOBAL_PARAMETER(name) \
00107    extern parameter name
00108 
00110 #define CLASS_PARAMETER_DEF(class,name,min,default,max) \
00111    parameter class::name(#name,min,default,max)
00112 
00114 #define GLOBAL_PARAMETER_DEF(name,min,default,max) \
00115    parameter name(#name,min,default,max)
00116 
00117 
00118 #endif