condition.h
1 /*
2  * <one line to give the program's name and a brief idea of what it does.>
3  * Copyright (C) 2023 Jose F Rivas C <josefelixrc7@gmail.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef NAF_QUERY_CONDITION
20 #define NAF_QUERY_CONDITION
21 
22 
23 #include "query/results.h"
24 #include "tools/output_logger.h"
25 
26 
27 namespace NAF
28 {
29  namespace Query
30  {
31  enum class ConditionType;
32  template <typename T> class Condition;
33  }
34 }
35 
36 
37 enum class NAF::Query::ConditionType
38 {
39  kWarning
40  ,kError
41 };
42 
43 template <typename T> class NAF::Query::Condition
44 {
45  public:
46  using Ptr = std::shared_ptr<Condition>;
47  using Functor = std::function<bool(T)>;
48 
49  Condition(std::string identifier, ConditionType type, Functor functor);
50 
51  ConditionType get_type() const { return type_; }
52  std::string get_identifier() const { return identifier_; }
53  Functor& get_functor()
54  {
55  auto& var = functor_;
56  return var;
57  }
58 
59  void set_identifier(std::string identifier) { identifier_ = identifier; }
60  void set_type(ConditionType type) { type_ = type; }
61  void set_functor(Functor functor) { functor_ = functor; }
62 
63  bool VerifyCondition_(T t);
64 
65  private:
66  std::string identifier_;
67  ConditionType type_;
68  Functor functor_;
69 };
70 
71 template <typename T> NAF::Query::Condition<T>::Condition(std::string identifier, ConditionType type, Functor functor) :
72  identifier_(identifier)
73  ,type_(type)
74  ,functor_(functor)
75 {
76 
77 }
78 
79 template <typename T> bool NAF::Query::Condition<T>::VerifyCondition_(T t)
80 {
81  return functor_(t);
82 }
83 
84 #endif // NAF_QUERY_CONDITION
Definition: condition.h:44