5a42e15c4a
Squashed messages from 9 commits: 9. Properties now uses PropertyFamily and contained classes. Fetching,seting,clearing properties can be done with PropertyFamilyKey or PropertyTypeKey. Hierarchy of newly added clases is: Vertices -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags} Edges -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags} PropertyFamilyKey -> PropertyType PropertyTypeKey -> PropertyType PropertyType t0,t1; let t0!=t1 be true let t0.family==t1.family be true then next is true PropertyTypeKey{&t0}!=PropertyTypeKey{&t1} PropertyFamilyKey{&t0}==PropertyFamilyKey{&t1} PropertyFamilyKey{&t0}==PropertyTypeKey{&t1} PropertyTypeKey{&t0}==PropertyFamilyKey{&t1} 8. Intermedate commit. Noticed that integration queries throw SEGFAULT. 7. Defined interface for indexes. Fixed three memory leaks. Fixed integration_queries test which now passes. 6. Commit which return Xorshift128plus to valid shape. 5. Tmp commit. 4. Label Index is compiling. 3. tmp 2. Vertex::Accessor now updates Label index. 1. Applied changes for code review.
75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "utils/option.hpp"
|
|
|
|
namespace iter
|
|
{
|
|
|
|
// Class which wraps iterator with next() into c++ iterator.
|
|
// T - type of return value
|
|
// I - iterator type
|
|
template <class T, class I>
|
|
class RangeIterator
|
|
{
|
|
|
|
public:
|
|
RangeIterator() : iter(Option<I>()), value(Option<T>()){};
|
|
|
|
RangeIterator(I &&iter)
|
|
: value(iter.next()), iter(Option<I>(std::move(iter)))
|
|
{
|
|
}
|
|
|
|
T &operator*()
|
|
{
|
|
assert(value.is_present());
|
|
return value.get();
|
|
}
|
|
|
|
T *operator->()
|
|
{
|
|
assert(value.is_present());
|
|
return &value.get();
|
|
}
|
|
|
|
operator T &()
|
|
{
|
|
assert(value.is_present());
|
|
return value.get();
|
|
}
|
|
|
|
RangeIterator &operator++()
|
|
{
|
|
assert(iter.is_present());
|
|
value = iter.get().next();
|
|
return (*this);
|
|
}
|
|
|
|
RangeIterator &operator++(int) { return operator++(); }
|
|
|
|
friend bool operator==(const RangeIterator &a, const RangeIterator &b)
|
|
{
|
|
return a.value.is_present() == b.value.is_present();
|
|
}
|
|
|
|
friend bool operator!=(const RangeIterator &a, const RangeIterator &b)
|
|
{
|
|
return !(a == b);
|
|
}
|
|
|
|
private:
|
|
Option<I> iter;
|
|
Option<T> value;
|
|
};
|
|
|
|
template <class I>
|
|
auto make_range_iterator(I &&iter)
|
|
{
|
|
// Because function isn't receving or in any way using type T from
|
|
// RangeIterator compiler can't deduce it thats way there is decltype in
|
|
// construction of RangeIterator. Resoulting type of iter.next().take() is
|
|
// T.
|
|
return RangeIterator<decltype(iter.next().take()), I>(std::move(iter));
|
|
}
|
|
}
|