25#include "patch_kernel.hpp"
26#include "patch_manager.hpp"
37const int PatchManager::AUTOMATIC_ID = IndexGenerator<int>::NULL_ID;
42std::unique_ptr<PatchManager> PatchManager::m_manager =
nullptr;
52 m_manager = std::unique_ptr<PatchManager>(
new PatchManager());
65 for (
const auto &entry : m_patchIds) {
66 long patchId = entry.second;
82int PatchManager::registerPatch(
PatchKernel *patch,
int id)
86 throw std::runtime_error (
"A patch with the same id already exists");
95 m_patchIds[patch] = id;
96 m_patchOrder.push_back(patch);
106void PatchManager::unregisterPatch(PatchKernel *patch)
108 auto iterator = m_patchIds.find(patch);
109 if (iterator == m_patchIds.end()) {
110 throw std::runtime_error (
"The patch to be unregistered does not exist");
113 int id = iterator->second;
114 m_idGenerator.
trash(
id);
116 m_patchIds.erase(iterator);
117 for (
auto itr = m_patchOrder.begin(); itr != m_patchOrder.end(); ++itr) {
119 m_patchOrder.erase(itr);
128PatchManager::PatchManager()
139 m_idGenerator.
dump(stream);
175 m_idGenerator.
reset();
178 patch->restore(stream);
bool isAssigned(id_type id)
void setAssigned(id_type id)
void restore(std::istream &stream)
void dump(std::ostream &stream) const
The PatchKernel class provides an interface for defining patches.
The PatchManager oversee the handling of the patches.
void dumpAll(std::ostream &stream)
void restoreAll(std::istream &stream)
void dump(std::ostream &stream)
PatchKernel * get(int id)
static PatchManager & manager()
void restore(std::istream &stream)