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