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

  1. // ========================================================================
  2. //  TODB LIBRARY
  3. //    icoll.h
  4. //
  5. //    Indexed Collection
  6. //    MakeToken class, IdxString class, IdxColl class
  7. //
  8. //    Version: see TODB.H file
  9. //
  10. //    Copyright 1993 Christian Thérien
  11. //    All rights reserved
  12. // ========================================================================
  13.  
  14. #ifndef _ICOLL_H
  15. #define _ICOLL_H
  16.  
  17. #include "boolean.h"
  18. #include "strn.h"
  19. #include "ptodb.h"
  20.  
  21. class TIndex;
  22. class TODB;
  23. class ErrReporter;
  24.  
  25. //-------------------------------------------------------------------------
  26. // MakeToken class (abstract base class)
  27. //-------------------------------------------------------------------------
  28.  
  29. class MakeToken
  30. {
  31. public:
  32.     virtual ~MakeToken();
  33.     virtual void Put( const char * s ) = 0;
  34.     virtual int First( char * token ) = 0;
  35.     virtual int Next( char * token ) = 0;
  36. };
  37.  
  38. //-------------------------------------------------------------------------
  39. // IdxString class
  40. //-------------------------------------------------------------------------
  41.  
  42. class IdxString : public String
  43. {
  44. friend class IdxColl;
  45.  
  46. public:
  47.     IdxString();
  48.     IdxString( const IdxString & istr );
  49.     IdxString( const String & str );
  50.  
  51.     ~IdxString();
  52.  
  53.     // -- assignment
  54.     IdxString & operator = ( const IdxString & istr );
  55.     IdxString & operator = ( const String & str );
  56.  
  57.     // -- update operator
  58.     IdxString & operator /= ( const String & str );
  59.  
  60. private:
  61.     String old_str_;
  62.     Boolean dirty_;
  63.  
  64.     // -- returns old string
  65.     String OldStr() const;
  66.     // -- returns state
  67.     Boolean Dirty() const;
  68. };
  69.  
  70. inline IdxString::~IdxString()
  71. {
  72. }
  73.  
  74. inline String IdxString::OldStr() const
  75. {
  76.     return old_str_;
  77. }
  78.  
  79. inline Boolean IdxString::Dirty() const
  80. {
  81.     return dirty_;
  82. }
  83.  
  84. //-------------------------------------------------------------------------
  85. // IdxColl class (abstract base class)
  86. //     "Indexed collection"
  87. //-------------------------------------------------------------------------
  88.  
  89. class IdxColl
  90. {
  91. public:
  92.     IdxColl( TODB & db, IdType cid );
  93.  
  94.     virtual ~IdxColl();
  95.  
  96.     void SaveIdx();
  97.     void ChangeIdx();
  98.     void DeleteIdx();
  99.  
  100.     void IndexObject( KeyType key, IdType idxid,
  101.               MakeToken & mt,
  102.               const IdxString & str );
  103.  
  104. protected:
  105.     virtual void Index() = 0;
  106.  
  107. private:
  108.     TODB & todb_;
  109.     TIndex & btree_;
  110.     char * token_;
  111.     char * entry_;
  112.     IdType curcid_;
  113.     Boolean changed_;
  114.     Boolean deleted_;
  115.  
  116.     IdxColl( const IdxColl & ic );
  117.     IdxColl & operator = ( const IdxColl & ic );
  118.  
  119.     void MakePrefix( IdType cid, IdType idxid );
  120.     void NormID( char * buf );
  121.  
  122.     void NewSet( KeyType key );
  123.     void AddIndexes( KeyType key, IdType idxid, MakeToken & mt,
  124.              const IdxString & str );
  125.     void DeleteIndexes( KeyType key, IdType idxid, MakeToken & mt,
  126.             const IdxString & str );
  127.     void RemoveIndexes( KeyType key, IdType idxid, MakeToken & mt,
  128.             const String & str );
  129. };
  130.  
  131. inline void IdxColl::ChangeIdx()
  132. {
  133.     changed_ = True;
  134. }
  135.  
  136. inline void IdxColl::DeleteIdx()
  137. {
  138.     deleted_ = True;
  139. }
  140.  
  141. #endif // _ICOLL_H
  142.