aocpp/intcode/include/intcode/Machine.hpp

44 lines
1004 B
C++

#ifndef INTCODE_MACHINE_HPP_
#define INTCODE_MACHINE_HPP_
#include <cstddef>
#include <unordered_map>
#include <vector>
#include <iostream>
namespace intcode {
using ValueType = std::int64_t;
class Machine {
std::vector<ValueType> rom_;
std::unordered_map<std::size_t, ValueType> ram_;
std::size_t pc_;
std::size_t base_;
public:
Machine();
/// Initialize a new machine with a given program starting
/// execution and program counter 0.
explicit Machine(std::vector<ValueType> program);
/// Access memory at absolute address
/// @param address
/// @return reference to memory at given address
auto At(std::size_t address) -> ValueType &;
/// Access memory at address relative to base pointer
/// @param offset from base pointer
/// @return reference to memory at given offset
auto Rel(std::size_t offset) -> ValueType &;
auto Next() -> ValueType &;
auto Goto(std::size_t address) -> void;
auto Rebase(std::size_t offset) -> void;
};
} // namespace
#endif