SILICON
Loading...
Searching...
No Matches
GUIComponentFactory Class Reference

Factory for creating graphical circuit components. More...

#include <gui_component_factory.hpp>

Classes

struct  Entry
 Map of type names to factory functions. More...

Public Types

using Factory = std::function<std::unique_ptr<GraphicalComponent>(QGraphicsItem*)>
 Factory function type for creating components.

Public Member Functions

 GUIComponentFactory ()
void registerType (std::string type, Factory factory)
 Registers a component type.
void registerType (std::string type, Factory factory, EntryMetadata metadata)
std::unique_ptr< GraphicalComponent > create (std::string_view type, QGraphicsItem *parent=nullptr) const
 Creates a component by type name.
std::unique_ptr< GraphicalComponent > createForCoreType (std::string_view coreType, QGraphicsItem *parent=nullptr) const
 Creates the graphical component registered for a core component type.
std::vector< std::string > availableTypes () const
 Gets all available component types.
const EntryMetadata & metadata (std::string_view type) const
bool hasType (std::string_view type) const
 Checks if a type is registered.

Static Public Member Functions

static GUIComponentFactory empty ()
 Creates an empty factory without registered types.
static GUIComponentFactory & instance ()
 Gets the global singleton factory instance.

Private Attributes

std::map< std::string, Entry, std::less<> > factories

Detailed Description

Factory for creating graphical circuit components.

The GUIComponentFactory implements a registry pattern for creating GraphicalComponent instances by type name. It supports registration of custom component types and provides a singleton instance for global access.

Components are registered via registerType() and created via create(). This allows for extensible component libraries without modifying the core factory code.

See also
GraphicalComponent
GraphicalLogicComponent

Definition at line 55 of file gui_component_factory.hpp.

Member Typedef Documentation

◆ Factory

using Factory = std::function<std::unique_ptr<GraphicalComponent>(QGraphicsItem*)>

Factory function type for creating components.

Parameters
parentOptional parent graphics item
Returns
Unique pointer to created component

Definition at line 63 of file gui_component_factory.hpp.

Constructor & Destructor Documentation

◆ GUIComponentFactory()

GUIComponentFactory ( )
default

Member Function Documentation

◆ availableTypes()

std::vector< std::string > availableTypes ( ) const

Gets all available component types.

Returns
Vector of type name strings

Definition at line 101 of file gui_component_factory.cpp.

◆ create()

std::unique_ptr< GraphicalComponent > create ( std::string_view type,
QGraphicsItem * parent = nullptr ) const

Creates a component by type name.

Parameters
typeThe type identifier
parentOptional parent graphics item
Returns
Unique pointer to created component
Exceptions
std::runtime_errorif type is unknown

Definition at line 61 of file gui_component_factory.cpp.

◆ createForCoreType()

std::unique_ptr< GraphicalComponent > createForCoreType ( std::string_view coreType,
QGraphicsItem * parent = nullptr ) const

Creates the graphical component registered for a core component type.

Parameters
coreTypeThe core component type identifier
parentOptional parent graphics item
Returns
Unique pointer to the matching graphical component
Exceptions
std::runtime_errorif no graphical type, or more than one graphical type, is registered for the core type

Definition at line 72 of file gui_component_factory.cpp.

◆ empty()

GUIComponentFactory empty ( )
static

Creates an empty factory without registered types.

Returns
New empty factory instance

Definition at line 26 of file gui_component_factory.cpp.

◆ hasType()

bool hasType ( std::string_view type) const

Checks if a type is registered.

Parameters
typeThe type to check
Returns
True if the type exists

Definition at line 111 of file gui_component_factory.cpp.

◆ instance()

GUIComponentFactory & instance ( )
static

Gets the global singleton factory instance.

Returns
Reference to the singleton

Definition at line 31 of file gui_component_factory.cpp.

◆ metadata()

const GUIComponentFactory::EntryMetadata & metadata ( std::string_view type) const

Definition at line 117 of file gui_component_factory.cpp.

◆ registerType() [1/2]

void registerType ( std::string type,
Factory factory )

Registers a component type.

Parameters
typeThe type identifier string
factoryThe factory function
Exceptions
std::logic_errorif type is already registered

Definition at line 37 of file gui_component_factory.cpp.

◆ registerType() [2/2]

void registerType ( std::string type,
Factory factory,
EntryMetadata metadata )

Definition at line 43 of file gui_component_factory.cpp.

Member Data Documentation

◆ factories

std::map<std::string, Entry, std::less<> > factories
private

Definition at line 139 of file gui_component_factory.hpp.


The documentation for this class was generated from the following files: