From 9af5588c30c4126a2800aae1afcb0de2c373dc6c Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 20 May 2024 17:40:47 -0400 Subject: rewrite application stuff in the kernel to support multitasking --- euler/include/vector | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 euler/include/vector (limited to 'euler/include/vector') diff --git a/euler/include/vector b/euler/include/vector new file mode 100644 index 0000000..f5083ed --- /dev/null +++ b/euler/include/vector @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +namespace std { + + template + class vector { + + t *buffer; + size_t buffer_length;//always positive + size_t count; + + public: + vector() : buffer(new t[16]), buffer_length(16), count(0) {} + + ~vector() { + delete[] buffer; + } + + t &operator[](size_t pos) { + return buffer[pos]; + } + + const t &operator[](size_t pos) const { + return buffer[pos]; + } + + t *data() { + return buffer; + } + + const t *data() const { + return buffer; + } + + size_t size() const { + return count; + } + + void reserve(size_t new_length) { + if (new_length <= buffer_length) + return; + t *new_buffer = new t[new_length]; + for (size_t i = 0; i < count; ++i) + new_buffer[i] = std::move(buffer[i]); + delete[] buffer; + buffer = new_buffer; + buffer_length = new_length; + } + + void push_back(t &&value) { + if (count == buffer_length) + reserve(count * 2); + buffer[count++] = std::move(value); + } + + //TODO + }; + +} -- cgit v1.2.3