home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / watc11up.zip / cpplib_hdr.zip / h / wcsibase.h < prev    next >
C/C++ Source or Header  |  2001-08-28  |  3KB  |  125 lines

  1. //
  2. //  wcsibase.h    Base Class Definitions for the WATCOM Container Skip List
  3. //        Iterator Classes
  4. //
  5. //  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  6. //  Copyright by Sybase, Inc. 1997-1999.  All rights reserved.
  7. //
  8. #ifndef _WCSIBASE_H_INCLUDED
  9. #define _WCSIBASE_H_INCLUDED
  10. #if !defined(_ENABLE_AUTODEPEND)
  11.   #pragma read_only_file;
  12. #endif
  13.  
  14. #ifndef __cplusplus
  15. #error wcsibase.h is for use with C++
  16. #endif
  17.  
  18. #ifndef _WCEXCEPT_H_INCLUDED
  19.  #include <wcexcept.h>
  20. #endif
  21.  
  22.  
  23. //
  24. // The WCSkipListIterBase is the base iterator class for all skip list
  25. // iterators.
  26. //
  27. // Objects of this type should never be instantiated: use the appropriate
  28. // skip list iterator defined in wcskipit.h instead.
  29. //
  30. // WCIterExcept is used as a base class to provide exception handling
  31. //
  32.  
  33. template<class Type>
  34. class WCSkipListIterBase : public WCIterExcept {
  35. private:
  36.     typedef WCSkipListPtrs *    node_ptr;
  37.     const WCSkipListBase<Type> *curr_skip_list;
  38.  
  39. protected:
  40.     node_ptr            curr;
  41.  
  42. private:
  43.     int                at_end;
  44.  
  45.     WCbool base_advance();
  46.  
  47. protected:
  48.     inline WCSkipListNode<Type> *base_curr_node() const {
  49.     if( curr != 0 ) {
  50.         return( WCSkipListBase<Type>::base_whole_node( curr ) );
  51.     } else {
  52.         return( 0 );
  53.     }
  54.     };
  55.     
  56. public:
  57.     inline WCSkipListIterBase() : curr_skip_list( 0 )
  58.                        , curr( 0 ), at_end( 0 ) {};
  59.  
  60.     inline WCSkipListIterBase( const WCSkipListBase<Type>& skip_list )
  61.             : curr_skip_list( &skip_list ), curr( 0 ), at_end( 0 ) {};
  62.  
  63.     inline ~WCSkipListIterBase() {};
  64.  
  65.     inline const WCSkipListBase<Type> *container() const {
  66.     if( curr_skip_list == 0 ) {
  67.         base_throw_undef_iter();
  68.     }
  69.     return( curr_skip_list );
  70.     };
  71.  
  72.     Type current() const;
  73.  
  74.     inline void reset() {
  75.     curr = 0;
  76.     at_end = 0;
  77.     };
  78.  
  79.     inline void reset( const WCSkipListBase<Type> &skip_list ) {
  80.     curr_skip_list = &skip_list;
  81.     reset();
  82.     };
  83.  
  84.     inline WCbool operator++() {
  85.     return( base_advance() );
  86.     }
  87.  
  88.     inline WCbool operator()() {
  89.     return( base_advance() );
  90.     }
  91. };
  92.  
  93.  
  94. template <class Type>
  95. WCbool WCSkipListIterBase<Type>::base_advance() {
  96.     if( ( curr_skip_list == 0 )||( at_end ) ) {
  97.     at_end = 1;
  98.     base_throw_undef_iter();
  99.     return( FALSE );
  100.     }
  101.     if( curr == 0 ) {
  102.     curr = curr_skip_list->header;
  103.     }
  104.     curr = curr->forward[ 0 ];
  105.     if( curr == 0 ) {
  106.     at_end = 1;
  107.     return( FALSE );
  108.     } else {
  109.     return( TRUE );
  110.     }
  111. };
  112.  
  113.  
  114. template <class Type>
  115. Type WCSkipListIterBase<Type>::current() const {
  116.     if( curr == 0 ) {
  117.     base_throw_undef_item();
  118.     Type temp;
  119.     return( temp );
  120.     }
  121.     return( base_curr_node()->data );
  122. };
  123.  
  124. #endif
  125.