diff options
author | Mark Spruiell <mes@zeroc.com> | 2003-02-03 20:14:17 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2003-02-03 20:14:17 +0000 |
commit | b3f6eb515322fbee178b3a78b557b273313ab48d (patch) | |
tree | c609afd3daaa479a3eab44d26e6ad8becd9c6e4d /cpp | |
parent | added ice attribute to ant tasks (diff) | |
download | ice-b3f6eb515322fbee178b3a78b557b273313ab48d.tar.bz2 ice-b3f6eb515322fbee178b3a78b557b273313ab48d.tar.xz ice-b3f6eb515322fbee178b3a78b557b273313ab48d.zip |
fix iterator equality operator
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Freeze/Map.h | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/cpp/include/Freeze/Map.h b/cpp/include/Freeze/Map.h index 2ba36e96a28..1e762596584 100644 --- a/cpp/include/Freeze/Map.h +++ b/cpp/include/Freeze/Map.h @@ -44,9 +44,8 @@ struct DBIteratorBase // restriction that it's only possible to explicitely write back into // the database. // -// Equality and inequality are based on whether the iterator is -// "valid". An valid iterator contains a valid database and cursor -// pointer, otherwise the iterator is invalid. +// Two iterators are equal if they use the same database and their +// current records have the same key. // // TODO: It's possible to implement bidirectional iterators, if // necessary. @@ -110,11 +109,29 @@ public: bool operator==(const DBIterator& rhs) const { - if(!_db && !rhs._db) - { - return true; - } - return false; + if(_db && _db == rhs._db && _cursor && rhs._cursor) + { + Freeze::Key k1, k2; + Freeze::Value v; + try + { + _cursor->curr(k1, v); + rhs._cursor->curr(k2, v); + return k1 == k2; + } + catch(const DBNotFoundException&) + { + return false; + } + } + else if(!_db && !rhs._db) + { + return true; + } + else + { + return false; + } } bool operator!=(const DBIterator& rhs) const @@ -305,11 +322,29 @@ public: bool operator==(const ConstDBIterator& rhs) { - if(!_db && !rhs._db) - { - return true; - } - return false; + if(_db && _db == rhs._db && _cursor && rhs._cursor) + { + Freeze::Key k1, k2; + Freeze::Value v; + try + { + _cursor->curr(k1, v); + rhs._cursor->curr(k2, v); + return k1 == k2; + } + catch(const DBNotFoundException&) + { + return false; + } + } + else if(!_db && !rhs._db) + { + return true; + } + else + { + return false; + } } bool operator!=(const ConstDBIterator& rhs) |