diff --git a/.gitignore b/.gitignore index fc632cff..16e4adb6 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,13 @@ build/ .vs/ *.ini !dllTest/* + +#CMake +*.vcxproj* +CmakeCache* +CmakeFiles/ +Debug/ +cmake_* +*.dir/ +*.sln +x64/ \ No newline at end of file diff --git a/src/poc/src/CMakeLists.txt b/src/poc/src/CMakeLists.txt index 15fa4ad7..9db8e421 100644 --- a/src/poc/src/CMakeLists.txt +++ b/src/poc/src/CMakeLists.txt @@ -13,5 +13,4 @@ target_sources( ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Registry.cpp ) diff --git a/src/poc/src/Registry.cpp b/src/poc/src/Registry.cpp deleted file mode 100644 index a8317376..00000000 --- a/src/poc/src/Registry.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Registry.hpp" - -Registry::Registry() -{ -} - -Registry::~Registry() -{ -} diff --git a/src/poc/src/Registry.hpp b/src/poc/src/Registry.hpp index e0fb2afa..1d8c39ea 100644 --- a/src/poc/src/Registry.hpp +++ b/src/poc/src/Registry.hpp @@ -1,5 +1,38 @@ +#include +#include +#include +#include +#include "SparseArray.hpp" +#include + class Registry { public: - Registry(); - ~Registry(); + template + using array = std::shared_ptr>; + + template + array registerComponent() + { + if (_data.find(typeid(Component)) == _data.end()) { + _data[typeid(Component)] = std::make_shared>(); + } + return castReturn(); + }; + template + array getComponents() + { + return castReturn(); + }; + template + array const &getComponents() const + { + return castReturn(); + }; + private: + template + array castReturn() + { + return std::any_cast>(_data[typeid(Component)]); + } + std::unordered_map _data; }; diff --git a/src/poc/src/main.cpp b/src/poc/src/main.cpp new file mode 100644 index 00000000..ceaa551b --- /dev/null +++ b/src/poc/src/main.cpp @@ -0,0 +1,20 @@ +#include +#include "Registry.hpp" + +int main() +{ + Registry registry; + Registry::array arrInt = registry.registerComponent(); + arrInt->add(4); + arrInt->add(69); + Registry::array arrFloat = registry.registerComponent(); + arrFloat->add(69.69); + Registry::array scdContainer = registry.getComponents(); + for (auto begin = arrInt->begin(); begin != arrInt->end(); begin++) { + std::cout << *begin << std::endl; + } + for (auto begin = scdContainer->begin(); begin != scdContainer->end(); begin++) { + std::cout << *begin << std::endl; + } + return 0; +}