SILICON
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
30namespace SILICON::core {
31
32class Component;
33using Component_ptr = std::shared_ptr<Component>;
34
36public:
37 using Factory = std::function<Component_ptr()>;
40
42 static ComponentRegistry empty();
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
51private:
52 struct Entry {
54 };
55
56 std::map<std::string, Entry, std::less<>> types;
57};
58
59std::string_view componentCategoryName(ComponentCategory category);
60
61} // namespace SILICON::core
SILICON::core::ComponentCategory ComponentCategory
std::function< Component_ptr()> Factory
std::map< std::string, Entry, std::less<> > types
static ComponentRegistry empty()
Component_ptr create(std::string_view type) const
ComponentMetadata metadata(std::string_view type) const
static ComponentRegistry & instance()
std::vector< std::string > availableTypes() const
void registerType(std::string type, Factory factory)
SILICON::core::ComponentMetadata ComponentMetadata
bool hasType(std::string_view type) const
Base class for all digital circuit components.
std::shared_ptr< Component > Component_ptr
std::string_view componentCategoryName(const ComponentCategory category)