From f8bc2a06a90c0ee172054db7ae2e1fdae09d14a3 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 6 Oct 2024 14:10:52 +0200 Subject: code standard v3 --- src/crepe/ComponentManager.hpp | 74 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'src/crepe/ComponentManager.hpp') diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 30b0e38..999cdcf 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -5,15 +5,16 @@ namespace crepe { template -void ComponentManager::add_component(std::uint32_t id, Args &&... args) { +void ComponentManager::add_component(uint32_t id, Args &&... args) { + using namespace std; + // Determine the type of T (this is used as the key of the unordered_map<>) - std::type_index type = typeid(T); + type_index type = typeid(T); // Check if this component type is already in the unordered_map<> if (components.find(type) == components.end()) { //If not, create a new (empty) vector<> of vector> - components[type] - = std::vector>>(); + components[type] = vector>>(); } // Resize the vector<> if the id is greater than the current size @@ -24,25 +25,26 @@ void ComponentManager::add_component(std::uint32_t id, Args &&... args) { // Create a new component of type T using perfect forwarding and store its // unique_ptr in the vector<> - components[type][id].push_back( - std::make_unique(std::forward(args)...)); + components[type][id].push_back(make_unique(forward(args)...)); } template -void ComponentManager::delete_components_by_id(std::uint32_t id) { +void ComponentManager::delete_components_by_id(uint32_t id) { + using namespace std; + // Determine the type of T (this is used as the key of the unordered_map<>) - std::type_index type = typeid(T); + type_index type = typeid(T); // Find the type (in the unordered_map<>) if (components.find(type) != components.end()) { // Get the correct vector<> - std::vector>> & componentArray + vector>> & component_array = components[type]; // Make sure that the id (that we are looking for) is within the boundaries of the vector<> - if (id < componentArray.size()) { + if (id < component_array.size()) { // Clear the whole vector<> of this specific type and id - componentArray[id].clear(); + component_array[id].clear(); } } } @@ -61,72 +63,74 @@ void ComponentManager::delete_components() { template std::vector> -ComponentManager::get_components_by_id(std::uint32_t id) const { +ComponentManager::get_components_by_id(uint32_t id) const { + using namespace std; + // Determine the type of T (this is used as the key of the unordered_map<>) - std::type_index type = typeid(T); + type_index type = typeid(T); // Create an empty vector<> - std::vector> componentVector; + vector> component_vector; // Find the type (in the unordered_map<>) if (components.find(type) != components.end()) { // Get the correct vector<> - const std::vector>> & - componentArray + const vector>> & component_array = components.at(type); // Make sure that the id (that we are looking for) is within the boundaries of the vector<> - if (id < componentArray.size()) { + if (id < component_array.size()) { // Loop trough the whole vector<> - for (const std::unique_ptr & componentPtr : - componentArray[id]) { + for (const unique_ptr & component_ptr : + component_array[id]) { // Cast the unique_ptr to a raw pointer - T * castedComponent = static_cast(componentPtr.get()); + T * casted_component = static_cast(component_ptr.get()); // Ensure that the cast was successful - if (castedComponent) { + if (casted_component) { // Add the dereferenced raw pointer to the vector<> - componentVector.push_back(*castedComponent); + component_vector.push_back(*casted_component); } } } } // Return the vector<> - return componentVector; + return component_vector; } template std::vector> ComponentManager::get_components_by_type() const { + using namespace std; + // Determine the type of T (this is used as the key of the unordered_map<>) - std::type_index type = typeid(T); + type_index type = typeid(T); // Create an empty vector<> - std::vector> componentVector; + vector> component_vector; // Set the id to 0 (the id will also be stored in the returned vector<>) - // std::uint32_t id = 0; + // uint32_t id = 0; // Find the type (in the unordered_map<>) if (components.find(type) != components.end()) { // Get the correct vector<> - const std::vector>> & - componentArray + const vector>> & component_array = components.at(type); // Loop through the whole vector<> - for (const std::vector> & component : - componentArray) { + for (const vector> & component : + component_array) { // Loop trough the whole vector<> - for (const std::unique_ptr & componentPtr : component) { + for (const unique_ptr & component_ptr : component) { // Cast the unique_ptr to a raw pointer - T * castedComponent = static_cast(componentPtr.get()); + T * casted_component = static_cast(component_ptr.get()); // Ensure that the cast was successful - if (castedComponent) { + if (casted_component) { // Pair the dereferenced raw pointer and the id and add it to the vector<> - componentVector.emplace_back(std::ref(*castedComponent)); + component_vector.emplace_back(ref(*casted_component)); } } @@ -136,7 +140,7 @@ ComponentManager::get_components_by_type() const { } // Return the vector<> - return componentVector; + return component_vector; } } // namespace crepe -- cgit v1.2.3