JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
CLI.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 12/07/18.
3 //
4 
5 #ifndef JODA_CLI_H
6 #define JODA_CLI_H
7 #include <readline/history.h>
8 #include <readline/readline.h>
9 #include <string>
10 #include <vector>
11 #include "joda/misc/Benchmark.h"
12 #include "joda/query/Query.h"
14 
15 #ifdef JODA_ENABLE_PROFILING
16 #include "gperftools/profiler.h"
17 #endif
18 
19 namespace joda::cli {
23 class CLI {
24  public:
25  CLI();
31  void start(const std::vector<std::string> &onceQueries);
32 
40  void setSimpleMode(bool simpleMode);
41 
42  protected:
43  bool simpleMode = false;
44  void checkTerminal();
45  /*
46  * String/Command modification
47  */
48  std::string &ltrim(std::string &str);
49  std::string &rtrim(std::string &str);
50  void parseCommand();
51  void print(const std::string &toprint);
52 
53  /*
54  * Commands
55  */
56  std::vector<std::pair<std::string, std::function<void(const std::string &)>>>
57  getCommands();
58  void quit();
59  void query(std::string &query);
60  void toggleCache();
61  void help();
62  void dumpConfig();
63  void listSources();
64  void listResults();
65  void unknownCommand();
66  void executeQuery(std::shared_ptr<query::Query> &query,
67  bool printResult = true);
68  void executeNonInteractiveQuery(std::shared_ptr<query::Query> &query,
69  bool printResult = true);
70  void logo();
71 #ifdef JODA_ENABLE_PROFILING
72  void profileStart(const std::string &name);
73  void profileStop();
74  bool profileRunning = false;
75 #endif
76 
77  /*
78  * Benchmarking
79  */
80 
81  void benchmarkQuery(const std::shared_ptr<query::Query> &q,
82  const std::string &name);
83  void benchmarkQuery(std::vector<std::shared_ptr<query::Query>> qs,
84  const std::string &name);
85 
86  /*
87  * Class variables
88  */
89  bool execute = true;
91  std::shared_ptr<JSONStorage> checkResult(unsigned long resultId);
92 };
93 } // namespace joda::cli
94 
95 #endif // JODA_CLI_H
Definition: Benchmark.h:27
Definition: CLI.h:23
void logo()
Definition: CLI.cpp:426
void unknownCommand()
Definition: CLI.cpp:424
void executeQuery(std::shared_ptr< query::Query > &query, bool printResult=true)
Definition: CLI.cpp:300
void print(const std::string &toprint)
Definition: CLI.cpp:177
bool simpleMode
Definition: CLI.h:43
void dumpConfig()
Definition: CLI.cpp:485
std::string & rtrim(std::string &str)
Definition: CLI.cpp:73
Benchmark bench
Definition: CLI.h:90
void quit()
Definition: CLI.cpp:181
void executeNonInteractiveQuery(std::shared_ptr< query::Query > &query, bool printResult=true)
Definition: CLI.cpp:231
bool execute
Definition: CLI.h:89
void setSimpleMode(bool simpleMode)
Definition: CLI.cpp:492
void benchmarkQuery(const std::shared_ptr< query::Query > &q, const std::string &name)
Definition: CLI.cpp:402
void start(const std::vector< std::string > &onceQueries)
Definition: CLI.cpp:114
void checkTerminal()
Definition: CLI.cpp:500
void listResults()
Definition: CLI.cpp:205
std::shared_ptr< JSONStorage > checkResult(unsigned long resultId)
Definition: CLI.cpp:273
void help()
Definition: CLI.cpp:468
std::string & ltrim(std::string &str)
Definition: CLI.cpp:65
void query(std::string &query)
Definition: CLI.cpp:219
std::vector< std::pair< std::string, std::function< void(const std::string &)> > > getCommands()
Definition: CLI.cpp:451
void listSources()
Definition: CLI.cpp:192
void toggleCache()
Definition: CLI.cpp:186
CLI()
Definition: CLI.cpp:400
void parseCommand()
Definition: CLI.cpp:81
Definition: CLI.h:19