-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotfile.cc
61 lines (49 loc) · 1.57 KB
/
hotfile.cc
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
/*
* Copyright (C) 2014 Dmitry Marakasov
*
* This file is part of opendaed.
*
* opendaed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opendaed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with opendaed. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <fstream>
#include "hotfile.hh"
HotFile::HotFile(const std::string& path) {
std::ifstream stream(path, std::ios_base::in);
stream.exceptions(std::ifstream::badbit);
while (!stream.eof()) {
int frameno;
stream >> frameno;
if (stream.fail())
break;
RectVector rects;
for (int i = 0; i < 8; i++) {
int x1, y1, x2, y2;
stream >> x1 >> y1 >> x2 >> y2;
if (stream.fail())
break;
if (x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0)
rects.emplace_back(x1, y1, x2 - x1, y2 - y1);
}
entries_.emplace(std::make_pair(frameno, std::move(rects)));
}
}
HotFile::~HotFile() {
}
const HotFile::RectVector& HotFile::GetRectsForFrame(int frame) const {
EntryMap::const_iterator entry = entries_.find(frame);
if (entry == entries_.end())
throw std::runtime_error("no hotspots for requested frame");
return entry->second;
}