You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
721 B

5 years ago
#include <fstream>
#include <iostream>
#include <orders.hpp>
void orders::load() {
try {
std::fstream f(get_path());
f >> *this;
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
}
}
const fs::path &orders::get_path() {
static fs::path orders_json;
if (orders_json.empty())
orders_json = data_directory.get_path() / "orders.json";
return orders_json;
}
orders::orders(const with_data_directory &dir)
: json(json::array()), data_directory(dir) {
if (!fs::exists(get_path())) {
write();
5 years ago
}
}
void orders::write() {
5 years ago
try {
std::ofstream of(get_path());
of << *this;
5 years ago
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
}
}