contur2
Loading...
Searching...
No Matches
physical_memory.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7#include <vector>
8
10
11namespace contur {
12
17 class PhysicalMemory final : public IMemory
18 {
19 public:
22 explicit PhysicalMemory(std::size_t cellCount);
23 ~PhysicalMemory() override;
24
25 // Non-copyable, movable
26 PhysicalMemory(const PhysicalMemory &) = delete;
29 PhysicalMemory &operator=(PhysicalMemory &&) noexcept;
30
31 // IMemory interface
32 [[nodiscard]] Result<Block> read(MemoryAddress address) const override;
33 [[nodiscard]] Result<void> write(MemoryAddress address, const Block &block) override;
34 [[nodiscard]] std::size_t size() const noexcept override;
35 void clear() override;
36
41 [[nodiscard]] Result<void> writeRange(MemoryAddress startAddress, const std::vector<Block> &blocks);
42
47 [[nodiscard]] Result<std::vector<Block>> readRange(MemoryAddress startAddress, std::size_t count) const;
48
53 [[nodiscard]] Result<void> clearRange(MemoryAddress startAddress, std::size_t count);
54
55 private:
56 struct Impl;
57 std::unique_ptr<Impl> impl_;
58 };
59
60} // namespace contur
Abstract interface for linear addressable memory.
Definition i_memory.h:19
void clear() override
Clears all memory cells to default (Nop) blocks.
Result< void > writeRange(MemoryAddress startAddress, const std::vector< Block > &blocks)
Writes a contiguous sequence of blocks starting at the given address.
PhysicalMemory(PhysicalMemory &&) noexcept
std::unique_ptr< Impl > impl_
std::size_t size() const noexcept override
Returns the total number of addressable cells.
Result< Block > read(MemoryAddress address) const override
Reads a Block from the given address.
~PhysicalMemory() override
Result< void > write(MemoryAddress address, const Block &block) override
Writes a Block to the given address.
PhysicalMemory(const PhysicalMemory &)=delete
Result< void > clearRange(MemoryAddress startAddress, std::size_t count)
Clears a range of memory cells to default blocks.
PhysicalMemory(std::size_t cellCount)
Constructs physical memory with the given number of cells.
Result< std::vector< Block > > readRange(MemoryAddress startAddress, std::size_t count) const
Reads a contiguous sequence of blocks starting at the given address.
PhysicalMemory & operator=(const PhysicalMemory &)=delete
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
IMemory interface — abstract linear addressable memory.
Definition block.h:15
std::uint32_t MemoryAddress
Represents a memory address (physical or virtual).
Definition types.h:15
A single memory cell in the simulated architecture.
Definition block.h:26