wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementMetadata.cpp
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
5
6#include "App/Core/Common.h"
7
8QMap<ElementType, ElementMetadata> &ElementMetadataRegistry::registry()
9{
10 // QMap (not QHash): registrations happen via static-inline lambdas in each
11 // element's .cpp translation unit before QApplication::exec() runs, and
12 // iteration order over this registry is otherwise unspecified between
13 // runs/platforms unless insertion order is preserved — some serialization
14 // paths rely on that. Single-threaded at startup; concurrent access after
15 // is undefined.
16 static QMap<ElementType, ElementMetadata> s_registry;
17 return s_registry;
18}
19
21{
22 registry()[meta.type] = meta;
23}
24
26{
27 auto &reg = registry();
28
29 if (!reg.contains(type)) {
30 throw PANDACEPTION_WITH_CONTEXT("ElementMetadataRegistry", "No metadata registered for element type: %1", static_cast<int>(type));
31 }
32
33 return reg[type];
34}
35
37{
38 return registry().contains(type);
39}
Common logging utilities, the Pandaception error type, and helper macros.
#define PANDACEPTION_WITH_CONTEXT(context, msg,...)
Definition Common.h:102
Element metadata struct and global registry for compile-time element registration.
Enums::ElementType ElementType
Definition Enums.h:107
static bool hasMetadata(ElementType type)
Returns true if metadata has been registered for type.
static void registerMetadata(const ElementMetadata &meta)
Registers meta in the global map (called once per element type at startup).
static const ElementMetadata & metadata(ElementType type)
Returns the metadata for type. Asserts if type is not registered.
Compile-time-registered properties for one element type.
ElementType type
Unique element type identifier.