Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
process_journal_pair.cpp
Go to the documentation of this file.
3
4#include <iostream>
5#include <sstream>
6
7namespace joedb
8{
9 ////////////////////////////////////////////////////////////////////////////
11 ////////////////////////////////////////////////////////////////////////////
12 (
13 int argc,
14 char **argv,
15 void (*process)(Readonly_Journal &, Writable_Journal &, int64_t checkpoint)
16 )
17 {
18 int arg_index = 1;
19
20 bool ignore_errors = false;
21 if (arg_index + 2 < argc && std::string(argv[arg_index]) == "--ignore-errors")
22 {
23 ignore_errors = true;
24 arg_index++;
25 }
26
27 int64_t until = 0;
28 if (arg_index + 3 < argc && std::string(argv[arg_index]) == "--until")
29 {
30 std::istringstream(argv[arg_index + 1]) >> until;
31 arg_index += 2;
32 }
33
34 if (arg_index + 2 != argc)
35 {
36 std::cerr << "usage: " << argv[0];
37 std::cerr << " [--ignore-errors] [--until <checkpoint>] <input.joedb> <output.joedb> \n";
38 return 1;
39 }
40
41 const char *input_file_name = argv[arg_index];
42 const char *output_file_name = argv[arg_index + 1];
43
44 File input_file(input_file_name, Open_Mode::read_existing);
45
46 Readonly_Journal input_journal
47 (
48 Journal_Construction_Lock(input_file, ignore_errors)
49 );
50
51 File output_file(output_file_name, Open_Mode::create_new);
52 Writable_Journal output_journal(output_file);
53
54 process(input_journal, output_journal, until);
55
56 return 0;
57 }
58}
@ create_new
fails if already exists, locks the file for writing
@ read_existing
fails if does not exist
int process_journal_pair(int argc, char **argv, void(*process)(Readonly_Journal &, Writable_Journal &, int64_t checkpoint))
Definition Blob.h:7
JOEDB_FILE File
Definition File.h:25