SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
component_registry.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <
core/component.hpp
>
21
22
#include <functional>
23
#include <map>
24
#include <memory>
25
#include <stdexcept>
26
#include <string>
27
#include <string_view>
28
#include <vector>
29
30
namespace
SILICON::core
{
31
32
class
Component
;
33
using
Component_ptr
= std::shared_ptr<Component>;
34
35
class
ComponentRegistry
{
36
public
:
37
using
Factory
= std::function<
Component_ptr
()>;
38
using
ComponentCategory
=
SILICON::core::ComponentCategory
;
39
using
ComponentMetadata
=
SILICON::core::ComponentMetadata
;
40
41
ComponentRegistry
();
42
static
ComponentRegistry
empty
();
43
static
ComponentRegistry
&
instance
();
44
45
void
registerType
(std::string type,
Factory
factory);
46
Component_ptr
create
(std::string_view type)
const
;
47
bool
hasType
(std::string_view type)
const
;
48
ComponentMetadata
metadata
(std::string_view type)
const
;
49
std::vector<std::string>
availableTypes
()
const
;
50
51
private
:
52
struct
Entry
{
53
Factory
factory
;
54
};
55
56
std::map<std::string, Entry, std::less<>>
types
;
57
};
58
59
std::string_view
componentCategoryName
(
ComponentCategory
category);
60
61
}
// namespace SILICON::core
SILICON::core::ComponentRegistry::ComponentRegistry
ComponentRegistry()
SILICON::core::ComponentRegistry::ComponentCategory
SILICON::core::ComponentCategory ComponentCategory
Definition
component_registry.hpp:38
SILICON::core::ComponentRegistry::Factory
std::function< Component_ptr()> Factory
Definition
component_registry.hpp:37
SILICON::core::ComponentRegistry::types
std::map< std::string, Entry, std::less<> > types
Definition
component_registry.hpp:56
SILICON::core::ComponentRegistry::empty
static ComponentRegistry empty()
Definition
component_registry.cpp:29
SILICON::core::ComponentRegistry::create
Component_ptr create(std::string_view type) const
Definition
component_registry.cpp:64
SILICON::core::ComponentRegistry::metadata
ComponentMetadata metadata(std::string_view type) const
Definition
component_registry.cpp:78
SILICON::core::ComponentRegistry::instance
static ComponentRegistry & instance()
Definition
component_registry.cpp:34
SILICON::core::ComponentRegistry::availableTypes
std::vector< std::string > availableTypes() const
Definition
component_registry.cpp:87
SILICON::core::ComponentRegistry::registerType
void registerType(std::string type, Factory factory)
Definition
component_registry.cpp:49
SILICON::core::ComponentRegistry::ComponentMetadata
SILICON::core::ComponentMetadata ComponentMetadata
Definition
component_registry.hpp:39
SILICON::core::ComponentRegistry::hasType
bool hasType(std::string_view type) const
Definition
component_registry.cpp:73
SILICON::core::Component
Base class for all digital circuit components.
Definition
component.hpp:199
component.hpp
SILICON::core
Definition
activeKeyGuard.hpp:28
SILICON::core::Component_ptr
std::shared_ptr< Component > Component_ptr
Definition
component_registry.hpp:33
SILICON::core::ComponentCategory
ComponentCategory
Definition
component.hpp:47
SILICON::core::componentCategoryName
std::string_view componentCategoryName(const ComponentCategory category)
Definition
component_registry.cpp:97
SILICON::core::ComponentMetadata
Definition
component.hpp:72
SILICON::core::ComponentRegistry::Entry
Definition
component_registry.hpp:52
SILICON::core::ComponentRegistry::Entry::factory
Factory factory
Definition
component_registry.hpp:53
src
core
serialization
component_registry.hpp
Generated by
1.17.0