mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(array): add base array template
This commit is contained in:
parent
942fb18537
commit
5946abcb7d
3 changed files with 49 additions and 0 deletions
6
storm/Array.hpp
Normal file
6
storm/Array.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef STORM_ARRAY_HPP
|
||||||
|
#define STORM_ARRAY_HPP
|
||||||
|
|
||||||
|
#include "array/TSBaseArray.hpp"
|
||||||
|
|
||||||
|
#endif
|
||||||
34
storm/array/TSBaseArray.hpp
Normal file
34
storm/array/TSBaseArray.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP
|
||||||
|
#define STORM_ARRAY_TS_BASE_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
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<class T>
|
||||||
|
T& TSBaseArray<T>::operator[](uint32_t i) {
|
||||||
|
return this->m_data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
uint32_t TSBaseArray<T>::Count() {
|
||||||
|
return this->m_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void TSBaseArray<T>::Clear() {
|
||||||
|
delete[] this->m_data;
|
||||||
|
TSBaseArray<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
9
test/Array.cpp
Normal file
9
test/Array.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "Array.hpp"
|
||||||
|
#include "Test.hpp"
|
||||||
|
|
||||||
|
TEST_CASE("TSBaseArray", "[list]") {
|
||||||
|
SECTION("constructs correctly") {
|
||||||
|
TSBaseArray<uint32_t> array;
|
||||||
|
REQUIRE(array.Count() == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue