From aaeaa599a14642e916bbd8a32a208ee96a26eaac Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 2 Apr 2009 15:00:14 +0000 Subject: Array iterators' validity testing was actually reversed. That was a serious problem. Also, arrays now have a formatter. --- src/array.h | 36 ++++++++++++++++++++++++++++++++---- src/unit/array.unit | 2 ++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/array.h b/src/array.h index e717fd5..ca4ec21 100644 --- a/src/array.h +++ b/src/array.h @@ -245,14 +245,19 @@ namespace Bu return src[iPos]; } + long getIndex() const + { + return iPos; + } + operator bool() const { - return iPos < 0; + return iPos >= 0; } bool isValid() const { - return iPos < 0; + return iPos >= 0; } } iterator; @@ -337,15 +342,20 @@ namespace Bu "Cannot dereference finished iterator."); return src[iPos]; } + + long getIndex() const + { + return iPos; + } operator bool() const { - return iPos < 0; + return iPos >= 0; } bool isValid() const { - return iPos < 0; + return iPos >= 0; } } const_iterator; @@ -414,6 +424,24 @@ namespace Bu long iSize; long iCapacity; }; + + class Formatter; + Formatter &operator<<( Formatter &rOut, char *sStr ); + Formatter &operator<<( Formatter &rOut, signed char c ); + template + Formatter &operator<<( Formatter &f, const Bu::Array &a ) + { + f << '['; + for( typename Bu::Array::const_iterator i = a.begin(); i; i++ ) + { + if( i != a.begin() ) + f << ", "; + f << *i; + } + f << ']'; + + return f; + } } #endif diff --git a/src/unit/array.unit b/src/unit/array.unit index d5fc573..3a777d3 100644 --- a/src/unit/array.unit +++ b/src/unit/array.unit @@ -32,11 +32,13 @@ int j = 0; for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) unitTest( (*i) == j++ ); + unitTest( j == 10 ); const Bu::Array &ci = ai; j = 0; for( Bu::Array::const_iterator i = ci.begin(); i != ci.end(); i++ ) unitTest( (*i) == j++ ); + unitTest( j == 10 ); } {%iterate2} -- cgit v1.2.3