home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cslio205.zip / INCLUDE / CSVBASE.H < prev    next >
C/C++ Source or Header  |  1997-01-21  |  6KB  |  203 lines

  1. /***********************************************************************
  2.  
  3.                       CSDB Library, Free Evaluation Version 2.0.5 
  4.                                        Release: January 22th 1997 
  5.  
  6.        Header file of the VBASE class.
  7.        Database class for records with variable length.
  8.  
  9.                                            Copyright(c) 1994-1997 
  10.                                                           ComBits 
  11.                                                   The Netherlands 
  12. ***********************************************************************/
  13.  
  14. #ifndef __CSVBASE_H
  15. #define __CSVBASE_H
  16.  
  17. #include "cstypes.h"
  18. #include "cspage.h"
  19. #include "cstaba.h"
  20.  
  21.  
  22. /////////////////////// Some Typedefs /////////////////////////
  23.  
  24. typedef U32 VBPO;
  25. typedef U32 PANR;
  26. typedef U16 OFNR;
  27.  
  28.  
  29.  
  30. ////////////////////// VBASE class definition ///////////////////
  31.  
  32. class VBASE: public PAGE
  33. {
  34.  
  35.  private:
  36.  
  37.  
  38.    typedef struct
  39.    {
  40.      VBPO pos;
  41.    } vbi;             //VBase Index
  42.  
  43.    typedef struct
  44.    {
  45.      unsigned length: 15;
  46.      unsigned delet:   1;
  47.      U16 alloc;
  48.    } dhd;             //Data HeaDer
  49.  
  50.    typedef struct
  51.    {
  52.      VBPO   pos;
  53.      S16    alloc;
  54.    } edc;             //Empty Data Chain
  55.  
  56.  
  57. protected:
  58.  
  59.    TABLEa vpi;           // Virtual Page Index.
  60.    ARRAY  vpi_cut;       // Virtual Page Index short CUT.
  61.  
  62.    U16    ipp;           // Indexes Per Page.
  63.    U16    ipp_offmask;
  64.    U16    ipp_shftrig;
  65.    U16    nip;           // Number of pages currently used by the index.
  66.  
  67.    U16    pag_s;         // Page Shift.
  68.    U16    pag_o;         // Page OR.
  69.  
  70.    edc   *eda;           // Empty Data Array
  71.    U16    esr;           // Eda Shift Right
  72.    U16    enr;           // Eda NumbeR
  73.    int    epc;           // Eda Page Changed.
  74.  
  75.    U32    numrec;        // Number of records.
  76.    U16    maxrlen;       // Max Record Length.
  77.  
  78.    int    rel_shrink;    // Relocate record when shrunk.
  79.  
  80.    void   init_vpi(void);
  81.    void   init_eca(void);
  82.    void   init_vars(void);
  83.    void   init_defaults(void);
  84.    void   save_vpi(void);
  85.    void   close_vpi(void);
  86.    void   save_eca(void);
  87.    void   close_eca(void);
  88.    void   reset_vpi(void);
  89.    void   reset_eca(void);
  90.  
  91.    U32    pag(VBPO &p)              { return p>>pag_s;       }
  92.    U16    off(VBPO &p)              { return (U16)(p&pag_o); }
  93.    VBPO   vbpo(PANR &p,OFNR &of)    { return (p<<pag_s)|of;  }
  94.  
  95.    csCHAR   *pos_poa(PANR p,OFNR of)  { return load_page(p)+of; }
  96.    csCHAR   *pos_poda(PANR p,OFNR of) { return load_page_d(p)+of; }
  97.    csCHAR   *pos_poa(VBPO  p)       { return pos_poa(pag(p),off(p));  }
  98.    csCHAR   *pos_poz(VBPO  p)       { return pos_poa(p)+sizeof(dhd);  }
  99.    csCHAR   *pos_poda(VBPO  p)      { return pos_poda(pag(p),off(p)); }
  100.    csCHAR   *pos_podz(VBPO  p)      { return pos_poda(p)+sizeof(dhd); }
  101.  
  102.  
  103.    dhd   *DH(void *p) { return (dhd *)p; }
  104.  
  105.    VBPO   p2i(U32 rec);
  106.    void   p2i(U32 rec,VBPO pos);
  107.  
  108.    int    is_index_page(PANR p);
  109.  
  110.    U16    data_alloc(U16 amount,PANR &page,OFNR &offset,void *&ptr);
  111.    void   data_free(void *ptr,PANR page,OFNR  offset,U16 amount);
  112.    U16    data_alloc_full(U16 amount,PANR &page,OFNR &offset,void *&ptr);
  113.  
  114.    void   sort_eca(void);
  115.    void   set_num_page(PANR n);
  116.    int    max_buf_locked(void )     { return 4; }
  117.    void   numvrec(U32 l)            { numrec=l; }
  118.  
  119.    void   head2vars(void);
  120.    void   vars2head(void);
  121.  
  122.    virtual int check_id(U32 id);
  123.    virtual void set_id(void);
  124.  
  125. ///////////////////////// DB Header ///////////////////////////////////
  126.    virtual int read_header(void);
  127.    virtual int write_header(void);
  128.  
  129.  
  130.  
  131.  
  132. ////////////////////////////////////////////////////////////////////////
  133. ////////////////////// PUBLIC FUNCTIONS////////////////////////////////
  134. ////////////////////////////////////////////////////////////////////////
  135.  public:
  136.  
  137.    VBASE(void);
  138.    virtual
  139.   ~VBASE(void);
  140.  
  141.  
  142. //////////////////////// Compatibility functions ////////////////////////////
  143.    csCHAR *locate(U32 k)            { return pos_podz(p2i(k)); }
  144.  
  145. //////////////////////// Definition//////////////////////////////////////////
  146.    int  define(csCHAR *name,U16 struclen);
  147.    void relocate_when_shrunk(int TrueOrFalse);
  148.  
  149. //////////////////////// Open & Close////////////////////////////////////////
  150.    int  open(csCHAR *name,U16 kb_buf=100);
  151.    int  close(void);
  152.    int  save(void);
  153.  
  154. //////////////////////// Locate, Read & Writes records///////////////////////
  155.    void read_rec(U32 pos,void *ptr,U16  &length);
  156.    void read_rec(U32 pos,U16  maxlen,void *ptr,U16  &length);
  157.    void write_rec(U32 i,void *d,U16 len);
  158.  
  159.    csCHAR *locate_rec(S32  rec)     { return pos_poz(p2i(rec)); }
  160.    csCHAR *locate_rec_d(S32  rec)   { return pos_podz(p2i(rec)); }
  161.  
  162. //////////////////////// Add Records/////////////////////////////////////////
  163.    U32  append_rec(void *p,U16 len);
  164.  
  165. //////////////////////// Number of Records///////////////////////////////////
  166.    U32  numvrec(void)        { return numrec; }
  167.  
  168. //////////////////////// Data in Header Page/////////////////////////////////
  169. /* Inherited
  170.    int  data_2_header(void * ptr,U16 length);
  171.    int  header_2_data(void * ptr,U16 length);
  172.    U16  max_data_in_header(void);
  173. */
  174.  
  175. ////////////////////////// Deleting////////////////////////////////////////////
  176.    int  is_delet(U32 k)      { return !DH(pos_poa(p2i(k)))->delet; }
  177.    void delet(U32 k)         { DH(pos_poda(p2i(k)))->delet=0;   }
  178.    void undelet(U32 k )      { DH(pos_poda(p2i(k)))->delet=1;   }
  179.  
  180. ////////////////////////// Record Length///////////////////////////////////////
  181.    U16  rec_len(U32 k)       { return DH(pos_poa(p2i(k)))->length; }
  182.    U16  max_len(void)        { return maxrlen; }
  183.  
  184. //////////////////////// Report Writing//////////////////////////////////////
  185.    U16  report(csCHAR *name,S16 sub=1);
  186.    void report(FILE *fipo,S16 sub);
  187.  
  188. ////////////////////////// Miscellaneous///////////////////////////////////////
  189. /* Inherited
  190.    int  background(void)
  191. */
  192.    int  pack(void);
  193.    int  zap(void);
  194.    void empty(void);
  195.    void info(void);
  196.    int  relocate_when_shrunk(void) { return rel_shrink; }
  197.    virtual int class_ID(void)  { return CS_CLID_VBASE; }
  198.  
  199.  
  200. };
  201.  
  202. #endif
  203.