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