Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Connection_Parser.cpp
Go to the documentation of this file.
6
7#ifdef JOEDB_HAS_ASIO
9#endif
10
11#ifdef JOEDB_HAS_SSH
13#endif
14
15#ifdef JOEDB_HAS_WEBSOCKETS
17#endif
18
19#include <cstring>
20#include <sstream>
21
22namespace joedb
23{
24 //////////////////////////////////////////////////////////////////////////
26 //////////////////////////////////////////////////////////////////////////
27 {
28 builders.emplace_back(new Dummy_Connection_Builder());
29 builders.emplace_back(new File_Connection_Builder());
30
31#ifdef JOEDB_HAS_ASIO
32 builders.emplace_back(new Local_Connection_Builder());
33#endif
34
35#ifdef JOEDB_HAS_SSH
36 builders.emplace_back(new SSH_Connection_Builder());
37#endif
38
39#ifdef JOEDB_HAS_WEBSOCKETS
40 builders.emplace_back(new Websocket_Connection_Builder());
41#endif
42 }
43
44 //////////////////////////////////////////////////////////////////////////
45 void Connection_Parser::print_help(std::ostream &out) const
46 //////////////////////////////////////////////////////////////////////////
47 {
48 out << "\n<connection> is one of:\n";
49 for (size_t i = 0; i < builders.size(); i++)
50 {
51 out << ' ';
52
53 if (i == 0)
54 out << '[';
55
56 out<< builders[i]->get_name();
57
58 if (i == 0)
59 out << "] (default)";
60
61 out << ' ' << builders[i]->get_parameters_description();
62 out << '\n';
63 }
64 }
65
66 //////////////////////////////////////////////////////////////////////////
67 Connection_Builder &Connection_Parser::get_builder(std::string_view name) const
68 //////////////////////////////////////////////////////////////////////////
69 {
70 for (const auto &b: builders)
71 if (name == b->get_name())
72 return *b;
73
74 std::ostringstream message;
75 message << "Unknown connection type: " << name << '\n';
76 print_help(message);
77 throw Exception(message.str());
78 }
79
80 //////////////////////////////////////////////////////////////////////////
82 //////////////////////////////////////////////////////////////////////////
83 (
84 Logger &logger,
85 Arguments &arguments,
86 Abstract_File *file
87 ) const
88 {
89 std::string_view connection_name;
90
91 if (arguments.get_remaining_count() == 0)
92 connection_name = builders[0]->get_name();
93 else
94 connection_name = arguments.get_next();
95
96 logger.log("creating connection: " + std::string(connection_name));
97
98 Connection *result = get_builder(connection_name.data()).build
99 (
100 logger,
101 arguments,
102 file
103 );
104
105 return result;
106 }
107}
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
void print_help(std::ostream &out) const
Connection * build(Logger &logger, Arguments &arguments, Abstract_File *file) const