diff --git a/deps/ox/src/ox/fs/test/tests.cpp b/deps/ox/src/ox/fs/test/tests.cpp index 47e5a4a2..a055634f 100644 --- a/deps/ox/src/ox/fs/test/tests.cpp +++ b/deps/ox/src/ox/fs/test/tests.cpp @@ -198,7 +198,7 @@ map tests = { auto dataIn = "test string"; auto dataOutLen = 1024 * 64; auto dataOut = new char[dataOutLen]; - vector inodes; + std::vector inodes; const auto size = 1024 * 1024; auto buff = new uint8_t[size]; @@ -234,7 +234,7 @@ map tests = { auto dataIn = "test string"; auto dataOutLen = ox_strlen(dataIn) + 1; auto dataOut = new char[dataOutLen]; - vector inodes; + std::vector inodes; const auto size = 1024 * 1024; auto buff = new uint8_t[size]; @@ -263,7 +263,7 @@ map tests = { auto dataIn = "test string"; auto dataOutLen = ox_strlen(dataIn) + 1; auto dataOut = new char[dataOutLen]; - vector inodes; + std::vector inodes; const auto size = 1024 * 1024; auto buff = new uint8_t[size]; @@ -298,8 +298,8 @@ map tests = { auto dataIn = "test string"; auto dataOutLen = ox_strlen(dataIn) + 1; auto dataOut = new char[dataOutLen]; - vector inodes; - vector> files; + std::vector inodes; + std::vector> files; const auto size = 1024 * 1024; auto buff = new uint8_t[size]; diff --git a/deps/ox/src/ox/std/std.hpp b/deps/ox/src/ox/std/std.hpp index 66f5da91..c8cf9810 100644 --- a/deps/ox/src/ox/std/std.hpp +++ b/deps/ox/src/ox/std/std.hpp @@ -7,7 +7,6 @@ */ #pragma once -#include "array.hpp" #include "bitops.hpp" #include "byteswap.hpp" #include "memops.hpp" @@ -15,3 +14,4 @@ #include "strops.hpp" #include "string.hpp" #include "types.hpp" +#include "vector.hpp" diff --git a/deps/ox/src/ox/std/array.hpp b/deps/ox/src/ox/std/vector.hpp similarity index 59% rename from deps/ox/src/ox/std/array.hpp rename to deps/ox/src/ox/std/vector.hpp index d0bfdfbd..daefc501 100644 --- a/deps/ox/src/ox/std/array.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -13,28 +13,30 @@ namespace ox { template -class larray { +class Vector { private: size_t m_size = 0; T *m_items = nullptr; public: - larray() = default; + Vector() = default; - explicit larray(size_t size); + explicit Vector(size_t size); - larray(larray &other); + Vector(Vector &other); - larray(larray &&other); + Vector(Vector &&other); - ~larray(); + ~Vector(); size_t size() const; - larray &operator=(larray &other); + void resize(size_t size); - larray &operator=(larray &&other); + Vector &operator=(Vector &other); + + Vector &operator=(Vector &&other); T &operator[](size_t i); @@ -43,13 +45,13 @@ class larray { }; template -larray::larray(size_t size) { +Vector::Vector(size_t size) { m_size = size; m_items = new T[m_size]; } template -larray::larray(larray &other) { +Vector::Vector(Vector &other) { m_size = size; m_items = new T[m_size]; for (size_t i = 0; i < m_size; i++) { @@ -58,7 +60,7 @@ larray::larray(larray &other) { } template -larray::larray(larray &&other) { +Vector::Vector(Vector &&other) { m_size = other.m_size; m_items = other.m_items; other.m_size = 0; @@ -66,14 +68,16 @@ larray::larray(larray &&other) { } template -larray::~larray() { +Vector::~Vector() { if (m_items) { delete m_items; + m_items = nullptr; } } template -larray &larray::operator=(larray &other) { +Vector &Vector::operator=(Vector &other) { + ~Vector(); m_size = size; m_items = new T[m_size]; for (size_t i = 0; i < m_size; i++) { @@ -83,7 +87,8 @@ larray &larray::operator=(larray &other) { } template -larray &larray::operator=(larray &&other) { +Vector &Vector::operator=(Vector &&other) { + ~Vector(); m_size = other.m_size; m_items = other.m_items; other.m_size = 0; @@ -92,17 +97,28 @@ larray &larray::operator=(larray &&other) { } template -size_t larray::size() const { +size_t Vector::size() const { return m_size; }; template -T &larray::operator[](size_t i) { +void Vector::resize(size_t size) { + auto oldItems = m_items; + m_items = new T[size]; + const auto itRange = size > m_size ? m_size : size; + for (size_t i = 0; i < itRange; i++) { + m_items[i] = oldItems[i]; + } + m_size = size; +} + +template +T &Vector::operator[](size_t i) { return *(m_items[i]); } template -const T &larray::operator[](size_t i) const { +const T &Vector::operator[](size_t i) const { return *(m_items[i]); }