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.
|
// It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
|
||||||
|
|
||||||
template<typename T>
|
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;
|
typename dict<RTLIL::IdString, T>::iterator it;
|
||||||
dict<RTLIL::IdString, T> *list_p;
|
dict<RTLIL::IdString, T> *list_p;
|
||||||
int *refcount_p;
|
int *refcount_p;
|
||||||
|
@ -474,13 +478,25 @@ namespace RTLIL
|
||||||
return it != other.it;
|
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);
|
log_assert(list_p != nullptr);
|
||||||
if (++it == list_p->end()) {
|
if (++it == list_p->end()) {
|
||||||
(*refcount_p)--;
|
(*refcount_p)--;
|
||||||
list_p = nullptr;
|
list_p = nullptr;
|
||||||
refcount_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 <stdexcept>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
Loading…
Reference in New Issue