home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / MAGAZINE / DDJ9309.ZIP / NETSQL.ZIP / DDFFILE.H < prev    next >
C/C++ Source or Header  |  1993-04-30  |  3KB  |  144 lines

  1. #ifndef DDFFILE_H
  2. #define DDFFILE_H
  3.  
  4. #include "bfile.h"
  5.  
  6. class Value {
  7.    char *strValue;
  8.    double dValue;
  9.    long iValue;
  10.    int len;
  11.    int dec;
  12. public:
  13.    Value(int l=0,int dec=0);
  14.    Value(char *s,int l=10,int dec=0);
  15.    Value(double t,int l=10,int dec=0);
  16.    Value(long i,int l=10);
  17.    ~Value()
  18.    {
  19.       if ( strValue!=0 )
  20.       {
  21.          my_free(strValue,__FILE__,__LINE__);
  22.       }
  23.    }
  24.    void setVal(char *s);
  25.    void setVal(double t);
  26.    void setVal(long i);
  27.    void operator=(long l)
  28.    {
  29.       setVal(l);
  30.    }
  31.    void operator=(double d)
  32.    {
  33.       setVal(d);
  34.    }
  35.    void operator=(char *s)
  36.    {
  37.       setVal(s);
  38.    }
  39.    void setLenDec(int l,int d);
  40.    void clear();
  41.    operator char *() { return strValue; }
  42.    operator long() { return iValue; }
  43.    operator double() { return dValue; }
  44.    int getLen() { return len; }
  45.    int getDec() { return dec; }
  46. };
  47.  
  48. struct FILEDDF {
  49.    int fileID;
  50.    char fileName[20];
  51.    char fileLoc[64];
  52.    int flags;
  53. };
  54. struct FIELDDDF {
  55.       int fieldID;
  56.       int fileID;
  57.       char fieldName[20];
  58.       char btDataType;
  59.       int offset;
  60.       int fieldSize;
  61.       char decimals;
  62.       int flags;
  63.       class Value value;
  64. } ;
  65. struct INDEXDDF {
  66.    int fileID;
  67.    int fieldID;
  68.    int keyNumber;
  69.    int segNumber;
  70.    int flags;
  71. };
  72.  
  73. // this is what is needed to keep track of Btrieve currency.
  74. struct BOOKMARK {
  75.    char pos[4];
  76.    int key;
  77. };
  78.  
  79. class ddfFile {
  80.    char physicalName[22];
  81.    char logicalName[70];
  82.    bfile *theFile;
  83.    struct FIELDDDF *fields[256];
  84.    struct FILEDDF fileDDF;
  85.    int numFields;
  86.    int fieldsToData();
  87.    int dataToFields();
  88. public:
  89.    ddfFile(char *lname,char *owner=0);
  90.    ~ddfFile();
  91.    void setValue(char *t,int fnum)  { fields[fnum]->value.setVal(t); }
  92.    void setValue(long l,int fnum)   { fields[fnum]->value.setVal(l); }
  93.    void setValue(double d,int fnum) { fields[fnum]->value.setVal(d); }
  94.    void nullOut();
  95.    int getFieldID(char *);
  96.    char *getFieldName(int);
  97.    char *getValue(char *);
  98.    char *getValue(int fnum);
  99.    void toData(int fnum,void *t);
  100.    int get_status()
  101.    {
  102.       if ( theFile==0 )
  103.       {
  104.          return 9999;
  105.       }
  106.       else
  107.       {
  108.          return theFile->get_status();
  109.       }
  110.    }
  111.    int unlock()
  112.    {
  113.       return theFile->unlock();
  114.    }
  115.    void set_key_num(int key_num)
  116.    {
  117.       theFile->set_key_num(key_num);
  118.    }
  119.   // overload operator++
  120.    int  operator++(int )
  121.    {
  122.       char temp[255];
  123.       return(get_rec(temp,B_GET_NEXT));
  124.    }
  125.   // overload  operator--
  126.    int  operator--(int )
  127.    {
  128.       char temp[255];
  129.       return(get_rec(temp,B_GET_PREV));
  130.    }
  131.   // Gets a record.  Uses key 0 unless you have set key number.
  132.    int  get_rec(char far *keystr,int op=B_GET_EQ);
  133.   //   SEE BELOW...
  134.    int  put_rec(char far *keystr=0,unsigned tlen=0,int just_update=0);
  135.   // Insert.  made seperate functions to force insert.
  136.    int  insert(char far *keystr=0,unsigned tlen=0);
  137.   // self explanatory...except that if keystr==0, positioning is not done
  138.    int  del_rec(char far *keystr=0) { return(theFile->del_rec(keystr)); };
  139.    int getBookmark(struct BOOKMARK *theMark);
  140.    int gotoBookmark(struct BOOKMARK *theMark);
  141. };
  142. #endif
  143.  
  144.