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 #include <string>
00029 #include <map>
00030 #include <vector>
00031 #include <list>
00032 #include <typeinfo>
00033 
00034 #include "parameter.h"
00035 #include "misc.h"
00036 
00037 #ifndef ___PARMANAGER_H___
00038 #define ___PARMANAGER_H___
00039 
00040 
00041 #define READ_OK         0
00042 #define OPEN_FAIL       1
00043 #define UNEXPECTED_EOF  2
00044 #define UNKNOWN_PARAM   4
00045 
00046 #define MAX_LINE_LENGTH 256
00047 
00053 
00064 
00065 
00066 class InstanceDesc
00067 {
00068  public:
00069   string Name;
00070   string Comment;
00071 
00072  public:
00073   InstanceDesc();
00074   InstanceDesc(string aName, string aComment);
00075 };
00076 
00078 
00079 class ClassDesc
00080 {
00081  public:
00082   string Name;
00083   string Comment;
00084 
00085   list<int> Params;
00086   list<InstanceDesc> Instance;
00087   
00088  public:
00089   ClassDesc();
00090   ClassDesc(string aName, string aComment);
00091 };
00092 
00093 
00095 
00096 
00098 
00105 class ParamManager
00106 {
00107  protected:
00108   vector<GenericParameter *> param;
00109   map<string, int> par_num;
00110 
00111   vector<ClassDesc> classes;
00112   map<string, int> classnum;
00113 
00114  public:
00115   
00116   ParamManager();
00117 
00119 
00123   void addParameter(string Class, GenericParameter *aPar) throw(ParamManagerException);
00124 
00126 
00130   void addClass(string aClass, string aComment);
00131 
00133 
00138   void addInstance(string aClass, string aInstance, string aComment) throw(ParamManagerException);
00139 
00140 
00141 
00142 
00143   GenericParameter *get(string aName, string aClass, string aInstance) throw(ParamManagerException);
00144   
00146 
00150   void setDefault (string aName, string aValue) throw(ParamManagerException);
00151 
00152   void printTemplate(ostream &os, bool ClassComments, bool ParameterComments, bool ExpandInstances);
00153   
00154   
00155   void ReadFile(istream &s) throw(ParamManagerException);
00156 
00157   
00158   void ReadFile(const char *FileName) throw(ParamManagerException);
00159 };
00160 
00161 template<class parType, class outType> 
00162   outType get(ParamManager* Param, string aName, string aClass, string aInstance) throw(ParamManagerException)
00163 {
00164   parType *p = dynamic_cast<parType *>(Param->get(aName, aClass, aInstance));
00165 
00166   if (!p)
00167   {
00168     throw ParamManagerException("Error getting parameter: " + aName + 
00169                                 " : parameter is not of type " + className(p) +
00170                                 " but of type " + className(Param->get(aName, aClass, aInstance)));
00171   }
00172   
00173   return p->get(aClass, aInstance);
00174 }
00175 
00177 
00178 #endif
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203