Joedb 9.1.4
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 int64_t checkpoint = 0;
19 bool ignore_errors = false;
20 int arg_index = 1;
21
22 if (arg_index + 2 < argc && std::string(argv[arg_index]) == "--ignore-errors")
23 {
24 ignore_errors = true;
25 arg_index++;
26 }
27
28 if (arg_index + 3 < argc && std::string(argv[arg_index]) == "--checkpoint")
29 {
30 std::istringstream(argv[arg_index + 1]) >> checkpoint;
31 arg_index += 2;
32 }
33
34 if (arg_index + 2 != argc)
35 {
36 std::cerr << "usage: " << argv[0];
37 std::cerr << " [--ignore-errors] [--checkpoint N] <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 input_file,
49 ignore_errors ?
52 );
53
54 File output_file(output_file_name, Open_Mode::create_new);
55 Writable_Journal output_journal(output_file);
56
57 process(input_journal, output_journal, checkpoint);
58
59 return 0;
60 }
61}
@ 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