feat(kcp): Vector class outline

This commit is contained in:
Daniel Hammer
2025-03-01 19:29:34 +04:00
parent c3030ec15d
commit a8f0bb4454
3 changed files with 65 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
/*
* vector.cpp
* Kernel C++ platform: Vector library
* Copyright (c) 2025 Daniel Hammer
*/
#include "Vector.hpp"
+57
View File
@@ -0,0 +1,57 @@
/*
* vector.hpp
* Kernel C++ platform: Vector library
* Copyright (c) 2025 Daniel Hammer
*/
#pragma once
#include <cstdint>
#include <Terminal/terminal.hpp>
#include <Memory/Heap.hpp>
namespace kcp
{
template<typename T>
class vector {
protected:
T* array;
std::size_t sz;
public:
vector()
{
sz = 0;
array = nullptr;
}
T operator[](std::int64_t position)
{
if (position > (sz + 1)) {
kerr << "Vector out of bounds caught!" << Kt::newline;
return T{};
}
else
{
return array[position];
}
}
T at(std::int64_t position) {
return this->operator[](position);
}
void push_back(T value) {
array = (T *)Memory::g_allocator->Realloc(array, sz + 1);
array[sz++] = value;
}
void test() {
array = (T *)Memory::g_allocator->Realloc(array, sz + 1);
}
T& get_array()
{
return *array;
}
};
};
+1
View File
@@ -17,6 +17,7 @@
#include <Memory/Heap.hpp>
#include <CppLib/Stream.hpp>
#include <CppLib/Vector.hpp>
using namespace Kt;