home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / c / WLIB.ZIP / WBTRIEVE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-30  |  4.5 KB  |  132 lines

  1. #ifndef WBtrieveIncluded
  2. #define WBtrieveIncluded
  3.  
  4. // copyright (c) 1992, 1993 by Paul Wheaton
  5. // 1916 Brooks #205, Missoula, MT  59801
  6. //
  7. // voice phone:  (406)543-7543
  8. // modem phone:  (406)543-1144 (2400N81)
  9. //  CompuServe:  72707,207
  10. //    Internet:  72707.207@CompuServe.com
  11.  
  12. #include <WBits.h>
  13.  
  14. const int BtrieveNormal=0;
  15. const int BtrieveAccelerated=-1;
  16. const int BtrieveReadOnly=-2;
  17. const int BtrieveVerify=-3;
  18. const int BtrieveExclusive=-4;
  19.  
  20. class Btrieve // still working on this one. "CreateBtrieveFile" works great tho
  21.   {
  22.       char PosBlock[128]; // storage area for BTrieve
  23.       Bool Closed;
  24.       char* Buffy;  // storage for the current record
  25.       int BuffyLen;
  26.       int LastKey;
  27.       int Stat;
  28.       char* Keys[10];  // where the keys are in Buffy
  29.     public:
  30.       Btrieve(const char* FileName, int BiggestRecSize,int Mode=0);
  31.       ~Btrieve(){Close();}
  32.       void Close();
  33.       // Get functions return the size of the record retrieved - 0 if problem
  34.       int GetFirst(int KeyNum=0);
  35.       int GetLast(int KeyNum=0);
  36.       int GetNext();
  37.       int GetPrev();
  38.       int GetE(int SearchVal, int KeyNum=0);
  39.       int GetE(const char* SearchVal, int KeyNum=0);
  40.       int GetE(long SearchVal, int KeyNum=0);
  41.       int GetG(int SearchVal, int KeyNum=0);
  42.       int GetG(const char* SearchVal, int KeyNum=0);
  43.       int GetG(long SearchVal, int KeyNum=0);
  44.       int GetGE(int SearchVal, int KeyNum=0);
  45.       int GetGE(const char* SearchVal, int KeyNum=0);
  46.       int GetGE(long SearchVal, int KeyNum=0);
  47.       int GetL(int SearchVal, int KeyNum=0);
  48.       int GetL(const char* SearchVal, int KeyNum=0);
  49.       int GetL(long SearchVal, int KeyNum=0);
  50.       int GetLE(int SearchVal, int KeyNum=0);
  51.       int GetLE(const char* SearchVal, int KeyNum=0);
  52.       int GetLE(long SearchVal, int KeyNum=0);
  53.       void* Cur(){return Buffy;}
  54.       Bool Update(); // returns False on any error
  55.       Bool Update(int RecLen);
  56.       Bool Insert(const void* Rec=NULL);
  57.       Bool Insert(const void* Rec,int Len);
  58.       // set the local record and write that to the file
  59.       Bool Insert(int Len){return Insert(NULL,Len);}
  60.       void DelCur(); // the last record loaded up is killed from the database
  61.       long Position();
  62.       int GetDirect(long Pos);
  63.   };
  64.  
  65. #define CreateBtrieveClass(ClassName,ObjType)                        \
  66.                                                                      \
  67. class ClassName: public Btrieve                                      \
  68.   {                                                                  \
  69.     public:                                                          \
  70.       ClassName(const char* Name,int Mode=BtrieveNormal)             \
  71.           :Btrieve(Name,sizeof(ObjType),Mode){}                      \
  72.       ObjType& Cur(){return *((ObjType*)(Btrieve::Cur()));}          \
  73.       Bool Insert(const ObjType& X){return Btrieve::Insert(&X);}     \
  74.       Bool Insert(const ObjType& X, int Len)                         \
  75.           {return Btrieve::Insert(&X,Len);}                          \
  76.       Bool Insert(){return Btrieve::Insert();}                       \
  77.       Bool Insert(int Len){return Btrieve::Insert(Len);}             \
  78.   };
  79.  
  80. // internal use only
  81. struct KeySpec
  82.   {
  83.     int Pos;
  84.     int Len;
  85.     BitSet16 Flags;
  86.     long NotUsed;
  87.     char ExtendedType;
  88.     char NullValue;
  89.     long Reserved;
  90.   };
  91.  
  92. // internal use only
  93. CreateRefVectorClass(KeySpecVec,KeySpec);
  94.  
  95. // internal use only
  96. struct FileSpec
  97.   {
  98.     int RecLen;
  99.     int PageSize;
  100.     int NumIndexes;
  101.     long Unused;
  102.     BitSet16 Flags;
  103.     int Reserved;
  104.     int PreAllocation;
  105.   };
  106.  
  107. enum BtrieveKeyType {BKInt,BKStringFast,BKString};
  108.   // BKStringFast will be case sensitive
  109.  
  110. class CreateBtrieveFile
  111.   {
  112.       FileSpec F;
  113.       KeySpecVec K;
  114.       const char* Name;
  115.       Bool Closed;
  116.       Bool IncludeACS;
  117.     public:
  118.       CreateBtrieveFile(const char* FileName, int RecSize, int PageSize);
  119.       ~CreateBtrieveFile(){Done();}
  120.       void SetVariableLength() {F.Flags[0]=On;} // variable length records
  121.       void SetAutoTrim() {F.Flags[1]=On;} // trim trailing spaces of VLR?
  122.       void SetCompression(){F.Flags[3]=On;}
  123.       void SetKeyOnly(){F.Flags[4]=On;}
  124.       void SetFreeSpaceThreshold(int Percent);  // accepts 10, 20, 30
  125.       void PreAllocatePages(int Pages);
  126.       void DefineKey(int Pos, int Len, BtrieveKeyType BKT, Bool Duplicates,
  127.                      Bool Modifiable, int KeyNum=0);
  128.       void Done();
  129.   };
  130.  
  131. #endif
  132.