00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __MSD_DATATYPES_H__
00015 #define __MSD_DATATYPES_H__
00016
00017
00018 #include <ctype.h>
00019 #include <fstream>
00020 #include <ctime>
00021 #include <cstdio>
00022 #include <string>
00023 #include <unistd.h>
00024
00025
00026 #ifndef __MSD_DEFS_H__
00027 #include "msd_defs.h"
00028 #endif
00029
00030
00034 class msd_anyType
00035 { public:
00036 char * msd_item;
00037 let msd_sym;
00038 let msd_val;
00039 msd_anyType();
00040 virtual ~msd_anyType();
00041 virtual msd_anyType*& operator[](int i);
00042 virtual void print(std::ostream &s);
00043 virtual void setst(msdbStream &s);
00044 virtual void getst(msdbStream &s);
00045 virtual let getval();
00046 };
00047
00051 class msd_anySimpleType: public msd_anyType
00052 { public:
00053
00054 msd_anySimpleType();
00055 virtual ~msd_anySimpleType();
00056 virtual void print(std::ostream &s);
00057 virtual void setst(msdbStream &s);
00058 virtual void getst(msdbStream &s);
00059 virtual let getval();
00060 };
00061
00065 class msd_datetime: public msd_anySimpleType
00066 { public:
00067 otl_datetime msd_item;
00068 msd_datetime();
00069 virtual ~msd_datetime();
00070 msd_datetime(otl_datetime &t);
00071 virtual void print(std::ostream &s);
00072 virtual void setst(msdbStream &s);
00073 virtual void getst(msdbStream &s);
00074 virtual let getval();
00075 };
00076
00080 class msd_double: public msd_anySimpleType
00081 { public:
00082 double msd_item;
00083 msd_double();
00084 virtual ~msd_double();
00085 msd_double(double d);
00086 virtual void print(std::ostream &s);
00087 virtual void setst(msdbStream &s);
00088 virtual void getst(msdbStream &s);
00089 virtual let getval();
00090 };
00091
00092
00096 class msd_float: public msd_anySimpleType
00097 { public:
00098 float msd_item;
00099 msd_float();
00100 virtual ~msd_float();
00101 msd_float(float f);
00102 virtual void print(std::ostream &s);
00103 virtual void setst(msdbStream &s);
00104 virtual void getst(msdbStream &s);
00105 virtual let getval();
00106 };
00107
00108
00109
00113 class msd_string: public msd_anySimpleType
00114 { public:
00115
00116 msd_string();
00117 msd_string(char* st);
00118 msd_string(int size);
00119 virtual ~msd_string();
00120 virtual void print(std::ostream &s);
00121 virtual void setst(msdbStream &s);
00122 virtual void getst(msdbStream &s);
00123 virtual let getval();
00124 };
00125
00126
00130 class msd_int: public msd_anySimpleType
00131 { public:
00132 int msd_item;
00133 msd_int();
00134 virtual ~msd_int();
00135 msd_int(int i);
00136 virtual void print(std::ostream &s);
00137 virtual void setst(msdbStream &s);
00138 virtual void getst(msdbStream &s);
00139 virtual let getval();
00140 };
00141
00145 class msd_short: public msd_anySimpleType
00146 { public:
00147 short int msd_item;
00148 msd_short();
00149 virtual ~msd_short();
00150 msd_short(short int h);
00151 virtual void print(std::ostream &s);
00152 virtual void setst(msdbStream &s);
00153 virtual void getst(msdbStream &s);
00154 virtual let getval();
00155 };
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00191 class msd_array: public msd_anyType
00192 { public:
00193 msd_anyType **msd_ptr;
00194 int msd_size;
00195 msd_array();
00196 virtual ~msd_array();
00197 msd_array(int n);
00198 virtual msd_anyType*& operator[](int i);
00199 virtual void print(std::ostream &s);
00200 virtual void setst(msdbStream &s);
00201 virtual void getst(msdbStream &s);
00202 virtual let getval();
00203 };
00204
00206
00208 class MSDItemList;
00209 class MSDItemInfo;
00210 class MSDItem
00211 {
00212 MSDItemInfo * item_data;
00213 MSDItem * next;
00214 public:
00215 MSDItem(MSDItemInfo * new_item)
00216 { next = NULL;
00217 item_data = new_item;};
00218 friend class MSDItemList;
00219 };
00220 class MSDItemList
00221 {
00222 MSDItem *start;
00223 MSDItem *end_of_list;
00224 public:
00225 MSDItemList() {start = NULL;};
00226 void add_item(MSDItemInfo *new_item);
00227 void get_iteminfo(char * item_name);
00228 };
00229 class MSDItemInfo
00230 {
00231 public:
00232 char name[32];
00233 char description[32];
00234 char comment[256];
00235 MSDItemList * sublist1;
00236 MSDItemList * sublist2;
00237 MSDItemList * sublist3;
00238
00239 void display(void);
00240 };
00241
00243 template <class T>
00244
00248 class DBBin {
00249 private:
00250 char FileName[32];
00251 FILE* fp;
00252 public:
00253 DBBin() {
00254 strcpy(FileName,"");
00255 }
00256 DBBin(const char* fnm) {
00257 strcpy(FileName,fnm);
00258 }
00259 void SetFileName(const char* fnm) {
00260 strcpy(FileName,fnm);
00261 }
00262 bool Open() {
00263 fp = fopen(FileName,"rb+");
00264 if(fp == NULL) {
00265 fp = fopen(FileName,"wb+");
00266 }
00267 if(fp == NULL) {
00268 return false;
00269 }
00270 return true;
00271 }
00272 bool AddRecord(T& t) {
00273 fseek(fp,0,SEEK_END);
00274 if(fwrite((char*)&t,sizeof(T),1,fp)) {
00275 return true;
00276 }else {
00277 return false;
00278 }
00279 }
00280 bool FindRecord(unsigned long index, T& t) {
00281 int found;
00282 rewind(fp);
00283 bool ret = false;
00284 unsigned long pos = index * sizeof(T);
00285 found = fseek(fp,pos,SEEK_CUR);
00286 t.init();
00287 if (found == 0)
00288 {fread((char*)&t,sizeof(T),1,fp);
00289 ret = true;
00290 };
00291
00292
00293
00294 return ret;
00295 }
00296
00297 bool FindRecord(const char* on, T& t) {
00298 rewind(fp);
00299 bool ret = false;
00300
00301 t.init();
00302
00303 while((fread((char*)&t,sizeof(T),1,fp)) == 1) {
00304 if(strcmp(t.name,on) == 0){
00305 ret = true;
00306 break;}
00307
00308 }
00309
00310 return ret;
00311 }
00312
00313 bool ModifyRecord(T& newT,unsigned long index) {
00314 rewind(fp);
00315 unsigned long pos = index * sizeof(T);
00316 fseek(fp,pos,SEEK_CUR);
00317 if(fwrite((char*)&newT,sizeof(T),1,fp)) {
00318 return true;
00319 }else {
00320 return false;
00321 }
00322 }
00323 bool DeleteRecord(unsigned long index) {
00324 rewind(fp);
00325 FILE* tmp;
00326 char tmp_fnm[36];
00327 strcpy(tmp_fnm,"tmp.pln");
00328 tmp = fopen(tmp_fnm,"wb");
00329 if(tmp == NULL) {
00330 return false;
00331 }
00332 unsigned long idx = 0;
00333 T t;
00334
00335 while((fread((char*)&t,sizeof(T),1,fp)) == 1) {
00336 if(idx != index) {
00337 fwrite((char*)&t,sizeof(T),1,tmp);
00338 }
00339 idx++;
00340 }
00341 fclose(fp);
00342 fclose(tmp);
00343 tmp = fopen(tmp_fnm,"rb");
00344 fp = fopen(FileName,"wb+");
00345 if(fp != NULL) {
00346 rewind(fp);
00347 rewind(tmp);
00348 while((fread((char*)&t,sizeof(T),1,tmp)) == 1) {
00349 fwrite((char*)&t,sizeof(T),1,fp);
00350 }
00351 fclose(tmp);
00352 fclose(fp);
00353 fopen(FileName,"rb+");
00354 unlink(tmp_fnm);
00355 return true;
00356 }else {
00357 return false;
00358 }
00359 }
00360 unsigned long GetRecordCount() {
00361 fseek(fp,0,SEEK_END);
00362 unsigned long len = ftell(fp);
00363 unsigned long recs = len / sizeof(T);
00364 return recs;
00365 }
00366 void Close() {
00367 fclose(fp);
00368 }
00369 unsigned long GetNextRecordNo() {
00370 rewind(fp);
00371 unsigned long ret = 0;
00372 T t;
00373
00374 while((fread((char*)&t,sizeof(T),1,fp)) == 1) {
00375 if(t.id > ret) {
00376 ret = t.id;
00377 }
00378 }
00379 ret += 1;
00380 return ret;
00381 }
00382 };
00383
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00413
00417 class msd_xml_element
00418 {
00419 public:
00420 char * tag;
00421 char * data;
00422 msd_xml_element(){};
00423 ~msd_xml_element(){};
00424 };
00427
00431 class MSDDataSet {
00432 public:
00433 unsigned long id;
00434 char name[80];
00435 MSDDataSet();
00436 ~MSDDataSet();
00437 void init();
00438 void clean();
00439 int getSize() {return size;}
00440 void addEntity(let);
00441 void setValue(let, let, let);
00442 let getValue(let, let);
00443 void delEntity(let);
00444
00445
00446 private:
00447 int size;
00448
00449 let contents;
00450 };
00452
00453
00454
00455
00456 class msdDumpObjects
00457 {public:
00458 bool msdAddObject(MSDDataSet& obj);
00459 unsigned long msdFindObject(const char* obj);
00460 bool msdEditObject(const char* obj);
00461 bool msdDelObject(const char* obj);
00462 MSDDataSet msdGetObject(const char* obj);
00463 msdDumpObjects();
00464 ~msdDumpObjects();
00465 };
00467 int ToUpperStrArray(char* in[]);
00468 void trimspace(char* buffer);
00469 void trimcr(char* buffer);
00470 void removena(char* buffer);
00471 void lcase(char* buffer);
00472 void ucase(char* buffer);
00473 void midcopy(char* from,char* dest,int start_pos,int stop_pos);
00474 void leftcopy(char* from,char* dest,int pos);
00475 void rightcopy(char* from,char* dest,int pos);
00476 bool make_select_count (char* stm,char* countstm);
00477 bool make_select_param (char* stm ,char* paramstm);
00478 int has_integer_name (char* name);
00479 int StrArrayToListStr (char* strarray[], char liststr[]);
00480 bool isalphanum(const char* str);
00481 bool isnum(const char* str);
00482 bool fileexists(char* fn);
00483 bool ssm_file_completed(char* fn, const char* endstr);
00484 bool lsf_file_completed(char* fn);
00485 void wait(int seconds);
00486 char* getDateTime();
00487 void msdPrompt(char* host);
00488
00489
00490 #endif