aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/vm/Reader.hpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-07-24 09:25:12 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-08-03 23:57:07 +0200
commit97668cd39c5056629e357037f64417686f522083 (patch)
treed0e1c20c3de1ef5748f41081c2e99b53e43a4f77 /src/openvic-simulation/vm/Reader.hpp
parent972ed9d7921637d4ac290dae214942dbe9bc05c3 (diff)
Add outline for some instructions
Diffstat (limited to 'src/openvic-simulation/vm/Reader.hpp')
-rw-r--r--src/openvic-simulation/vm/Reader.hpp45
1 files changed, 14 insertions, 31 deletions
diff --git a/src/openvic-simulation/vm/Reader.hpp b/src/openvic-simulation/vm/Reader.hpp
index e75042f..83f4788 100644
--- a/src/openvic-simulation/vm/Reader.hpp
+++ b/src/openvic-simulation/vm/Reader.hpp
@@ -2,58 +2,37 @@
#include <string_view>
+#include "Utility.hpp"
#include <lauf/reader.h>
namespace OpenVic::Vm {
template<typename Tag>
- struct BasicReader {
- BasicReader(BasicReader&&) = default;
- BasicReader& operator=(BasicReader&&) = default;
-
- BasicReader(BasicReader const&) = delete;
- BasicReader& operator=(BasicReader const&) = delete;
+ struct BasicReader : utility::MoveOnlyHandleBase<BasicReader<Tag>, lauf_reader> {
+ using utility::MoveOnlyHandleBase<BasicReader<Tag>, lauf_reader>::MoveOnlyHandleBase;
+ using utility::MoveOnlyHandleBase<BasicReader<Tag>, lauf_reader>::operator=;
~BasicReader() {
- if (_handle == nullptr) {
+ if (this->_handle == nullptr) {
return;
}
- lauf_destroy_reader(_handle);
- }
-
- lauf_reader* handle() {
- return _handle;
- }
-
- const lauf_reader* handle() const {
- return _handle;
- }
-
- operator lauf_reader*() {
- return _handle;
- }
-
- operator const lauf_reader*() const {
- return _handle;
+ lauf_destroy_reader(*this);
+ this->_handle = nullptr;
}
void set_path(const char* path) {
- lauf_reader_set_path(_handle, path);
+ lauf_reader_set_path(*this, path);
}
struct StringTag;
struct FileTag;
struct StdinTag;
-
- protected:
- BasicReader(lauf_reader* reader) : _handle(reader) {}
-
- private:
- lauf_reader* _handle;
};
template<>
struct BasicReader<BasicReader<void>::StringTag> : BasicReader<void> {
using BasicReader<void>::BasicReader;
+ using BasicReader<void>::operator=;
+
BasicReader(const char* cstr) : BasicReader(lauf_create_cstring_reader(cstr)) {}
BasicReader(std::string_view view) : BasicReader(lauf_create_string_reader(view.data(), view.size())) {}
};
@@ -61,6 +40,8 @@ namespace OpenVic::Vm {
template<>
struct BasicReader<BasicReader<void>::FileTag> : BasicReader<void> {
using BasicReader<void>::BasicReader;
+ using BasicReader<void>::operator=;
+
BasicReader(const char* path) : BasicReader(lauf_create_file_reader(path)) {}
bool is_valid() {
@@ -71,6 +52,8 @@ namespace OpenVic::Vm {
template<>
struct BasicReader<BasicReader<void>::StdinTag> : BasicReader<void> {
using BasicReader<void>::BasicReader;
+ using BasicReader<void>::operator=;
+
BasicReader() : BasicReader(lauf_create_stdin_reader()) {}
};