mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 08:36:16 +00:00
Cleanup gdb stub and module mapping
This commit is contained in:
54
src/emulator/scoped_hook.hpp
Normal file
54
src/emulator/scoped_hook.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#include "emulator.hpp"
|
||||
|
||||
class scoped_hook
|
||||
{
|
||||
public:
|
||||
scoped_hook() = default;
|
||||
|
||||
scoped_hook(emulator& emu, emulator_hook* hook)
|
||||
: emu_(&emu)
|
||||
, hook_(hook)
|
||||
{
|
||||
}
|
||||
|
||||
~scoped_hook()
|
||||
{
|
||||
this->remove();
|
||||
}
|
||||
|
||||
scoped_hook(const scoped_hook&) = delete;
|
||||
scoped_hook& operator=(const scoped_hook&) = delete;
|
||||
|
||||
scoped_hook(scoped_hook&& obj) noexcept
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
scoped_hook& operator=(scoped_hook&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->remove();
|
||||
this->emu_ = obj.emu_;
|
||||
this->hook_ = obj.hook_;
|
||||
|
||||
obj.hook_ = {};
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void remove()
|
||||
{
|
||||
if (this->hook_)
|
||||
{
|
||||
this->emu_->delete_hook(this->hook_);
|
||||
this->hook_ = {};
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
emulator* emu_{};
|
||||
emulator_hook* hook_{};
|
||||
};
|
||||
Reference in New Issue
Block a user