diff --git a/deps/ox/src/ox/std/array.hpp b/deps/ox/src/ox/std/array.hpp new file mode 100644 index 00000000..d0bfdfbd --- /dev/null +++ b/deps/ox/src/ox/std/array.hpp @@ -0,0 +1,109 @@ +/* + * Copyright 2015 - 2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "types.hpp" + +namespace ox { + +template +class larray { + + private: + size_t m_size = 0; + T *m_items = nullptr; + + public: + larray() = default; + + explicit larray(size_t size); + + larray(larray &other); + + larray(larray &&other); + + ~larray(); + + size_t size() const; + + larray &operator=(larray &other); + + larray &operator=(larray &&other); + + T &operator[](size_t i); + + const T &operator[](size_t i) const; + +}; + +template +larray::larray(size_t size) { + m_size = size; + m_items = new T[m_size]; +} + +template +larray::larray(larray &other) { + m_size = size; + m_items = new T[m_size]; + for (size_t i = 0; i < m_size; i++) { + m_items[i] = other.m_items[i]; + } +} + +template +larray::larray(larray &&other) { + m_size = other.m_size; + m_items = other.m_items; + other.m_size = 0; + other.m_items = nullptr; +} + +template +larray::~larray() { + if (m_items) { + delete m_items; + } +} + +template +larray &larray::operator=(larray &other) { + m_size = size; + m_items = new T[m_size]; + for (size_t i = 0; i < m_size; i++) { + m_items[i] = other.m_items[i]; + } + return *this; +} + +template +larray &larray::operator=(larray &&other) { + m_size = other.m_size; + m_items = other.m_items; + other.m_size = 0; + other.m_items = nullptr; + return *this; +} + +template +size_t larray::size() const { + return m_size; +}; + +template +T &larray::operator[](size_t i) { + return *(m_items[i]); +} + +template +const T &larray::operator[](size_t i) const { + return *(m_items[i]); +} + +} diff --git a/deps/ox/src/ox/std/std.hpp b/deps/ox/src/ox/std/std.hpp index f0858ad6..66f5da91 100644 --- a/deps/ox/src/ox/std/std.hpp +++ b/deps/ox/src/ox/std/std.hpp @@ -7,6 +7,7 @@ */ #pragma once +#include "array.hpp" #include "bitops.hpp" #include "byteswap.hpp" #include "memops.hpp"