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.
38 lines
744 B
38 lines
744 B
#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(); |
|
} else { |
|
load(); |
|
} |
|
} |
|
|
|
void orders::write() { |
|
try { |
|
std::ofstream of(get_path()); |
|
of << *this; |
|
|
|
} catch (const std::exception &e) { |
|
std::cerr << e.what() << std::endl; |
|
} |
|
} |