diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-04-17 05:22:20 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-04-17 05:22:20 +0000 |
commit | 3b880d8aca618f2a288826543bc8ac51ccd0bee7 (patch) | |
tree | df0f14cf14f8eec7f75d4e65a35ba510fa23ef7f /src | |
parent | 44057a75ef001bfd1919e2169ec3f7f355d14c20 (diff) | |
download | libbu++-3b880d8aca618f2a288826543bc8ac51ccd0bee7.tar.gz libbu++-3b880d8aca618f2a288826543bc8ac51ccd0bee7.tar.bz2 libbu++-3b880d8aca618f2a288826543bc8ac51ccd0bee7.tar.xz libbu++-3b880d8aca618f2a288826543bc8ac51ccd0bee7.zip |
More updates to the Bu::List::iterator and Bu::List::const_iterator, assignemnt
now works correctly, and they don't worry about which list they're assosiated
with. Better errors too.
Diffstat (limited to '')
-rw-r--r-- | src/list.h | 100 |
1 files changed, 36 insertions, 64 deletions
@@ -288,30 +288,20 @@ namespace Bu | |||
288 | friend class List<value, cmpfunc, valuealloc, linkalloc>; | 288 | friend class List<value, cmpfunc, valuealloc, linkalloc>; |
289 | private: | 289 | private: |
290 | Link *pLink; | 290 | Link *pLink; |
291 | MyType *pList; | ||
292 | bool bOffFront; | ||
293 | iterator( MyType *pList ) : | ||
294 | pLink( NULL ), | ||
295 | pList( pList ) | ||
296 | { | ||
297 | } | ||
298 | 291 | ||
299 | iterator( Link *pLink, MyType *pList ) : | 292 | iterator( Link *pLink ) : |
300 | pLink( pLink ), | 293 | pLink( pLink ) |
301 | pList( pList ) | ||
302 | { | 294 | { |
303 | } | 295 | } |
304 | 296 | ||
305 | public: | 297 | public: |
306 | iterator() : | 298 | iterator() : |
307 | pLink( NULL ), | 299 | pLink( NULL ) |
308 | pList( NULL ) | ||
309 | { | 300 | { |
310 | } | 301 | } |
311 | 302 | ||
312 | iterator( const iterator &i ) : | 303 | iterator( const iterator &i ) : |
313 | pLink( i.pLink ), | 304 | pLink( i.pLink ) |
314 | pList( i.pList ) | ||
315 | { | 305 | { |
316 | } | 306 | } |
317 | 307 | ||
@@ -376,40 +366,36 @@ namespace Bu | |||
376 | iterator &operator++() | 366 | iterator &operator++() |
377 | { | 367 | { |
378 | if( pLink == NULL ) | 368 | if( pLink == NULL ) |
379 | pLink = (bOffFront)?(pList->pFirst):(NULL); | 369 | throw Bu::ExceptionBase( |
380 | else | 370 | "Attempt to iterate past end of list."); |
381 | pLink = pLink->pNext; | 371 | pLink = pLink->pNext; |
382 | bOffFront = false; | ||
383 | return *this; | 372 | return *this; |
384 | } | 373 | } |
385 | 374 | ||
386 | iterator &operator--() | 375 | iterator &operator--() |
387 | { | 376 | { |
388 | if( pLink == NULL ) | 377 | if( pLink == NULL ) |
389 | pLink = (bOffFront)?(NULL):(pList->pLast); | 378 | throw Bu::ExceptionBase( |
390 | else | 379 | "Attempt to iterate past begining of list."); |
391 | pLink = pLink->pPrev; | 380 | pLink = pLink->pPrev; |
392 | bOffFront = true; | ||
393 | return *this; | 381 | return *this; |
394 | } | 382 | } |
395 | 383 | ||
396 | iterator &operator++( int ) | 384 | iterator &operator++( int ) |
397 | { | 385 | { |
398 | if( pLink == NULL ) | 386 | if( pLink == NULL ) |
399 | pLink = (bOffFront)?(pList->pFirst):(NULL); | 387 | throw Bu::ExceptionBase( |
400 | else | 388 | "Attempt to iterate past end of list."); |
401 | pLink = pLink->pNext; | 389 | pLink = pLink->pNext; |
402 | bOffFront = false; | ||
403 | return *this; | 390 | return *this; |
404 | } | 391 | } |
405 | 392 | ||
406 | iterator &operator--( int ) | 393 | iterator &operator--( int ) |
407 | { | 394 | { |
408 | if( pLink == NULL ) | 395 | if( pLink == NULL ) |
409 | pLink = (bOffFront)?(NULL):(pList->pLast); | 396 | throw Bu::ExceptionBase( |
410 | else | 397 | "Attempt to iterate past begining of list."); |
411 | pLink = pLink->pPrev; | 398 | pLink = pLink->pPrev; |
412 | bOffFront = true; | ||
413 | return *this; | 399 | return *this; |
414 | } | 400 | } |
415 | 401 | ||
@@ -443,30 +429,20 @@ namespace Bu | |||
443 | friend class List<value, cmpfunc, valuealloc, linkalloc>; | 429 | friend class List<value, cmpfunc, valuealloc, linkalloc>; |
444 | private: | 430 | private: |
445 | Link *pLink; | 431 | Link *pLink; |
446 | const MyType *pList; | ||
447 | bool bOffFront; | ||
448 | const_iterator( const MyType *pList ) : | ||
449 | pLink( NULL ), | ||
450 | pList( pList ) | ||
451 | { | ||
452 | } | ||
453 | 432 | ||
454 | const_iterator( Link *pLink, const MyType *pList ) : | 433 | const_iterator( Link *pLink ) : |
455 | pLink( pLink ), | 434 | pLink( pLink ) |
456 | pList( pList ) | ||
457 | { | 435 | { |
458 | } | 436 | } |
459 | 437 | ||
460 | public: | 438 | public: |
461 | const_iterator() : | 439 | const_iterator() : |
462 | pLink( NULL ), | 440 | pLink( NULL ) |
463 | pList( NULL ) | ||
464 | { | 441 | { |
465 | } | 442 | } |
466 | 443 | ||
467 | const_iterator( const iterator &i ) : | 444 | const_iterator( const iterator &i ) : |
468 | pLink( i.pLink ), | 445 | pLink( i.pLink ) |
469 | pList( i.pList ) | ||
470 | { | 446 | { |
471 | } | 447 | } |
472 | 448 | ||
@@ -503,40 +479,36 @@ namespace Bu | |||
503 | const_iterator &operator++() | 479 | const_iterator &operator++() |
504 | { | 480 | { |
505 | if( pLink == NULL ) | 481 | if( pLink == NULL ) |
506 | pLink = (bOffFront)?(pList->pFirst):(NULL); | 482 | throw Bu::ExceptionBase( |
507 | else | 483 | "Attempt to iterate past end of list."); |
508 | pLink = pLink->pNext; | 484 | pLink = pLink->pNext; |
509 | bOffFront = false; | ||
510 | return *this; | 485 | return *this; |
511 | } | 486 | } |
512 | 487 | ||
513 | const_iterator &operator--() | 488 | const_iterator &operator--() |
514 | { | 489 | { |
515 | if( pLink == NULL ) | 490 | if( pLink == NULL ) |
516 | pLink = (bOffFront)?(NULL):(pList->pLast); | 491 | throw Bu::ExceptionBase( |
517 | else | 492 | "Attempt to iterate past begining of list."); |
518 | pLink = pLink->pPrev; | 493 | pLink = pLink->pPrev; |
519 | bOffFront = true; | ||
520 | return *this; | 494 | return *this; |
521 | } | 495 | } |
522 | 496 | ||
523 | const_iterator &operator++( int ) | 497 | const_iterator &operator++( int ) |
524 | { | 498 | { |
525 | if( pLink == NULL ) | 499 | if( pLink == NULL ) |
526 | pLink = (bOffFront)?(pList->pFirst):(NULL); | 500 | throw Bu::ExceptionBase( |
527 | else | 501 | "Attempt to iterate past end of list."); |
528 | pLink = pLink->pNext; | 502 | pLink = pLink->pNext; |
529 | bOffFront = false; | ||
530 | return *this; | 503 | return *this; |
531 | } | 504 | } |
532 | 505 | ||
533 | const_iterator &operator--( int ) | 506 | const_iterator &operator--( int ) |
534 | { | 507 | { |
535 | if( pLink == NULL ) | 508 | if( pLink == NULL ) |
536 | pLink = (bOffFront)?(NULL):(pList->pLast); | 509 | throw Bu::ExceptionBase( |
537 | else | 510 | "Attempt to iterate past begining of list."); |
538 | pLink = pLink->pPrev; | 511 | pLink = pLink->pPrev; |
539 | bOffFront = true; | ||
540 | return *this; | 512 | return *this; |
541 | } | 513 | } |
542 | 514 | ||
@@ -569,7 +541,7 @@ namespace Bu | |||
569 | */ | 541 | */ |
570 | iterator begin() | 542 | iterator begin() |
571 | { | 543 | { |
572 | return iterator( pFirst, this ); | 544 | return iterator( pFirst ); |
573 | } | 545 | } |
574 | 546 | ||
575 | /** | 547 | /** |
@@ -578,7 +550,7 @@ namespace Bu | |||
578 | */ | 550 | */ |
579 | const_iterator begin() const | 551 | const_iterator begin() const |
580 | { | 552 | { |
581 | return const_iterator( pFirst, this ); | 553 | return const_iterator( pFirst ); |
582 | } | 554 | } |
583 | 555 | ||
584 | /** | 556 | /** |
@@ -588,7 +560,7 @@ namespace Bu | |||
588 | */ | 560 | */ |
589 | const iterator end() | 561 | const iterator end() |
590 | { | 562 | { |
591 | return iterator( NULL, this ); | 563 | return iterator( NULL ); |
592 | } | 564 | } |
593 | 565 | ||
594 | /** | 566 | /** |
@@ -598,7 +570,7 @@ namespace Bu | |||
598 | */ | 570 | */ |
599 | const const_iterator end() const | 571 | const const_iterator end() const |
600 | { | 572 | { |
601 | return const_iterator( NULL, this ); | 573 | return const_iterator( NULL ); |
602 | } | 574 | } |
603 | 575 | ||
604 | /** | 576 | /** |