summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2003-02-03 20:14:17 +0000
committerMark Spruiell <mes@zeroc.com>2003-02-03 20:14:17 +0000
commitb3f6eb515322fbee178b3a78b557b273313ab48d (patch)
treec609afd3daaa479a3eab44d26e6ad8becd9c6e4d /cpp
parentadded ice attribute to ant tasks (diff)
downloadice-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.h61
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)