mirror of https://github.com/YosysHQ/yosys.git
Merge pull request #1219 from jakobwenzel/objIterator
made ObjectIterator comply with Iterator Interface
This commit is contained in:
commit
2bdd8003d3
|
@ -420,8 +420,12 @@ namespace RTLIL
|
|||
// It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
|
||||
|
||||
template<typename T>
|
||||
struct ObjIterator
|
||||
{
|
||||
struct ObjIterator {
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = T*;
|
||||
using reference = T&;
|
||||
typename dict<RTLIL::IdString, T>::iterator it;
|
||||
dict<RTLIL::IdString, T> *list_p;
|
||||
int *refcount_p;
|
||||
|
@ -474,13 +478,25 @@ namespace RTLIL
|
|||
return it != other.it;
|
||||
}
|
||||
|
||||
inline void operator++() {
|
||||
|
||||
inline bool operator==(const RTLIL::ObjIterator<T> &other) const {
|
||||
return !(*this != other);
|
||||
}
|
||||
|
||||
inline ObjIterator<T>& operator++() {
|
||||
log_assert(list_p != nullptr);
|
||||
if (++it == list_p->end()) {
|
||||
(*refcount_p)--;
|
||||
list_p = nullptr;
|
||||
refcount_p = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const ObjIterator<T> operator++(int) {
|
||||
ObjIterator<T> result(*this);
|
||||
++(*this);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
|
Loading…
Reference in New Issue