// // Created by erki on 28.02.21. // #include "OperationStorage.hpp" #include #include #include OperationStorage::OperationStorage(const std::string& output_filename) : _output_filename(output_filename) { } OperationStorage::~OperationStorage() { _dumpToFile(); } void OperationStorage::enablePrettyPrint() { _pretty_print = true; } void OperationStorage::pushOperation(const std::string& filename, OperationLog&& op) { auto it = _operations.find(filename); if (it == _operations.end()) it = _operations.emplace(filename, std::vector()).first; it->second.emplace_back(std::move(op)); } const std::unordered_map>& OperationStorage::getOperations() const { return _operations; } void OperationStorage::_dumpToFile() { nlohmann::json json = _operations; std::ofstream file(_output_filename); if (_pretty_print) file << std::setw(4) << json; else file << json; }