Joedb 10.2.1
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 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 std::cerr << "Creating connection (" << connection_name << ") ... ";
96
97 Connection *result = get_builder(connection_name.data()).build
98 (
99 arguments,
100 file
101 );
102
103 std::cerr << "OK\n";
104
105 return result;
106 }
107}
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
Connection * build(Arguments &arguments, Abstract_File *file) const
void print_help(std::ostream &out) const