mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
GH-1546: Make DictIterator() public, add copy/move operators
This commit is contained in:
parent
31f73f6e92
commit
6ab317f7bd
2 changed files with 90 additions and 3 deletions
82
src/Dict.cc
82
src/Dict.cc
|
@ -265,6 +265,11 @@ TEST_CASE("dict new iteration")
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDict<uint32_t>::iterator it;
|
||||||
|
it = dict.begin();
|
||||||
|
it = dict.end();
|
||||||
|
PDict<uint32_t>::iterator it2 = it;
|
||||||
|
|
||||||
CHECK(count == 2);
|
CHECK(count == 2);
|
||||||
|
|
||||||
delete key;
|
delete key;
|
||||||
|
@ -1557,10 +1562,13 @@ DictIterator::DictIterator(const Dictionary* d, detail::DictEntry* begin, detail
|
||||||
}
|
}
|
||||||
|
|
||||||
DictIterator::~DictIterator()
|
DictIterator::~DictIterator()
|
||||||
|
{
|
||||||
|
if ( dict )
|
||||||
{
|
{
|
||||||
assert(dict->num_iterators > 0);
|
assert(dict->num_iterators > 0);
|
||||||
dict->num_iterators--;
|
dict->num_iterators--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DictIterator& DictIterator::operator++()
|
DictIterator& DictIterator::operator++()
|
||||||
{
|
{
|
||||||
|
@ -1574,6 +1582,80 @@ DictIterator& DictIterator::operator++()
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DictIterator::DictIterator(const DictIterator& that)
|
||||||
|
{
|
||||||
|
if ( this == &that )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( dict )
|
||||||
|
{
|
||||||
|
assert(dict->num_iterators > 0);
|
||||||
|
dict->num_iterators--;
|
||||||
|
}
|
||||||
|
|
||||||
|
dict = that.dict;
|
||||||
|
curr = that.curr;
|
||||||
|
end = that.end;
|
||||||
|
dict->num_iterators++;
|
||||||
|
}
|
||||||
|
|
||||||
|
DictIterator& DictIterator::operator=(const DictIterator& that)
|
||||||
|
{
|
||||||
|
if ( this == &that )
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
if ( dict )
|
||||||
|
{
|
||||||
|
assert(dict->num_iterators > 0);
|
||||||
|
dict->num_iterators--;
|
||||||
|
}
|
||||||
|
|
||||||
|
dict = that.dict;
|
||||||
|
curr = that.curr;
|
||||||
|
end = that.end;
|
||||||
|
dict->num_iterators++;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
DictIterator::DictIterator(DictIterator&& that)
|
||||||
|
{
|
||||||
|
if ( this == &that )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( dict )
|
||||||
|
{
|
||||||
|
assert(dict->num_iterators > 0);
|
||||||
|
dict->num_iterators--;
|
||||||
|
}
|
||||||
|
|
||||||
|
dict = that.dict;
|
||||||
|
curr = that.curr;
|
||||||
|
end = that.end;
|
||||||
|
|
||||||
|
that.dict = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
DictIterator& DictIterator::operator=(DictIterator&& that)
|
||||||
|
{
|
||||||
|
if ( this == &that )
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
if ( dict )
|
||||||
|
{
|
||||||
|
assert(dict->num_iterators > 0);
|
||||||
|
dict->num_iterators--;
|
||||||
|
}
|
||||||
|
|
||||||
|
dict = that.dict;
|
||||||
|
curr = that.curr;
|
||||||
|
end = that.end;
|
||||||
|
|
||||||
|
that.dict = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -159,8 +159,14 @@ public:
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
using iterator_category = std::forward_iterator_tag;
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
|
||||||
|
DictIterator() = default;
|
||||||
~DictIterator();
|
~DictIterator();
|
||||||
|
|
||||||
|
DictIterator(const DictIterator& that);
|
||||||
|
DictIterator& operator=(const DictIterator& that);
|
||||||
|
DictIterator(DictIterator&& that);
|
||||||
|
DictIterator& operator=(DictIterator&& that);
|
||||||
|
|
||||||
reference operator*() { return *curr; }
|
reference operator*() { return *curr; }
|
||||||
pointer operator->() { return curr; }
|
pointer operator->() { return curr; }
|
||||||
|
|
||||||
|
@ -173,7 +179,6 @@ public:
|
||||||
private:
|
private:
|
||||||
friend class Dictionary;
|
friend class Dictionary;
|
||||||
|
|
||||||
DictIterator() = default;
|
|
||||||
DictIterator(const Dictionary* d, detail::DictEntry* begin, detail::DictEntry* end);
|
DictIterator(const Dictionary* d, detail::DictEntry* begin, detail::DictEntry* end);
|
||||||
|
|
||||||
Dictionary* dict = nullptr;
|
Dictionary* dict = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue