aboutsummaryrefslogtreecommitdiff
path: root/src/labeller.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-08-17 08:56:51 -0400
committerYour Name <you@example.com>2021-08-17 08:56:51 -0400
commit2a4ca022ad37ff2452ec3addb8c760a93bb616c6 (patch)
treedd66554b8e7e568a410974df71a95d37f5433d18 /src/labeller.cc
parent8a6b5564c0fc37e6e556d04e17ddba86d4bd3dc1 (diff)
parent5e4240ea795c992635a3cfc464d760205e07bf05 (diff)
downloadannotator-2a4ca022ad37ff2452ec3addb8c760a93bb616c6.tar.gz
annotator-2a4ca022ad37ff2452ec3addb8c760a93bb616c6.tar.bz2
annotator-2a4ca022ad37ff2452ec3addb8c760a93bb616c6.zip
Merge branch 'master' of https://vance.fish/git/annotator
Diffstat (limited to 'src/labeller.cc')
-rw-r--r--src/labeller.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/labeller.cc b/src/labeller.cc
index 024b720..f7fa69e 100644
--- a/src/labeller.cc
+++ b/src/labeller.cc
@@ -1,7 +1,7 @@
#include "labeller.h"
#include "settings.h"
#include <fstream>
-
+#include <iostream>
namespace backend {
struct labeller_impl {
@@ -14,11 +14,28 @@ namespace backend {
std::filesystem::path savepath;
};
+ void load(const std::filesystem::path& savepath, labeller_impl& data) {
+ std::ifstream in(savepath);
+ std::string line;
+ const char delim = ',';
+ while(std::getline(in, line)) {
+ std::size_t split = line.find(delim);
+ if(split == std::string::npos) {
+ std::cerr << "Error reading " << savepath << std::endl;
+ throw std::runtime_error(savepath.string());
+ }
+ data.annotations.push_back(label(line.substr(0, split), std::stod(line.substr(split+1))));
+ }
+ }
+
labeller::labeller(const std::filesystem::path& savepath) {
data = std::shared_ptr<labeller_impl>(new labeller_impl);
data->labels = settings::getLabels();
data->rectangleLabels = settings::getRectangleLabels();
data->savepath = savepath;
+ if(std::filesystem::directory_entry(savepath).exists()) {
+ load(savepath, *data);
+ }
}
std::pair<label, label> labeller::getSurrounding(double time) const {
@@ -111,6 +128,7 @@ namespace backend {
void labeller::save() const {
std::ofstream out;
+ std::filesystem::create_directories(data->savepath.parent_path());
out.open(data->savepath);
std::vector<label> a(data->annotations);
std::sort(a.begin(), a.end(), compareLabels);
@@ -119,4 +137,5 @@ namespace backend {
}
out.close();
}
+
}