JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
Function_State.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 08/05/2019.
3 //
4 
5 #ifndef JODA_FUNCTION_STATE_H
6 #define JODA_FUNCTION_STATE_H
7 
8 #include "Load_State.h"
9 #include "Query_State.h"
10 #include "Store_State.h"
12 enum Atom_Value {
18  ATOM_NULL
19 };
20 
21 struct functionState {
22  /*
23  * LOAD Master
24  */
25  template <typename Input>
26  inline functionState(const Input &in, loadState &qs) {}
27 
28  template <typename Input>
29  inline void success(const Input &in, loadState &qs) {
30  bool b = false;
31  auto prov = createFunc(in);
32  assert(prov != nullptr && "May not be null");
33  b = qs.putValProv(std::move(prov));
34  assert(b && "State should not be full");
35  }
36 
37  /*
38  * STORE Master
39  */
40  template <typename Input>
41  inline functionState(const Input &in, storeState &qs) {}
42 
43  template <typename Input>
44  inline void success(const Input &in, storeState &qs) {
45  bool b = false;
46  auto prov = createFunc(in);
47  assert(prov != nullptr && "May not be null");
48  b = qs.putValProv(std::move(prov));
49  assert(b && "State should not be full");
50  }
51 
52  /*
53  * Choose Master
54  */
55  template <typename Input>
56  inline functionState(const Input &in, chooseState &qs) {}
57 
58  template <typename Input>
59  inline void success(const Input &in, chooseState &qs) {
60  bool b = false;
61  auto prov = createFunc(in);
62  assert(prov != nullptr && "May not be null");
63  b = qs.putValProv(std::move(prov));
64  assert(b && "State should not be full");
65  }
66 
67  /*
68  * AS Master
69  */
70  template <typename Input>
71  inline functionState(const Input &in, asState &qs) {}
72 
73  template <typename Input>
74  inline void success(const Input &in, asState &qs) {
75  bool b = false;
76  auto prov = createFunc(in);
77  assert(prov != nullptr && "May not be null");
78  b = qs.putValProv(std::move(prov));
79  assert(b && "State should not be full");
80  }
81 
82  /*
83  * AGG Master
84  */
85  template <typename Input>
86  inline functionState(const Input &in, aggState &qs) {}
87 
88  template <typename Input>
89  inline void success(const Input &in, aggState &qs) {
90  bool b = false;
91  auto prov = createFunc(in);
92  assert(prov != nullptr && "May not be null");
93  b = qs.putValProv(std::move(prov));
94  assert(b && "State should not be full");
95  }
96  /*
97  * Function Master
98  */
99  template <typename Input>
100  inline functionState(const Input &in, functionState &qs) {}
101 
102  template <typename Input>
103  inline void success(const Input &in, functionState &qs) {
104  bool b = false;
105  auto prov = createFunc(in);
106  assert(prov != nullptr && "May not be null");
107  b = qs.putValProv(std::move(prov));
108  assert(b && "State should not be full");
109  }
110 
111  inline bool putValProv(std::unique_ptr<joda::query::IValueProvider> &&val) {
112  assert(val != nullptr && "Should not pass nullptr");
113  if (val == nullptr) return false;
114  params.push_back(std::move(val));
115  return true;
116  }
117 
118  template <typename Input>
119  inline std::unique_ptr<joda::query::IValueProvider> createFunc(
120  const Input &in) {
121  std::unique_ptr<joda::query::IValueProvider> prov = nullptr;
122  try {
123  if (factory != nullptr) {
124  prov = factory(std::move(params));
125  DCHECK(prov != nullptr)
126  << "prov should not be null, except for thrown parsing exceptions";
127  } else if (atom != NO_ATOM) {
128  assert(params.size() == 1);
129  prov = std::move(params.front());
130  } else {
131  DCHECK(false)
132  << "There should always be either a atom function or factory";
133  throw tao::pegtl::parse_error("Unexpected error during query parsing",
134  in);
135  }
136 
138  throw tao::pegtl::parse_error(e.what(), in);
139  }
140  return prov;
141  }
142 
144  std::function<std::unique_ptr<joda::query::IValueProvider>(
145  std::vector<std::unique_ptr<joda::query::IValueProvider>> &&)>
146  factory = nullptr;
147  std::vector<std::unique_ptr<joda::query::IValueProvider>> params;
148 };
149 } // namespace joda::queryparsing::grammar
150 #endif // JODA_FUNCTION_STATE_H
Definition: IValueProvider.h:46
virtual const char * what() const
Definition: IValueProvider.h:49
Atom_Value
Definition: Function_State.h:12
@ ATOM_BOOL
Definition: Function_State.h:16
@ ATOM_NUMBER
Definition: Function_State.h:15
@ ATOM_NULL
Definition: Function_State.h:18
@ NO_ATOM
Definition: Function_State.h:13
@ ATOM_POINTER
Definition: Function_State.h:17
@ ATOM_STRING
Definition: Function_State.h:14
Definition: Agg_State.h:24
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Agg_State.h:37
Definition: As_State.h:17
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: As_State.h:36
Definition: Choose_State.h:13
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Choose_State.h:42
Definition: Function_State.h:21
void success(const Input &in, loadState &qs)
Definition: Function_State.h:29
std::unique_ptr< joda::query::IValueProvider > createFunc(const Input &in)
Definition: Function_State.h:119
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Function_State.h:111
functionState(const Input &in, storeState &qs)
Definition: Function_State.h:41
Atom_Value atom
Definition: Function_State.h:143
void success(const Input &in, aggState &qs)
Definition: Function_State.h:89
functionState(const Input &in, asState &qs)
Definition: Function_State.h:71
void success(const Input &in, asState &qs)
Definition: Function_State.h:74
void success(const Input &in, storeState &qs)
Definition: Function_State.h:44
void success(const Input &in, functionState &qs)
Definition: Function_State.h:103
std::function< std::unique_ptr< joda::query::IValueProvider > std::vector< std::unique_ptr< joda::query::IValueProvider > > &&)> factory
Definition: Function_State.h:146
functionState(const Input &in, chooseState &qs)
Definition: Function_State.h:56
std::vector< std::unique_ptr< joda::query::IValueProvider > > params
Definition: Function_State.h:147
void success(const Input &in, chooseState &qs)
Definition: Function_State.h:59
functionState(const Input &in, functionState &qs)
Definition: Function_State.h:100
functionState(const Input &in, aggState &qs)
Definition: Function_State.h:86
functionState(const Input &in, loadState &qs)
Definition: Function_State.h:26
Definition: Load_State.h:23
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Load_State.h:39
Definition: Store_State.h:11
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Store_State.h:23