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

  1. // ========================================================================
  2. //  TODB LIBRARY
  3. //    schset.h
  4. //
  5. //    SearchSet class
  6. //
  7. //    Version: see TODB.H file
  8. //
  9. //    Copyright 1993 Christian Thérien
  10. //    All rights reserved
  11. // ========================================================================
  12.  
  13. #ifndef _SCHSET_H
  14. #define _SCHSET_H
  15.  
  16. #include "ptodb.h"
  17. #include "keyset.h"
  18.  
  19. class TODB;
  20. class TIndex;
  21. class KSet;
  22. class ErrReporter;
  23.  
  24. static const int SEARCHSET_MATCH     =  1;
  25. static const int SEARCHSET_NO_MATCH     =  0;
  26. static const int SEARCHSET_PATTERN_VALID =  0;    // valid pattern
  27. static const int SEARCHSET_PATTERN_ES     = -1;    // literal escape at end of pattern
  28. static const int SEARCHSET_PATTERN_RANGE = -2;    // incorrect range in [..] construct
  29. static const int SEARCHSET_PATTERN_CLOSE = -3;    // no end bracket in [..] construct
  30. static const int SEARCHSET_PATTERN_EMPTY = -4;    // [..] contstruct is empty
  31.  
  32. enum SearchSetError
  33. {
  34.     SSE_ALLOC,
  35.     SSE_DB
  36. };
  37.  
  38. class SearchSet
  39. {
  40. public:
  41.     // constructor
  42.     SearchSet( TODB * db );
  43.     SearchSet( const SearchSet & ss );
  44.  
  45.     // destructor
  46.     ~SearchSet();
  47.  
  48.     // number of elements
  49.     KeyNbr Card() const;
  50.  
  51.     // assignment
  52.     SearchSet & operator = ( const SearchSet & ss );
  53.  
  54.     // sets operators:
  55.  
  56.     // union (3 operands)
  57.     SearchSet operator * ( const SearchSet & ss );
  58.     // union (2 operands)
  59.     void operator *= ( const SearchSet & ss );
  60.  
  61.     // intersection (3 operands)
  62.     SearchSet operator + ( const SearchSet & ss );
  63.     // intersection (2 operands)
  64.     void operator += ( const SearchSet & ss );
  65.  
  66.     // difference (3 operands)
  67.     SearchSet operator - ( const SearchSet & ss );
  68.     // difference (2 operands)
  69.     void operator -= ( const SearchSet & ss );
  70.  
  71.     // sets comparison:
  72.     // same sets?
  73.     int operator == ( const SearchSet & ss ) const;
  74.     // different sets?
  75.     int operator != ( const SearchSet & ss ) const;
  76.  
  77.     // test
  78.     // returns 1 if pattern has any special wildcard characters, 0 otherwise
  79.     int isPattern( char * pattern ) const;
  80.     // check if pattern is valid
  81.     int isValidPattern( char * pattern ) const;
  82.  
  83.     // search functions
  84.     int FindExact( IdType cid, IdType idxid, char * buf);
  85.     int FindAll( IdType cid, IdType idxid );
  86.     int FindPattern( IdType cid, IdType idxid, char * pattern );
  87.  
  88.     // navigation (a returned value of 0 marks the end)
  89.     KeyType First();
  90.     KeyType Next();
  91.  
  92.     // error control
  93.     static void SetErrOut( ErrReporter * er );
  94.  
  95. protected:
  96.     SearchSet();
  97.  
  98. private:
  99.     TODB * todb_;
  100.     TIndex * btree_;
  101.     KSet * set_;
  102.     KeySet * pSet_;
  103.     char * entry_;
  104.     IdType curcid_;
  105.     IdType curidxid_;
  106.     ObjAdr addr_;
  107.  
  108.     void SetUnion( KSet & a, KSet & b, KSet & c );
  109.     void SetIntersection( KSet & a, KSet & b, KSet & c );
  110.     void SetDifference( KSet & a, KSet & b, KSet & c );
  111.     void MakePrefix( IdType cid, IdType idxid );
  112.     IdType ToCID();
  113.     IdType ToIDXID();
  114.  
  115.     int PosFirst();
  116.     int PosNext();
  117.  
  118.     // error control
  119.     static ErrReporter * ErrOut;
  120.     static void ErrorHandler( SearchSetError err );
  121. };
  122.  
  123. inline void SearchSet::operator *= ( const SearchSet & ss )
  124. {
  125.     *this = *this * ss;
  126. }
  127.  
  128. inline void SearchSet::operator += ( const SearchSet & ss )
  129. {
  130.     *this = *this + ss;
  131. }
  132.  
  133. inline void SearchSet::operator -= ( const SearchSet & ss )
  134. {
  135.     *this = *this - ss;
  136. }
  137.  
  138. inline KeyType SearchSet::First()
  139. {
  140.     return set_->First();
  141. }
  142.  
  143. inline KeyType SearchSet::Next()
  144. {
  145.     return set_->Next();
  146. }
  147.  
  148. #endif // _SCHSET_H
  149.