Joedb 10.0.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_NETWORKING
9#endif
10
11#ifdef JOEDB_HAS_SSH
13#endif
14
15#include <cstring>
16#include <sstream>
17
18namespace joedb
19{
20 //////////////////////////////////////////////////////////////////////////
22 //////////////////////////////////////////////////////////////////////////
23 {
24 builders.emplace_back(new Dummy_Connection_Builder());
25 builders.emplace_back(new File_Connection_Builder());
26
27#ifdef JOEDB_HAS_NETWORKING
28 builders.emplace_back(new Local_Connection_Builder());
29#endif
30
31#ifdef JOEDB_HAS_SSH
32 builders.emplace_back(new SSH_Connection_Builder());
33#endif
34 }
35
36 //////////////////////////////////////////////////////////////////////////
37 void Connection_Parser::print_help(std::ostream &out) const
38 //////////////////////////////////////////////////////////////////////////
39 {
40 out << "\n<connection> is one of:\n";
41 for (size_t i = 0; i < builders.size(); i++)
42 {
43 out << ' ';
44
45 if (i == 0)
46 out << '[';
47
48 out<< builders[i]->get_name();
49
50 if (i == 0)
51 out << "] (default)";
52
53 out << ' ' << builders[i]->get_parameters_description();
54 out << '\n';
55 }
56 }
57
58 //////////////////////////////////////////////////////////////////////////
59 Connection_Builder &Connection_Parser::get_builder(std::string_view name) const
60 //////////////////////////////////////////////////////////////////////////
61 {
62 for (const auto &b: builders)
63 if (name == b->get_name())
64 return *b;
65
66 std::ostringstream message;
67 message << "Unknown connection type: " << name << '\n';
68 print_help(message);
69 throw Exception(message.str());
70 }
71
72 //////////////////////////////////////////////////////////////////////////
74 //////////////////////////////////////////////////////////////////////////
75 (
76 Arguments &arguments,
77 Buffered_File *file
78 ) const
79 {
80 std::string_view connection_name;
81
82 if (arguments.get_remaining_count() == 0)
83 connection_name = builders[0]->get_name();
84 else
85 connection_name = arguments.get_next();
86
87 std::cerr << "Creating connection (" << connection_name << ") ... ";
88
89 Connection *result = get_builder(connection_name.data()).build(arguments, file);
90
91 std::cerr << "OK\n";
92
93 return result;
94 }
95}
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
void print_help(std::ostream &out) const
Connection * build(Arguments &arguments, Buffered_File *file) const
Definition Blob.h:7