00001 #ifndef __CSIMCLASS_H__
00002 #define __CSIMCLASS_H__
00003
00115
00123
00140 #include <string.h>
00141 #include <stdio.h>
00142 #include "globaldefinitions.h"
00143
00144
00145 class csimClass;
00146 class Network;
00147 class Advancable;
00148
00149 typedef double * pDoubleField;
00150 typedef double ** pDoubleArray;
00151 typedef float * pFloatField;
00152 typedef float ** pFloatArray;
00153 typedef int * pIntField;
00154 typedef int ** pIntArray;
00155
00156 #define DOUBLEFIELD 0
00157 #define DOUBLEARRAY 1
00158 #define FLOATFIELD 2
00159 #define FLOATARRAY 3
00160 #define INTFIELD 4
00161 #define INTARRAY 5
00162
00164 #define READONLY 0
00165
00167 #define READWRITE 1
00168
00170
00171 class csimFieldInfo {
00172 public:
00173 csimFieldInfo(void) { offset = -1; fieldType = -1;};
00175 const char *name;
00176
00178 const char *description;
00179
00181 const char *units;
00182
00184 int access;
00185
00187 int m;
00188
00190 float lb;
00191
00193 float ub;
00194
00198
00199 int fieldType;
00201 int offset;
00203 };
00204
00205
00207
00208 class csimClassInfo {
00209
00210 public:
00211 csimClassInfo(void);
00212 ~csimClassInfo(void);
00213
00215 const char *name;
00216
00218 const char *description;
00219
00221 int classId;
00222
00225
00226 int registerField(char *base, const char *name, pDoubleField field, int access, int sz, double lb, double ub, const char *units, const char *desc);
00228 int registerField(char *base, const char *name, pDoubleArray array, int access, int sz, double lb, double ub, const char *units, const char *desc);
00230 int registerField(char *base, const char *name, pFloatField field, int access, int sz, double lb, double ub, const char *units, const char *desc);
00232 int registerField(char *base, const char *name, pFloatArray array, int access, int sz, double lb, double ub, const char *units, const char *desc);
00234 int registerField(char *base, const char *name, pIntField field, int access, int sz, double lb, double ub, const char *units, const char *desc);
00236 int registerField(char *base, const char *name, pIntArray array, int access, int sz, double lb, double ub, const char *units, const char *desc);
00238
00240 int getFieldId(char *name);
00241
00243 inline int nFields(void) { return nRegFields; }
00244
00246 inline const char *getFieldName(int id) { if ( id>=0 && id < nRegFields ) return regFields[id]->name; else return 0; }
00247
00249 inline bool isFieldRW(int id) { return (regFields[id]->access==READWRITE); }
00250
00252 void listFields(void);
00253
00255 int getFieldArraySize(void) { return arraySize; };
00256
00257 private:
00258 friend class csimClass;
00259
00262
00263 int add(csimFieldInfo *fi);
00265 int nRegFields;
00267 int lRegFields;
00269 csimFieldInfo **regFields;
00271
00273 int arraySize;
00274 };
00275
00277
00288 class csimClassInfoDB {
00289 public:
00290 csimClassInfoDB(void);
00291 ~csimClassInfoDB(void);
00292
00294
00301 csimClassInfo *registerCsimClass(const char *name, const char *desc);
00302
00304 void registerClasses(void);
00305
00307 void listClasses(bool F);
00308
00309 private:
00310
00312
00313 int add(csimClassInfo *info);
00315 int lRegClasses;
00317 int nRegClasses;
00318 csimClassInfo **regClasses;
00320 };
00321
00322
00323 extern csimClassInfoDB TheCsimClassDB;
00324
00326 #define DO_REGISTERING public: \
00327 virtual csimClassInfo *getClassInfo(void) { return classInfo; }; \
00328 protected: \
00329 friend class csimClassInfoDB; \
00330 virtual void setClassInfo(csimClassInfo *ci){ classInfo = ci; }; \
00331 private: \
00332 static csimClassInfo *classInfo;
00333
00335
00348 class Advancable ;
00349
00350 class csimClass {
00351
00352 public:
00353
00354 csimClass(void);
00355
00356
00357 virtual ~csimClass(void){};
00358
00360 virtual int init(Advancable *) { return 0; };
00361
00363 int setFieldByName(char *o, char *name, double *v);
00364
00366 int setFieldById(char *o, int id, double *v);
00367
00369 int getFieldByName(char *o, char *name, double *v);
00370
00372 int getFieldById(char *o, int id, double *v);
00373
00375 int getFieldSizeByName(char *o, char *name);
00376
00378 int getFieldSizeById(char *o, int id);
00379
00381 void printFields(char *o);
00382
00384 double *getFieldArray(char *o);
00385
00387 int setFieldArray(char *o, double *p);
00388
00390 inline int getFieldArraySize(void) { return getClassInfo()->getFieldArraySize(); }
00391
00393 inline int getFieldId(char *name) { return getClassInfo()->getFieldId(name); }
00394
00396 inline const char *getFieldName(int fId) { return getClassInfo()->getFieldName(fId); }
00397
00399 inline int classId(void) { return getClassInfo()->classId; }
00400
00402 inline const char *className(void) { return getClassInfo()->name; }
00403
00405 inline int getId(void) { return Id; }
00406
00408 virtual csimClassInfo *getClassInfo(void) { return classInfo; };
00409
00411
00414 int fieldChangeNotify(bool force=0) {
00415 if ( force || dirty ) {
00416 return ((dirty=(updateInternal()!=0)) ? -1 : 0);
00417 } else
00418 return 0;
00419 };
00420
00422
00425 virtual int updateInternal(void) { return 0; };
00426
00427 protected:
00428 friend class csimClassInfoDB;
00429
00431 virtual void setClassInfo(csimClassInfo *ci){ classInfo = ci; };
00432
00433 friend class csimRecorder;
00435 char *getFieldPointerById(char *o, int id);
00436 int getFieldTypeById(int id);
00437
00438 private:
00440 static csimClassInfo *classInfo;
00441
00442 friend class Network;
00444
00445 int Id;
00446
00448
00451 bool dirty;
00452
00453 };
00454
00455
00456 #endif