-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_extract.cpp
83 lines (71 loc) · 2.1 KB
/
index_extract.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cstdlib>
#include <cstdint>
#include <limits>
#include <boost/program_options.hpp>
#include <api.hpp>
#include <io.hpp>
std::ostream &operator<<(std::ostream &s, const std::vector<char> &v)
{
s << std::string(v.data(), v.size());
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v)
{
for (auto i : v) {
s << i << " ";
}
return s;
}
class call {
private:
size_t start;
size_t end;
public:
call(size_t start, size_t end) : start(start), end(end) { }
template <typename Index>
void invoke(Index &idx)
{
start = std::min(start, idx.size());
end = std::min(end, idx.size());
std::cout << idx(start, end);
}
};
int main(int argc, char **argv)
{
using std::string;
namespace po = boost::program_options;
po::options_description desc;
po::variables_map vm;
try {
desc.add_options()
("index-file,i", po::value<string>()->required(),
"Index filename.")
("reference-file,r", po::value<string>()->required(),
"Reference file.")
("start,s", po::value<size_t>()->default_value(0),
"Extraction start.")
("end,e", po::value<size_t>()->default_value(std::numeric_limits<size_t>::max()),
"Extraction end.");
po::positional_options_description pd;
pd.add("index-file", 1).add("reference-file", 1).add("start", 1).add("end", 1);
try {
po::store(po::command_line_parser(argc, argv).options(desc).positional(pd).run(), vm);
po::notify(vm);
} catch (boost::program_options::error &e) {
throw std::runtime_error(e.what());
}
string index = vm["index-file"].as<string>();
string reference = vm["reference-file"].as<string>();
size_t start = vm["start"].as<size_t>();
size_t end = vm["end"].as<size_t>();
call c { start, end };
rlz::serialize::load_stream(index.c_str(), reference.c_str(), c);
} catch (std::exception &e) {
std::cerr << e.what() << "\n"
<< "Command-line options:" << "\n"
<< desc << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}