Changeset d675c7 in git
- Timestamp:
- Jul 8, 1996, 10:18:49 AM (27 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- f63dbca24fdad0fc65e8496a781d6830dafded8e
- Parents:
- cc3e5eb035f7602ac7563d30a082c4b4bc9debf6
- Location:
- factory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/fac_iterfor.cc
rcc3e5e rd675c7 1 1 // emacs edit mode for this file is -*- C++ -*- 2 // $Id: fac_iterfor.cc,v 1. 0 1996-05-17 10:59:45stobbe Exp $2 // $Id: fac_iterfor.cc,v 1.1 1996-07-08 08:18:49 stobbe Exp $ 3 3 4 4 /* 5 5 $Log: not supported by cvs2svn $ 6 Revision 1.0 1996/05/17 10:59:45 stobbe 7 Initial revision 8 6 9 */ 7 10 … … 21 24 } 22 25 23 IteratedFor::IteratedFor( int n, int max ) : MAX( max ), N( n), last( false )26 IteratedFor::IteratedFor( int from, int to, int max ) : MAX( max ), FROM( from ), TO( to ), N( TO-FROM ), last( false ) 24 27 { 25 ASSERT( n > 1&& max >= 0, "illegal iterated for" );26 index = new int[ n+1];27 imax = new int[ n+1];28 fill( 2, max );28 ASSERT( n >= 0 && max >= 0, "illegal iterated for" ); 29 index = new int[N+1]; 30 imax = new int[N+1]; 31 fill( 0, max ); 29 32 } 30 33 31 IteratedFor::IteratedFor( const IteratedFor & I ) : MAX( I.MAX ), N( I.N ), last( I.last )34 IteratedFor::IteratedFor( const IteratedFor & I ) : MAX( I.MAX ), FROM( I.FROM ), TO( I.TO ), N( I.N ), last( I.last ) 32 35 { 33 36 index = new int[N+1]; 34 37 imax = new int[N+1]; 35 for ( int i = 2; i<= N; i++ ) {38 for ( int i = 0; i <= N; i++ ) { 36 39 index[i] = I.index[i]; 37 40 imax[i] = I.imax[i]; … … 56 59 imax = new int[N+1]; 57 60 } 61 FROM = I.FROM; 62 TO = I.TO; 58 63 MAX = I.MAX; 59 64 last = I.last; 60 for ( int i = 2; i<= N; i++ ) {65 for ( int i = 0; i<= N; i++ ) { 61 66 index[i] = I.index[i]; 62 67 imax[i] = I.imax[i]; … … 70 75 { 71 76 ASSERT( ! last, "no more iterations" ); 72 if ( index[ 2] == MAX )77 if ( index[0] == MAX ) 73 78 last = true; 74 79 else { … … 79 84 else { 80 85 int i = N-1, m = index[N]; 81 while ( i > 1&& index[i] == imax[i] ) {86 while ( i > 0 && index[i] == imax[i] ) { 82 87 m += imax[i]; 83 88 i--; … … 92 97 IteratedFor::operator[] ( int i ) const 93 98 { 94 ASSERT( i >= 2 && i <= N, "illegal index" );95 return index[i ];99 ASSERT( i >= FROM && i <= TO, "illegal index" ); 100 return index[i-FROM]; 96 101 } 97 102 98 103 ostream& operator<< ( ostream& os, const IteratedFor & I ) 99 104 { 100 os << "( " << I[ 2];101 for ( int i = 3; i <= I.n(); i++ )105 os << "( " << I[I.from()]; 106 for ( int i = I.from()+1; i <= I.to(); i++ ) 102 107 os << ", " << I[i]; 103 108 os << " )"; -
factory/fac_iterfor.h
rcc3e5e rd675c7 1 1 // emacs edit mode for this file is -*- C++ -*- 2 // $Id: fac_iterfor.h,v 1. 0 1996-05-17 10:59:40stobbe Exp $2 // $Id: fac_iterfor.h,v 1.1 1996-07-08 08:18:49 stobbe Exp $ 3 3 4 4 #ifndef INCL_ITERFOR_H … … 7 7 /* 8 8 $Log: not supported by cvs2svn $ 9 Revision 1.0 1996/05/17 10:59:40 stobbe 10 Initial revision 11 9 12 */ 10 13 … … 15 18 private: 16 19 int MAX; 20 int FROM; 21 int TO; 17 22 int N; 18 23 bool last; … … 21 26 void fill ( int from, int n ); 22 27 public: 23 IteratedFor( int n, int max );28 IteratedFor( int from, int to, int max ); 24 29 IteratedFor( const IteratedFor & ); 25 30 ~IteratedFor(); 26 31 IteratedFor& operator= ( const IteratedFor & ); 27 int n() const { return N; } 32 int from() const { return FROM; } 33 int to() const { return TO; } 34 int n() const { return N; }; 28 35 int max() const { return MAX; } 29 36 void nextiteration();
Note: See TracChangeset
for help on using the changeset viewer.