Changes in libcfa/src/bits/stack.hfa [5e82d56:636d3715]
- File:
-
- 1 edited
-
libcfa/src/bits/stack.hfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/stack.hfa
r5e82d56 r636d3715 14 14 } // post: empty() & head() == 0 | !empty() & head() in *this 15 15 16 bool empty( Stack(T) & s ) with( s ) { // 0 <=> *this contains no elements17 return empty( (Collection &)s );18 }19 20 T *& Next( T * n ) {21 return (T *)Next( (Colable *)n );22 }23 24 T * Root( Stack(T) & s ) with( s ) {25 return (T *)root;26 }27 28 16 void ?{}( Stack(T) &, const Stack(T) & ) = void; // no copy 29 17 Stack(T) & ?=?( const Stack(T) & ) = void; // no assignment … … 33 21 } // post: empty() 34 22 35 T *top( Stack(T) & s ) with( s ) {36 return head( s );23 T & top( Stack(T) & s ) with( s ) { 24 return *head( s ); 37 25 } 38 26 39 void addHead( Stack(T) & s, T *n ) with( s ) {27 void addHead( Stack(T) & s, T & n ) with( s ) { 40 28 #ifdef __CFA_DEBUG__ 41 if ( listed( (Colable &)( *n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n );29 if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n ); 42 30 #endif // __CFA_DEBUG__ 43 Next( n ) = Root( s ) ? Root( s ) :n;44 root = n;31 Next( &n ) = head( s ) ? head( s ) : &n; 32 root = &n; 45 33 } 46 34 47 void add( Stack(T) & s, T *n ) with( s ) {35 void add( Stack(T) & s, T & n ) with( s ) { 48 36 addHead( s, n ); 49 37 } 50 38 51 void push( Stack(T) & s, T *n ) with( s ) {39 void push( Stack(T) & s, T & n ) with( s ) { 52 40 addHead( s, n ); 53 41 } 54 42 55 T *drop( Stack(T) & s ) with( s ) {56 T * t =head( s );43 T & drop( Stack(T) & s ) with( s ) { 44 T & t = *head( s ); 57 45 if ( root ) { 58 46 root = ( T *)Next(root); 59 if ( Root( s ) ==t ) root = 0p; // only one element ?60 Next( t ) = 0p;47 if ( head( s ) == &t ) root = 0p; // only one element ? 48 Next( &t ) = 0p; 61 49 } // if 62 50 return t; 63 51 } 64 52 65 T *pop( Stack(T) & s ) with( s ) {53 T & pop( Stack(T) & s ) with( s ) { 66 54 return drop( s ); 67 55 } … … 76 64 77 65 inline { 78 // wrappers to make ColIter have T79 T * Curr( StackIter(T) & si ) with( si ) {80 return (T *)curr;81 }82 83 66 void ?{}( StackIter(T) & si ) with( si ) { 84 67 ((ColIter &)si){}; … … 90 73 } // post: curr = {e in s} 91 74 92 void ?{}( StackIter(T) & si, T *start ) with( si ) {93 curr = start;75 void ?{}( StackIter(T) & si, T & start ) with( si ) { 76 curr = &start; 94 77 } // post: curr = {e in s} 95 78 … … 99 82 } // post: curr = {e in s} 100 83 101 bool ?>>?( StackIter(T) & si, T *& tp ) with( si ) {84 bool ?>>?( StackIter(T) & si, T && tp ) with( si ) { 102 85 if ( curr ) { 103 tp = Curr( si );86 &tp = Curr( si ); 104 87 T * n = Next( Curr( si ) ); 105 curr = (n == Curr( si )) ? 0p : n;106 } else tp = 0p;107 return tp != 0p;88 curr = n == Curr( si ) ? 0p : n; 89 } else &tp = 0p; 90 return &tp != 0p; 108 91 } 109 92 } // distribution
Note:
See TracChangeset
for help on using the changeset viewer.