Class filter

Synopsis

#include <include/flecs/addons/cpp/filter.hpp>

template<typename ... Components>
class filter : public filter_base

Description

No description yet.

Methods

filter overload
each
iter
operator= overload

Source

Lines 116-173 in include/flecs/addons/cpp/filter.hpp.

template<typename ... Components>
class filter : public filter_base {
    using Terms = typename _::term_ptrs<Components...>::array;

public:
    filter() { }

    filter(world_t *world, filter_t *f)
        : filter_base(world, f) { }

    explicit filter(const world& world, const char *expr = nullptr) 
        : filter_base(world.c_ptr())
    {
        auto qb = world.filter_builder<Components ...>()
            .expr(expr);

        if (!expr) {
            qb.substitute_default();
        }

        flecs::filter_t f = qb;
        ecs_filter_move(&m_filter, &f);
        m_filter_ptr = &m_filter;
    }

    filter(const filter& obj) : filter_base(obj) { }

    filter& operator=(const filter& obj) {
        *this = obj;
        return *this;
    }

    filter(filter&& obj) : filter_base(std::move(obj)) { }

    filter& operator=(filter&& obj) {
        filter_base(std::move(obj));
        return *this;
    }

    template <typename Func>
    void each(Func&& func) const {
        iterate<_::each_invoker>(std::forward<Func>(func), ecs_filter_next);
    } 

    template <typename Func>
    void iter(Func&& func) const { 
        iterate<_::iter_invoker>(std::forward<Func>(func), ecs_filter_next);
    }

private:
    template < template<typename Func, typename ... Comps> class Invoker, typename Func, typename NextFunc, typename ... Args>
    void iterate(Func&& func, NextFunc next, Args &&... args) const {
        ecs_iter_t it = ecs_filter_iter(m_world, m_filter_ptr);
        while (next(&it, std::forward<Args>(args)...)) {
            Invoker<Func, Components...>(std::move(func)).invoke(&it);
        }
    }
};