CSIM: csimclass.h Source File

csimclass.h

Go to the documentation of this file.
00001 #ifndef __CSIMCLASS_H__
00002 #define __CSIMCLASS_H__
00003 
00115 
00123 
00145 #include <string.h>
00146 #include <stdio.h>
00147 #include "globaldefinitions.h"
00148 
00149 
00150 class csimClass;
00151 class Network;
00152 class Advancable;
00153 
00154 typedef double * pDoubleField;
00155 typedef double ** pDoubleArray;
00156 typedef float * pFloatField;
00157 typedef float ** pFloatArray;
00158 typedef int  * pIntField;
00159 typedef int ** pIntArray;
00160 
00161 #define DOUBLEFIELD  0
00162 #define DOUBLEARRAY  1 
00163 #define FLOATFIELD   2
00164 #define FLOATARRAY   3
00165 #define INTFIELD     4
00166 #define INTARRAY     5
00167 
00169 #define READONLY  0
00170 
00172 #define READWRITE 1
00173 
00175 
00176 class csimFieldInfo {
00177 public:
00178   csimFieldInfo(void) { offset = -1; fieldType = -1;};
00180   const char *name;
00181 
00183   const char *description;
00184   
00186   const char *units;
00187 
00189   int access;
00190 
00192   int m;
00193 
00195   float lb;
00196 
00198   float ub;
00199 
00203 
00204   int fieldType;
00206   int offset;
00208 };
00209 
00210 
00212 
00213 class csimClassInfo {
00214   
00215  public:
00216   csimClassInfo(void);
00217   ~csimClassInfo(void);
00218   
00220   const char *name;
00221 
00223   const char *description;
00224 
00226   int  classId;
00227 
00230 
00231   int registerField(char *base, const char *name, pDoubleField field, int access, int sz, double lb, double ub, const char *units, const char *desc);
00233   int registerField(char *base, const char *name, pDoubleArray array, int access, int sz, double lb, double ub, const char *units, const char *desc);
00235   int registerField(char *base, const char *name, pFloatField field, int access, int sz, double lb, double ub, const char *units, const char *desc);
00237   int registerField(char *base, const char *name, pFloatArray array, int access, int sz, double lb, double ub, const char *units, const char *desc);
00239   int registerField(char *base, const char *name, pIntField field, int access, int sz, double lb, double ub, const char *units, const char *desc);
00241   int registerField(char *base, const char *name, pIntArray array, int access, int sz, double lb, double ub, const char *units, const char *desc);
00243 
00245   int getFieldId(char *name);
00246 
00248   inline int nFields(void) { return nRegFields; }
00249   
00251   inline const char *getFieldName(int id) { if ( id>=0 && id < nRegFields ) return regFields[id]->name; else return 0; }
00252 
00254   inline bool isFieldRW(int id) { return (regFields[id]->access==READWRITE); }
00255 
00257   void listFields(void);
00258 
00260   int getFieldArraySize(void) { return arraySize; };
00261 
00262  private:
00263   friend class csimClass;
00264 
00267 
00268   int add(csimFieldInfo *fi);
00270   int nRegFields;
00272   int lRegFields;
00274   csimFieldInfo **regFields;
00276 
00278   int arraySize;
00279 };
00280 
00282 
00293 class csimClassInfoDB {
00294  public:
00295   csimClassInfoDB(void);
00296   ~csimClassInfoDB(void);
00297 
00299 
00306   csimClassInfo *registerCsimClass(const char *name, const char *desc);
00307 
00309   void registerClasses(void);
00310 
00312   void listClasses(bool F);
00313 
00314  private:
00315   /* @name Quick implementation of a list of csimClassInfo objects */
00317 
00318   int add(csimClassInfo *info);
00320   int lRegClasses;
00322   int nRegClasses;
00323   csimClassInfo **regClasses;
00325 };
00326 
00327 
00328 extern csimClassInfoDB TheCsimClassDB;
00329 
00331 #define DO_REGISTERING    public: \
00332                             virtual csimClassInfo *getClassInfo(void) { return classInfo; }; \
00333                           protected: \
00334                             friend  class csimClassInfoDB; \
00335                             virtual void setClassInfo(csimClassInfo *ci){ classInfo = ci; }; \
00336                           private: \
00337                             static csimClassInfo *classInfo;
00338 
00339 class Advancable ;
00340 
00342 
00355 class csimClass {
00356 
00357  public:
00358   // The constructor (sets Id to -1)
00359   csimClass(void);
00360   
00361   // The destructor is needed bcs we have virtual function
00362   virtual ~csimClass(void){};
00363 
00365   virtual int init(Advancable *) { return 0; };
00366 
00368   int setFieldByName(char *o, char *name, double *v);
00369 
00371   int setFieldById(char *o, int id, double *v);
00372 
00374   int getFieldByName(char *o, char *name, double *v);
00375 
00377   int getFieldById(char *o, int id, double *v);
00378 
00380   int getFieldSizeByName(char *o, char *name);
00381 
00383   int getFieldSizeById(char *o, int id);
00384  
00386   void printFields(char *o);
00387 
00389   double *getFieldArray(char *o);
00390 
00392   int setFieldArray(char *o, double *p);
00393 
00395   inline int getFieldArraySize(void) { return getClassInfo()->getFieldArraySize(); }
00396 
00398   inline int getFieldId(char *name) { return getClassInfo()->getFieldId(name); }
00399 
00401   inline const char *getFieldName(int fId) { return getClassInfo()->getFieldName(fId); }
00402 
00404   inline int classId(void) { return getClassInfo()->classId; }
00405 
00407   inline const char *className(void) { return getClassInfo()->name; }
00408 
00410   inline int getId(void) { return Id; }
00411 
00413   virtual csimClassInfo *getClassInfo(void) { return classInfo; };
00414 
00416 
00419   int fieldChangeNotify(bool force=0) { 
00420     if ( force || dirty ) { 
00421       return ((dirty=(updateInternal()!=0)) ? -1 : 0); 
00422     } else 
00423       return 0;
00424   };
00425 
00427 
00430   virtual int updateInternal(void) { return 0; };
00431 
00432 protected:
00433   friend  class csimClassInfoDB;
00434 
00436   virtual void setClassInfo(csimClassInfo *ci){ classInfo = ci; };
00437 
00438   friend class csimRecorder;
00439 
00440   /* **********************
00441      BEGIN MICHAEL PFEIFFER
00442      ********************** */
00443   friend class Readout;
00444   /* ********************
00445      END MICHAEL PFEIFFER
00446      ******************** */
00447 
00448 
00450   char *getFieldPointerById(char *o, int id);
00451   int getFieldTypeById(int id);
00452 
00453 private:
00455   static csimClassInfo *classInfo;
00456   
00457   friend class Network;
00459 
00460   int Id;
00461 
00463 
00466   bool dirty;
00467 
00468 };
00469 
00470 
00471 #endif

 
(C) 2003, Thomas Natschläger last modified 07/10/2006