JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
Choose_State.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 08/05/2019.
3 //
4 
5 #ifndef JODA_CHOOSE_STATE_H
6 #define JODA_CHOOSE_STATE_H
7 
9 #include "Query_State.h"
10 
12 
13 struct chooseState {
14  template <typename Input>
15  inline chooseState(const Input &in, queryState &qs) {
16  comp = NONE;
17  }
18 
19  template <typename Input>
20  inline void success(const Input &in, queryState &qs) {
21  assert(valProv.first == nullptr);
22  assert(valProv.second == nullptr);
23  assert(ptr.empty());
24  if (preds.empty()) {
25  std::unique_ptr<joda::query::Predicate> pred =
26  std::make_unique<joda::query::ValToPredicate>(true);
27  qs.q->setPredicate(std::move(pred));
28  return;
29  }
30 
31  if (preds.top().second.empty()) {
32  std::unique_ptr<joda::query::Predicate> t =
33  std::make_unique<joda::query::ValToPredicate>(true);
34  preds.top().second.push_back(std::move(t));
35  }
36  assert(preds.top().second.size() == 1);
37  std::unique_ptr<joda::query::Predicate> tmp =
38  std::move(preds.top().second[0]);
39  qs.q->setPredicate(std::move(tmp));
40  }
41 
42  inline bool putValProv(std::unique_ptr<joda::query::IValueProvider> &&val) {
43  assert(val != nullptr && "Should not pass nullptr");
44  if (val == nullptr) return false;
45  if (valProv.first == nullptr) {
46  valProv.first = std::move(val);
47  return true;
48  }
49  if (valProv.second == nullptr) {
50  valProv.second = std::move(val);
51  return true;
52  }
53  assert(false && "Should not be full");
54  return false;
55  }
56 
58  std::pair<std::unique_ptr<joda::query::IValueProvider>,
59  std::unique_ptr<joda::query::IValueProvider>>
62  std::string ptr;
63 };
64 } // namespace joda::queryparsing::grammar
65 #endif // JODA_CHOOSE_STATE_H
Comparison
Definition: Query_State.h:38
@ NONE
Definition: Query_State.h:38
std::stack< std::pair< stackMod, std::vector< std::unique_ptr< joda::query::Predicate > > > > predStack
Definition: Query_State.h:43
Definition: Choose_State.h:13
chooseState(const Input &in, queryState &qs)
Definition: Choose_State.h:15
Comparison comp
Definition: Choose_State.h:61
void success(const Input &in, queryState &qs)
Definition: Choose_State.h:20
std::string ptr
Definition: Choose_State.h:62
std::pair< std::unique_ptr< joda::query::IValueProvider >, std::unique_ptr< joda::query::IValueProvider > > valProv
Definition: Choose_State.h:60
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Choose_State.h:42
predStack preds
Definition: Choose_State.h:57
Definition: Query_State.h:21
std::shared_ptr< joda::query::Query > q
Definition: Query_State.h:33