Skip to content

Commit

Permalink
Add SparseArray
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeAbel committed Sep 20, 2023
1 parent 3ad782c commit 2d1e858
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/poc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.27)

set(PROJECT_NAME poc)

project(
${PROJECT_NAME}
VERSION 1.0.0
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 20)

add_executable(
${PROJECT_NAME}
)

if(MSVC)
target_compile_options(
${PROJECT_NAME}
PRIVATE
/W4
)
else()
target_compile_options(
${PROJECT_NAME}
PRIVATE
-Wall -Wextra
)
endif()

add_subdirectory(src)

if (WIN32)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${PROJECT_NAME}>
${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.exe
)
else()
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${PROJECT_NAME}>
${CMAKE_SOURCE_DIR}/${PROJECT_NAME}
)
endif()
13 changes: 13 additions & 0 deletions src/poc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.27)

target_include_directories(
${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_sources(
${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/mainSparseArray.cpp
)
33 changes: 33 additions & 0 deletions src/poc/src/SparseArray.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iterator>
#include <list>

template <typename Component>
class SparseArray {
public:
void add(Component component)
{
_components.push_back(component);
};
void erase(int id)
{
auto it = _components.begin();
std::advance(it, id);
_components.erase(it);
};
Component &operator[](size_t idx)
{
return _components[idx];
}

std::list<Component>::iterator begin()
{
return _components.begin();
}

std::list<Component>::iterator end()
{
return _components.end();
}
private:
std::list<Component> _components;
};

0 comments on commit 2d1e858

Please sign in to comment.