diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9245fb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target\ \ No newline at end of file diff --git a/Build.bat b/Build.bat index 00dba8c..0359a35 100644 --- a/Build.bat +++ b/Build.bat @@ -1,9 +1,9 @@ @ECHO OFF SETLOCAL EnableDelayedExpansion -SET target_name=Test.exe +SET target_name=Kraken-Core.exe -SET target_dir=Target\ +SET target_dir=target\ SET compiler=g++ SET compiler_flags=-ggdb -Wall -Wextra diff --git a/Run.bat b/Run.bat index 6a375a1..783bbf8 100644 --- a/Run.bat +++ b/Run.bat @@ -1,9 +1,9 @@ @ECHO OFF SETLOCAL EnableDelayedExpansion -SET target_name=Test.exe +SET target_name=Kraken-Core.exe -SET target_dir=Target\ +SET target_dir=target\ CALL Build.bat diff --git a/Source/Main.cpp b/Source/Main.cpp deleted file mode 100644 index 91f38f2..0000000 --- a/Source/Main.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -i32 main() { - -} \ No newline at end of file diff --git a/src/Core/Containers/Vector.hpp b/src/Core/Containers/Vector.hpp new file mode 100644 index 0000000..664d6ff --- /dev/null +++ b/src/Core/Containers/Vector.hpp @@ -0,0 +1,197 @@ +#pragma once + +#include + +class OutOfRange {}; + +// @todo: implementing copy ctor & copy assignment +template +class Vector { + public: + Vector(); + ~Vector(); + +/** + * Element access + */ + Type& operator[] (i32 index); + const Type& operator[] (i32 index) const; + + Type* data() { return M_data; } + const Type* data() const { return M_data; } + +/** + * Capacity + */ + bool is_empty() const { return (M_length == 0); } + i32 length() const { return M_length; } + + void reserve(i32 new_capacity); + + i32 capacity() const { return M_capacity; } + +/** + * Modifiers + */ + void clear(); + + void insert(const Type& value, i32 index); + void erase(i32 index); + + void push(const Type& value); + void pop(); + + void resize(i32 new_capacity); + + private: + Type* M_data; + i32 M_capacity; + i32 M_length; +}; + + +template +inline Vector::Vector() { + i32 initial_capacity = 8; + + M_data = new Type[initial_capacity]; + M_capacity = initial_capacity; + M_length = 0; +} + + +template +inline Vector::~Vector() { + delete[] M_data; + + M_data = nullptr; + M_capacity = 0; + M_length = 0; +} + + +template +inline Type& Vector::operator[] (i32 index) { + if(index < 0 || index > M_length) { + throw OutOfRange(); + } + + return M_data[index]; +} + + +template +inline const Type& Vector::operator[] (i32 index) const { + if(index < 0 || index > M_length) { + throw OutOfRange(); + } + + return M_data[index]; +} + + +template +inline void Vector::reserve(i32 new_capacity) { + if(new_capacity < M_capacity) { + return; + } + + M_capacity = new_capacity; + + Type* new_data = new Type[new_capacity]; + + for(i32 i = 0; i < M_length; i += 1) { + new_data[i] = M_data[i]; + } + + delete[] M_data; + + M_data = new_data; +} + + +template +inline void Vector::clear() { + delete[] M_data; + + i32 initial_capacity = 8; + + M_data = new Type[initial_capacity]; + M_capacity = initial_capacity; + M_length = 0; +} + + +template +inline void Vector::insert(const Type& value, i32 index) { + if(index < 0 || index > M_length) { + return; + } + + if(M_length + 1 > M_capacity) { + resize(M_capacity *= 2); + } + + for(i32 i = M_length; i > index; i -= 1) { + M_data[i] = M_data[i - 1]; + } + + M_length += 1; + + M_data[index] = value; +} + + +template +inline void Vector::erase(i32 index) { + if(index < 0 || index > M_length) { + return; + } + + M_length -= 1; + + for(i32 i = index; i < M_length; i += 1) { + M_data[i] = M_data[i + 1]; + } +} + + +template +inline void Vector::push(const Type& value) { + if(M_length + 1 > M_capacity) { + resize(M_capacity *= 2); + } + + M_data[M_length] = value; + M_length += 1; +} + + +template +inline void Vector::resize(i32 new_capacity) { + if(new_capacity < 0) { + return; + } + + M_capacity = new_capacity; + + Type* new_data = new Type[new_capacity]; + + if(new_capacity < M_length) { + M_length = new_capacity; + } + + for(i32 i = 0; i < M_length; i += 1) { + new_data[i] = M_data[i]; + } + + delete[] M_data; + + M_data = new_data; +} + + +template +inline void Vector::pop() { + --M_length; +} diff --git a/Source/Core/ScalarDataTypes.hpp b/src/Core/ScalarDataTypes.hpp similarity index 100% rename from Source/Core/ScalarDataTypes.hpp rename to src/Core/ScalarDataTypes.hpp diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 0000000..44cff64 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,41 @@ +#include + +#include +using namespace std::chrono; + +#define KRAKEN_DEBUG 1 + +#include +#include + +class Timer { + public: + void start() { + M_start_time = high_resolution_clock::now();; + } + + void stop() { + M_stop_time = high_resolution_clock::now(); + } + + std::chrono::nanoseconds duration() { + auto d = duration_cast(M_stop_time - M_start_time); + return d; + } + + private: + std::chrono::_V2::system_clock::time_point M_start_time, M_stop_time; +}; + +void print_vector(const Vector& v) { + for(i32 i = 0; i < v.length(); i += 1) { + std::cout << v[i] << ' '; + } + std::cout << std::endl; +} + +i32 main() { + { + Vector v; + } +} \ No newline at end of file diff --git a/target/Kraken-Core.exe b/target/Kraken-Core.exe new file mode 100644 index 0000000..0441bfc Binary files /dev/null and b/target/Kraken-Core.exe differ