home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / todb101 / todb / lib / todb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-26  |  2.6 KB  |  128 lines

  1. // ========================================================================
  2. //  TODB LIBRARY
  3. //    todb.h
  4. //
  5. //    TODB class
  6. //
  7. //    Version: 1.01
  8. //
  9. //    Copyright 1993 Christian Thérien
  10. //    All rights reserved
  11. // ========================================================================
  12.  
  13. #ifndef _TODB_H
  14. #define _TODB_H
  15.  
  16. #include "ptodb.h"
  17. #include "boolean.h"
  18. #include <stdio.h>
  19.  
  20. class String;
  21. class TIndex;
  22. class ErrReporter;
  23.  
  24. typedef ObjAdr BlockNbr;
  25. typedef KeyType KeyNbr;
  26.  
  27. enum TODBError
  28. {
  29.     TODBE_ALLOC,
  30.     TODBE_OPENFAIL,
  31.     TODBE_READ,
  32.     TODBE_CLOSE
  33. };
  34.  
  35. const int IDX_CREAT  =    0x01;
  36. const int IDX_EXIST  =    0x02;
  37. const int IDX_APPEND =    0x04;
  38.  
  39. class TODB
  40. {
  41. friend class IdxColl;
  42. friend class SearchSet;
  43. friend class Block;
  44. friend class KSPersistent;
  45. friend void CloseFromError();
  46.  
  47. public:
  48.     TODB();
  49.  
  50.     ~TODB();
  51.  
  52.     // -- open a key set database
  53.     Boolean Open( String & fname_key, String & fname_idx, int omode );
  54.     // -- close a key set database
  55.     void Close();
  56.     // -- database state
  57.     Boolean isOpen() const;
  58.  
  59.     // error control
  60.     static void SetErrOut( ErrReporter * er );
  61.  
  62. protected:
  63.     void SetErrorTrap();
  64.     void ResetErrorTrap();
  65.  
  66. private:
  67.     Boolean open_;             // true if files are opened
  68.     Boolean append_;             // true if opened in append mode
  69.     TIndex * tindex_;             // the b-tree
  70.     FILE * dataf_;             // key set database file
  71.     Boolean newf_;             // true if files are new
  72.     BlockNbr deletedblock_;         // first deleted block
  73.     BlockNbr highestblock_;         // highest assigned block
  74.     BlockNbr origdeletedblock_;         // original first deleted block
  75.     BlockNbr orighighestblock_;         // original highest assigned block
  76.  
  77.     TIndex * TIndexFile();
  78.     FILE * DataFile();
  79.  
  80.     BlockNbr NewBlock();
  81.     void SetDeletedBlock( BlockNbr block );
  82.     BlockNbr DeletedBlock() const;
  83.     Boolean Append() const;
  84.  
  85.     TODB( const TODB & db );
  86.     TODB & operator = ( const TODB & db );
  87.  
  88.     // error control
  89.     static ErrReporter * ErrOut;
  90.     static int ErrorTrapEnable;
  91.     static TODB * thisTODB;
  92.     static void ErrorHandler( TODBError err );
  93.     void SetGlobalErrorTrap();
  94.     static int MemError( size_t nm );
  95. };
  96.  
  97. inline Boolean TODB::isOpen() const
  98. {
  99.     return open_;
  100. }
  101.  
  102. inline Boolean TODB::Append() const
  103. {
  104.     return append_;
  105. }
  106.  
  107. inline void TODB::SetDeletedBlock( BlockNbr block )
  108. {
  109.     deletedblock_ = block;
  110. }
  111.  
  112. inline BlockNbr TODB::DeletedBlock() const
  113. {
  114.     return deletedblock_;
  115. }
  116.  
  117. inline TIndex * TODB::TIndexFile()
  118. {
  119.     return tindex_;
  120. }
  121.  
  122. inline FILE * TODB::DataFile()
  123. {
  124.     return dataf_;
  125. }
  126.  
  127. #endif // _TODB_H
  128.