52 lines
1012 B
C++
52 lines
1012 B
C++
//
|
|
// Created by erki on 28.02.21.
|
|
//
|
|
|
|
#include "OperationStorage.hpp"
|
|
|
|
#include <fstream>
|
|
#include <filesystem>
|
|
|
|
#include <llvm/Support/CommandLine.h>
|
|
|
|
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<OperationLog>()).first;
|
|
|
|
it->second.emplace_back(std::move(op));
|
|
}
|
|
|
|
const std::unordered_map<std::string, std::vector<OperationLog>>& 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;
|
|
}
|