summaryrefslogtreecommitdiff
path: root/src/array.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-04-02 15:00:14 +0000
committerMike Buland <eichlan@xagasoft.com>2009-04-02 15:00:14 +0000
commitaaeaa599a14642e916bbd8a32a208ee96a26eaac (patch)
treedd96f81051b43e398059c9463cfd1997e08d217a /src/array.h
parente9e5da32b2e154698482b7ec6b7ab2098cd849c8 (diff)
downloadlibbu++-aaeaa599a14642e916bbd8a32a208ee96a26eaac.tar.gz
libbu++-aaeaa599a14642e916bbd8a32a208ee96a26eaac.tar.bz2
libbu++-aaeaa599a14642e916bbd8a32a208ee96a26eaac.tar.xz
libbu++-aaeaa599a14642e916bbd8a32a208ee96a26eaac.zip
Array iterators' validity testing was actually reversed. That was a serious
problem. Also, arrays now have a formatter.
Diffstat (limited to 'src/array.h')
-rw-r--r--src/array.h36
1 files changed, 32 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
245 return src[iPos]; 245 return src[iPos];
246 } 246 }
247 247
248 long getIndex() const
249 {
250 return iPos;
251 }
252
248 operator bool() const 253 operator bool() const
249 { 254 {
250 return iPos < 0; 255 return iPos >= 0;
251 } 256 }
252 257
253 bool isValid() const 258 bool isValid() const
254 { 259 {
255 return iPos < 0; 260 return iPos >= 0;
256 } 261 }
257 } iterator; 262 } iterator;
258 263
@@ -337,15 +342,20 @@ namespace Bu
337 "Cannot dereference finished iterator."); 342 "Cannot dereference finished iterator.");
338 return src[iPos]; 343 return src[iPos];
339 } 344 }
345
346 long getIndex() const
347 {
348 return iPos;
349 }
340 350
341 operator bool() const 351 operator bool() const
342 { 352 {
343 return iPos < 0; 353 return iPos >= 0;
344 } 354 }
345 355
346 bool isValid() const 356 bool isValid() const
347 { 357 {
348 return iPos < 0; 358 return iPos >= 0;
349 } 359 }
350 } const_iterator; 360 } const_iterator;
351 361
@@ -414,6 +424,24 @@ namespace Bu
414 long iSize; 424 long iSize;
415 long iCapacity; 425 long iCapacity;
416 }; 426 };
427
428 class Formatter;
429 Formatter &operator<<( Formatter &rOut, char *sStr );
430 Formatter &operator<<( Formatter &rOut, signed char c );
431 template<typename value>
432 Formatter &operator<<( Formatter &f, const Bu::Array<value> &a )
433 {
434 f << '[';
435 for( typename Bu::Array<value>::const_iterator i = a.begin(); i; i++ )
436 {
437 if( i != a.begin() )
438 f << ", ";
439 f << *i;
440 }
441 f << ']';
442
443 return f;
444 }
417} 445}
418 446
419#endif 447#endif