PLCnext API Documentation 23.6.0.37
ComponentFactory.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Acf/IComponentFactory.hpp"
9#include <map>
10
11namespace Arp { namespace System { namespace Acf
12{
13
17{
18public: // typedefs
20 typedef IComponent::Ptr (*FactoryMethod)(IApplication& application, const String& componentName);
21
22private: // typedefs
23 typedef std::map<String, FactoryMethod> FactoryMethods;
24
25public: // construction/destruction
26 ComponentFactory(void) = default;
27 virtual ~ComponentFactory(void) = default;
28
29public: // overridden operations from IComponentFactory
30 bool HasComponentType(const String& typeName)override;
31 IComponent::Ptr CreateComponent(IApplication& application, const String& componentType, const String& componentName)override;
32
33public: // operations
38 bool AddFactoryMethod(const String& componentType, FactoryMethod factoryMethod);
39
40private: // ComponentFactory methods to avoid copying
41 ComponentFactory(const ComponentFactory& arg) = default;
42 ComponentFactory& operator=(const ComponentFactory& arg) = default;
43
44private: // fields
45 FactoryMethods factoryMethods;
46};
47
49// inline methods of class ComponentFactory
50inline bool ComponentFactory::HasComponentType(const String& typeName)
51{
52 return this->factoryMethods.find(typeName) != this->factoryMethods.end();
53}
54
55inline bool ComponentFactory::AddFactoryMethod(const String& componentType, FactoryMethod factoryMethod)
56{
57 return this->factoryMethods.insert(std::make_pair(componentType, factoryMethod)).second;
58}
59
60}}} // end of namesapce Arp::System::Acf
This class is used by Acf libraries to provide a component factory of the library specific components...
Definition: ComponentFactory.hpp:17
IComponent::Ptr(* FactoryMethod)(IApplication &application, const String &componentName)
The prototype of the component factory method, which might be registered to create components.
Definition: ComponentFactory.hpp:20
bool AddFactoryMethod(const String &componentType, FactoryMethod factoryMethod)
Adds a component specific factory method to this factory.
Definition: ComponentFactory.hpp:55
IComponent::Ptr CreateComponent(IApplication &application, const String &componentType, const String &componentName) override
Creates a component of the given typename.
bool HasComponentType(const String &typeName) override
Determines if this factory provides components of the given typename.
Definition: ComponentFactory.hpp:50
This interface shall be implemented by the application class.
Definition: IApplication.hpp:19
This interface is used by the Acf to create components dynamiically through configuration (....
Definition: IComponentFactory.hpp:19
std::shared_ptr< IComponent > Ptr
The pointer type of this interface.
Definition: IComponent.hpp:84
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API