mirror of https://github.com/YosysHQ/yosys.git
made ObjectIterator extend std::iterator
this makes it possible to use std algorithms on them
This commit is contained in:
parent
a66f17b6a7
commit
25685a9a5b
|
@ -420,7 +420,11 @@ 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 : public std::iterator<std::forward_iterator_tag,
|
||||||
|
T,
|
||||||
|
ptrdiff_t,
|
||||||
|
T *,
|
||||||
|
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;
|
||||||
|
@ -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