mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 16:46:16 +00:00
Introduce try_read/try_write for emulator_object
This commit is contained in:
@@ -104,6 +104,16 @@ class emulator_object
|
||||
return this->address_ != 0;
|
||||
}
|
||||
|
||||
std::optional<T> try_read(const size_t index = 0) const
|
||||
{
|
||||
T obj{};
|
||||
if (this->memory_->try_read_memory(this->address_ + index * this->size(), &obj, sizeof(obj)))
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
T read(const size_t index = 0) const
|
||||
{
|
||||
T obj{};
|
||||
@@ -111,6 +121,11 @@ class emulator_object
|
||||
return obj;
|
||||
}
|
||||
|
||||
bool try_write(const T& value, const size_t index = 0) const
|
||||
{
|
||||
return this->memory_->try_write_memory(this->address_ + index * this->size(), &value, sizeof(value));
|
||||
}
|
||||
|
||||
void write(const T& value, const size_t index = 0) const
|
||||
{
|
||||
this->memory_->write_memory(this->address_ + index * this->size(), &value, sizeof(value));
|
||||
|
||||
Reference in New Issue
Block a user