VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
componentSystemRegistry.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 10.09.2025.
5//
6#pragma once
7
8#include <typeindex>
9#include <unordered_map>
10
11#include "core/eventHandler.h"
12
13namespace visutwin::canvas
14{
15 class IComponentSystem;
16
17 /*
18 * The ComponentSystemRegistry manages the instances of an application's ComponentSystems
19 */
21 {
22 public:
23 void add(std::unique_ptr<IComponentSystem> system);
24
25 IComponentSystem* getById(const std::string& id) const;
26
27 template<typename ComponentType>
29 {
30 const auto it = _systemsByComponentType.find(std::type_index(typeid(ComponentType)));
31 return it != _systemsByComponentType.end() ? it->second : nullptr;
32 }
33
38 IComponentSystem* getByComponentTypeInfo(const std::type_info& typeInfo) const
39 {
40 const auto it = _systemsByComponentType.find(std::type_index(typeInfo));
41 return it != _systemsByComponentType.end() ? it->second : nullptr;
42 }
43
44 private:
45 std::vector<std::unique_ptr<IComponentSystem>> _ownedSystems;
46 std::unordered_map<std::string, IComponentSystem*> _systems;
47 std::unordered_map<std::type_index, IComponentSystem*> _systemsByComponentType;
48 };
49}
IComponentSystem * getById(const std::string &id) const
IComponentSystem * getByComponentTypeInfo(const std::type_info &typeInfo) const
void add(std::unique_ptr< IComponentSystem > system)