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