JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
Load_Actions.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 08/05/2019.
3 //
4 
5 #ifndef JODA_LOAD_ACTIONS_H
6 #define JODA_LOAD_ACTIONS_H
7 
9 #include "../grammar/Grammar.h"
10 #include "../states/States.h"
11 
14 
15 template <>
17  template <typename Input>
18  static void apply(const Input &in, loadState &state) {
19  state.loadVar = in.string();
20  }
21 };
22 
23 template <>
25  static void apply0(loadState &state) { state.source = DIRECTORY_SOURCE; }
26 };
27 
28 template <>
30  static void apply0(loadState &state) { state.source = FILE_SOURCE; }
31 };
32 
33 template <>
35  template <typename Input>
36  static void apply(const Input &in, loadState &state) {
37 #ifndef JODA_ENABLE_FROMURL
38  throw tao::pegtl::parse_error(
39  "This program was compiled without 'FROM URL' support.", in);
40 #endif
41  state.source = URL_SOURCE;
42  }
43 };
44 
45 template <>
47  template <typename Input>
48  static void apply(const Input &in, loadState &state) {
49  state.loadFile = in.string();
50  }
51 };
52 
53 template <>
55  template <typename Input>
56  static void apply(const Input &in, loadState &state) {
57  std::string pointer = in.string();
58  state.putValProv(std::make_unique<joda::query::PointerProvider>(
59  pointer.substr(1, pointer.size() - 2)));
60  }
61 };
62 
63 template <>
65  static void apply0(loadState &state) { state.lineSeperated = true; }
66 };
67 
68 template <>
70  template <typename Input>
71  static void apply(const Input &in, loadState &state) {
72  std::string str = in.string();
73  assert(!str.empty() && "String can not be empty");
74  state.sampleNum = std::stod(str);
75  }
76 };
77 
78 template <>
80  template <typename Input>
81  static void apply(const Input &in, loadState &state) {
82  if (!state.loadFile.empty()) {
83  switch (state.source) {
84  case NO_SOURCE:
85  LOG(ERROR) << "No source for load, this should not be possible.";
86  break;
87  case FILE_SOURCE:
88  state.sources.emplace_back(
89  std::make_unique<docparsing::JSONFileSource>(
90  state.loadFile, state.lineSeperated, state.sampleNum));
91  break;
92  case DIRECTORY_SOURCE:
93  state.sources.emplace_back(
94  std::make_unique<docparsing::JSONFileDirectorySource>(
95  state.loadFile, state.lineSeperated, state.sampleNum));
96  break;
97  case URL_SOURCE:
98  state.sources.emplace_back(
99  std::make_unique<docparsing::JSONURLSource>(state.loadFile));
100  break;
101  }
102  }
103  state.source = NO_SOURCE;
104  state.loadFile.clear();
105  state.sampleNum = 1;
107  }
108 };
109 
110 } // namespace joda::queryparsing::grammar
111 #endif // JODA_LOAD_ACTIONS_H
#define JODA_DEFAULT_LINE_SEPERATED
Definition: Load_State.h:8
@ NO_SOURCE
Definition: Load_State.h:17
@ URL_SOURCE
Definition: Load_State.h:20
@ FILE_SOURCE
Definition: Load_State.h:18
@ DIRECTORY_SOURCE
Definition: Load_State.h:19
static void apply0(loadState &state)
Definition: Load_Actions.h:30
static void apply0(loadState &state)
Definition: Load_Actions.h:25
static void apply(const Input &in, loadState &state)
Definition: Load_Actions.h:36
static void apply(const Input &in, loadState &state)
Definition: Load_Actions.h:56
static void apply(const Input &in, loadState &state)
Definition: Load_Actions.h:48
static void apply0(loadState &state)
Definition: Load_Actions.h:65
static void apply(const Input &in, loadState &state)
Definition: Load_Actions.h:18
static void apply(const Input &in, loadState &state)
Definition: Load_Actions.h:81
static void apply(const Input &in, loadState &state)
Definition: Load_Actions.h:71
Definition: Load_State.h:23
Source_Value source
Definition: Load_State.h:53
std::string loadVar
Definition: Load_State.h:50
bool lineSeperated
Definition: Load_State.h:55
double sampleNum
Definition: Load_State.h:54
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: Load_State.h:39
std::vector< std::unique_ptr< docparsing::IImportSource > > sources
Definition: Load_State.h:56
std::string loadFile
Definition: Load_State.h:51
Definition: Literals.h:27