-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpersist.cpp
65 lines (46 loc) · 1.39 KB
/
persist.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
#include <boost/filesystem.hpp>
#include "ttxdata/ttxdata.hpp"
namespace fs = boost::filesystem;
namespace ttxPersist {
ttxPage_p load_file(const fs::path & path) {
BOOST_LOG_TRIVIAL(info) << "Loading teletext page from file: '" + path.string() + "'";
ttxPage_p page = std::make_shared<ttxPage>();
std::ifstream infile;
int line_num = 1;
infile.open(path.string().c_str(), std::ios::binary);
assert(infile.is_open());
while (infile.peek() != EOF) {
infile >> (*(page->new_line)(line_num++));
}
return page;
};
ttxPageEntry_map load_directory(const fs::path & dir) {
ttxPageEntry_map page_list;
ttxPage_p page;
BOOST_LOG_TRIVIAL(info) << "Loading teletext pages from directory: '" + dir.string() + "'";
assert(fs::exists(dir));
for (auto ent : fs::directory_iterator(dir)) {
if (ent.path().extension() == ".ttx") {
try {
// Is the filename a valid page address?
ttxPageAddress addr(ent.path().stem().string());
try {
page = load_file(ent);
}
catch (std::invalid_argument) {
BOOST_LOG_TRIVIAL(warning) << "Skipping invalid file: " << ent.path().filename();
continue;
}
page_list.emplace(addr, page);
}
catch (std::invalid_argument) {
BOOST_LOG_TRIVIAL(warning) << "Skipping invalid filename: " << ent.path().filename();
continue;
}
}
}
return page_list;
}
void save_pages() {
}
};