AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
fluent.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <vector>
23#include <functional>
24#include <limits>
25#include <cstdint>
26
27
28namespace anch {
29
38 template<typename T, template<typename> typename C>
39 class Fluent {
40 // Attributes +
41 private:
43 C<T>* _internalValues;
44
46 C<T>& _values;
47
49 std::vector<std::function<bool(const T&)>> _filters;
50
52 uint64_t _skip;
53
55 uint64_t _limit;
56
58 uint64_t _index;
59
61 uint64_t _treated;
62
64 Fluent<T,C>* _next;
65 // Attributes -
66
67 // Constructors +
68 public:
72 Fluent() = delete;
73
79 Fluent(C<T>& container);
80
84 Fluent(const Fluent& other);
85
89 Fluent(Fluent&& other);
90 // Constructors -
91
92 // Destructor +
93 public:
97 virtual ~Fluent();
98 // Destructor -
99
100 // Methods +
101 public:
109 Fluent& filter(std::function<bool(const T&)> predicate);
110
118 Fluent& skip(uint64_t skip);
119
127 Fluent& limit(uint64_t limit);
128
134 Fluent& concat(Fluent<T,C>& other) noexcept;
135
141 bool allMatch(std::function<bool(const T&)> predicate);
142
148 bool anyMatch(std::function<bool(const T&)> predicate);
149
155 bool noneMatch(std::function<bool(const T&)> predicate);
156
162 void forEach(std::function<void(T&)> action);
163
169 template<typename U>
170 Fluent<U,std::vector> map(std::function<U(const T&)> mapper);
171
178 template<typename D>
179 void collect(D& container, std::function<void(D&,const T&)> collector);
180
188 template<typename D>
189 D collect(std::function<void(D&,const T&)> collector);
190
197 template<typename D, typename R>
198 void collect(D& container, R(D::*collector)(const T&));
199
207 template<typename D, typename R>
208 D collect(R(D::*collector)(const T&));
209
210 private:
217 void forEach(std::function<void(T&)> action, const std::vector<std::function<bool(const T&)>>& filters);
218
225 bool allMatch(std::function<bool(const T&)> predicate, const std::vector<std::function<bool(const T&)>>& filters);
226
233 bool anyMatch(std::function<bool(const T&)> predicate, const std::vector<std::function<bool(const T&)>>& filters);
234
241 bool noneMatch(std::function<bool(const T&)> predicate, const std::vector<std::function<bool(const T&)>>& filters);
242
248 bool limitReached() const;
249 // Methods -
250
251 };
252
253}
254
255#include "impl/fluent.hpp"
Fluent & limit(uint64_t limit)
bool anyMatch(std::function< bool(const T &)> predicate)
void collect(D &container, std::function< void(D &, const T &)> collector)
D collect(std::function< void(D &, const T &)> collector)
Fluent & skip(uint64_t skip)
Fluent & filter(std::function< bool(const T &)> predicate)
Fluent(C< T > &container)
void collect(D &container, R(D::*collector)(const T &))
D collect(R(D::*collector)(const T &))
Fluent(const Fluent &other)
Fluent()=delete
Fluent & concat(Fluent< T, C > &other) noexcept
virtual ~Fluent()
Fluent< U, std::vector > map(std::function< U(const T &)> mapper)
void forEach(std::function< void(T &)> action)
bool noneMatch(std::function< bool(const T &)> predicate)
Fluent(Fluent &&other)
bool allMatch(std::function< bool(const T &)> predicate)
AnCH framework base namespace.
Definition app.hpp:28