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