3 changed files with 60 additions and 5 deletions
@ -0,0 +1,16 @@
|
||||
#pragma once |
||||
#include <data.hpp> |
||||
#include <fs.hpp> |
||||
#include <future> |
||||
#include <json.hpp> |
||||
|
||||
class orders : public json { |
||||
const with_data_directory &data_directory; |
||||
const fs::path &get_path(); |
||||
|
||||
|
||||
public: |
||||
void write(const json &); |
||||
void load(); |
||||
orders(const with_data_directory &); |
||||
}; |
||||
@ -0,0 +1,36 @@
|
||||
#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(*this); |
||||
} |
||||
} |
||||
|
||||
void orders::write(const json &input) { |
||||
try { |
||||
std::ofstream of(get_path()); |
||||
of << input; |
||||
|
||||
} catch (const std::exception &e) { |
||||
std::cerr << e.what() << std::endl; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue