From 5946abcb7d0ef554de233227075e8652930de821 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 24 Sep 2020 23:33:18 -0500 Subject: [PATCH] feat(array): add base array template --- storm/Array.hpp | 6 ++++++ storm/array/TSBaseArray.hpp | 34 ++++++++++++++++++++++++++++++++++ test/Array.cpp | 9 +++++++++ 3 files changed, 49 insertions(+) create mode 100644 storm/Array.hpp create mode 100644 storm/array/TSBaseArray.hpp create mode 100644 test/Array.cpp diff --git a/storm/Array.hpp b/storm/Array.hpp new file mode 100644 index 0000000..a9ef2b0 --- /dev/null +++ b/storm/Array.hpp @@ -0,0 +1,6 @@ +#ifndef STORM_ARRAY_HPP +#define STORM_ARRAY_HPP + +#include "array/TSBaseArray.hpp" + +#endif diff --git a/storm/array/TSBaseArray.hpp b/storm/array/TSBaseArray.hpp new file mode 100644 index 0000000..1eddb20 --- /dev/null +++ b/storm/array/TSBaseArray.hpp @@ -0,0 +1,34 @@ +#ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP +#define STORM_ARRAY_TS_BASE_ARRAY_HPP + +#include + +template +class TSBaseArray { + public: + uint32_t m_alloc = 0; + uint32_t m_count = 0; + T* m_data = nullptr; + + T& operator[](uint32_t i); + uint32_t Count(void); + void Clear(void); +}; + +template +T& TSBaseArray::operator[](uint32_t i) { + return this->m_data[i]; +} + +template +uint32_t TSBaseArray::Count() { + return this->m_count; +} + +template +void TSBaseArray::Clear() { + delete[] this->m_data; + TSBaseArray(); +} + +#endif diff --git a/test/Array.cpp b/test/Array.cpp new file mode 100644 index 0000000..2b91ed8 --- /dev/null +++ b/test/Array.cpp @@ -0,0 +1,9 @@ +#include "Array.hpp" +#include "Test.hpp" + +TEST_CASE("TSBaseArray", "[list]") { + SECTION("constructs correctly") { + TSBaseArray array; + REQUIRE(array.Count() == 0); + } +}