Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Client_Parser.cpp
Go to the documentation of this file.
8
9#include <iostream>
10#include <cstring>
11
12namespace joedb
13{
14 ////////////////////////////////////////////////////////////////////////////
16 ////////////////////////////////////////////////////////////////////////////
17 (
18 bool local,
19 Open_Mode default_open_mode,
20 bool with_database
21 ):
22 file_parser(default_open_mode, false, true, true),
23 connection_parser(local),
24 default_open_mode(default_open_mode),
25 default_with_database(with_database)
26 {
27 }
28
29 ////////////////////////////////////////////////////////////////////////////
30 void Client_Parser::print_help(std::ostream &out) const
31 ////////////////////////////////////////////////////////////////////////////
32 {
33 out << " [--nocheck]";
34 if (default_with_database)
35 out << " [--nodb]";
36 out << " <file> <connection>\n\n";
37
38 file_parser.print_help(out);
39 connection_parser.print_help(out);
40 }
41
42 ////////////////////////////////////////////////////////////////////////////
43 Client &Client_Parser::parse(int argc, char **argv)
44 ////////////////////////////////////////////////////////////////////////////
45 {
46 int arg_index = 0;
47
48 bool content_check = true;
49 if (arg_index < argc && std::strcmp(argv[arg_index], "--nocheck") == 0)
50 {
51 arg_index++;
52 content_check = false;
53 }
54 std::cerr << "content_check = " << content_check << '\n';
55
56 bool with_database = default_with_database;
57 if (arg_index < argc && std::strcmp(argv[arg_index], "--nodb") == 0)
58 {
59 arg_index++;
60 with_database = false;
61 }
62
63 file_parser.parse
64 (
65 std::cerr,
66 argc,
67 argv,
68 arg_index
69 );
70
71 Buffered_File *client_file = file_parser.get_file();
72
73 Connection &connection = connection_parser.build
74 (
75 argc - arg_index,
76 argv + arg_index,
77 client_file
78 );
79
80 if (!client_file)
81 client_file = dynamic_cast<Buffered_File *>(&connection);
82
83 if (!client_file)
84 throw Exception("server file must be used with a network or ssh connection");
85
86 std::cerr << "Creating client data... ";
87 std::cerr << "OK\n";
88
89 if (with_database)
90 {
91 if (client_file->is_readonly())
92 client.reset(new Readonly_Database_Client(*client_file, connection, content_check));
93 else
94 client.reset(new Writable_Database_Client(*client_file, connection, content_check));
95 }
96 else
97 {
98 if (client_file->is_readonly())
99 client.reset(new Readonly_Journal_Client(*client_file, connection, content_check));
100 else
101 client.reset(new Writable_Journal_Client(*client_file, connection, content_check));
102 }
103
104 return *client;
105 }
106}
bool is_readonly() const noexcept
Client_Parser(bool local, Open_Mode default_open_mode, bool with_database)
void print_help(std::ostream &out) const
Client & parse(int argc, char **argv)
Handle concurrent access to a file with a joedb::Connection.
Definition Client.h:12
Buffered_File * get_file() const
Definition File_Parser.h:56
Buffered_File * parse(std::ostream &out, int argc, char **argv, int &arg_index)
Open_Mode
Definition Open_Mode.h:8
Definition Blob.h:7