// // Created by erki on 28.02.21. // #include "OperationStorage.hpp" #include #include #include OperationStorage::~OperationStorage() { } void OperationStorage::enablePrettyPrint() { _pretty_print = true; } void OperationStorage::toStream(std::ostream& stream) { nlohmann::json json = _operations; if (_pretty_print) stream << std::setw(4) << json; else stream << json; } void OperationStorage::toFile(const std::string& output_filename) { std::ofstream file(output_filename); toStream(file); } void OperationStorage::pushOperation(const std::string& original_filename, OperationLog&& op) { const std::string filename = _convertFilepath(original_filename); 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; } std::string OperationStorage::_convertFilepath(const std::string& original) { const std::filesystem::path path = original; return path.filename().string(); }