2016-08-18 22:34:36 +08:00
|
|
|
#pragma once
|
|
|
|
|
2016-08-30 12:29:30 +08:00
|
|
|
#include "utils/iterator/count.hpp"
|
2016-08-18 22:34:36 +08:00
|
|
|
#include "utils/option.hpp"
|
|
|
|
|
2016-08-30 12:29:30 +08:00
|
|
|
class EdgeType;
|
|
|
|
|
2016-08-30 13:16:04 +08:00
|
|
|
namespace iter
|
|
|
|
{
|
|
|
|
template <class I, class OP>
|
|
|
|
auto make_map(I &&iter, OP &&op);
|
|
|
|
|
|
|
|
template <class I, class OP>
|
|
|
|
auto make_filter(I &&iter, OP &&op);
|
|
|
|
|
|
|
|
template <class I, class C>
|
|
|
|
void for_all(I &&iter, C &&consumer);
|
|
|
|
}
|
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
// Base iterator for next() kind iterator.
|
|
|
|
// T - type of return value
|
|
|
|
template <class T>
|
|
|
|
class IteratorBase
|
|
|
|
{
|
|
|
|
public:
|
2016-08-28 22:47:13 +08:00
|
|
|
virtual ~IteratorBase(){};
|
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
virtual Option<T> next() = 0;
|
2016-08-30 12:29:30 +08:00
|
|
|
|
|
|
|
virtual Count count() { return Count(0, ~((size_t)0)); }
|
|
|
|
|
|
|
|
template <class OP>
|
2016-08-30 13:16:04 +08:00
|
|
|
auto map(OP &&op)
|
|
|
|
{
|
|
|
|
return iter::make_map<decltype(std::move(*this)), OP>(std::move(*this),
|
|
|
|
std::move(op));
|
|
|
|
}
|
2016-08-30 12:29:30 +08:00
|
|
|
|
|
|
|
template <class OP>
|
2016-08-30 13:16:04 +08:00
|
|
|
auto filter(OP &&op)
|
|
|
|
{
|
|
|
|
return iter::make_filter<decltype(std::move(*this)), OP>(
|
|
|
|
std::move(*this), std::move(op));
|
|
|
|
}
|
2016-08-30 12:29:30 +08:00
|
|
|
|
|
|
|
// Maps with call to method to() and filters with call to fill.
|
2016-08-30 13:16:04 +08:00
|
|
|
auto to()
|
|
|
|
{
|
|
|
|
return map([](auto er) { return er.to(); }).fill();
|
|
|
|
}
|
2016-08-30 12:29:30 +08:00
|
|
|
|
|
|
|
// Filters with call to method fill()
|
2016-08-30 13:16:04 +08:00
|
|
|
auto fill()
|
|
|
|
{
|
|
|
|
return filter([](auto &ra) { return ra.fill(); });
|
|
|
|
}
|
2016-08-30 12:29:30 +08:00
|
|
|
|
|
|
|
// Filters with type
|
|
|
|
template <class TYPE>
|
2016-08-30 13:16:04 +08:00
|
|
|
auto type(TYPE const &type)
|
|
|
|
{
|
|
|
|
return filter([&](auto &ra) { return ra.edge_type() == type; });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filters out vertices which are connected.
|
|
|
|
auto isolated()
|
|
|
|
{
|
|
|
|
return filter([&](auto &ra) { return ra.isolated(); });
|
|
|
|
}
|
2016-08-30 12:29:30 +08:00
|
|
|
|
|
|
|
// For all items calls OP.
|
|
|
|
template <class OP>
|
2016-08-30 13:16:04 +08:00
|
|
|
void for_all(OP &&op)
|
|
|
|
{
|
|
|
|
iter::for_all(std::move(*this), std::move(op));
|
|
|
|
}
|
2016-08-18 22:34:36 +08:00
|
|
|
};
|