PLCnext API Documentation 25.0.2.69
LibraryBase.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/CommonTypeName.hxx"
9#include "Arp/Base/Acf/Commons/ILibrary.hpp"
10#include "Arp/Base/Acf/Commons/IComponentFactory.hpp"
11
12namespace Arp::Base::Acf::Commons
13{
14
17class ARP_EXPORT LibraryBase : public ILibrary
18{
19public: // Impl forward declaration
20 class Impl;
21
22public: // usings
25
26public: // construction/destruction/assignment
27 explicit LibraryBase(const ArpVersion& libraryVersion = ArpVersion{});
28 LibraryBase(const LibraryBase& arg) = delete;
29 LibraryBase(LibraryBase&& arg)noexcept;
30 LibraryBase& operator=(const LibraryBase& arg) = delete;
32 ~LibraryBase(void)override;
33
34public: // ILibrary operations
35 void Initialize(void)override;
36 void Dispose(void)override;
37 IComponentFactory& GetComponentFactory(void)override;
38 const ArpVersion& GetBuildVersion(void)const override;
39 const ArpVersion& GetLibraryVersion(void)const override;
40 String GetLibraryInfoItem(LibraryInfoKind kind)const override;
41
42public: // factory operations
43 template<class T> void AddComponentType(void);
44 template<class T> void RegisterComponentType(void);
45 template<class T> void RegisterComponentType(const String& typeName);
46
47public: // internal operations
48 Impl& GetImpl(void);
49 const Impl& GetImpl(void)const;
50
51private: // methods
52 void AddComponentTypeImpl(const String& typeName, FactoryMethod factoryMethod);
53 void RegisterComponentTypeImpl(const String& typeName, FactoryMethodCompat factoryMethod);
54
55private: // Impl usings
56 using Pimpl = PimplPtr<Impl>;
57
58private: // Impl fields
59 Pimpl pimpl;
60};
61
64template<class T>
66{
67 auto createComponent = [](ILibrary & library, const String& componentName) -> IComponent::Ptr
68 {
69 return std::make_shared<T>(library, componentName);
70 };
71 this->AddComponentTypeImpl(TypeName<T>().GetFullName(), createComponent);
72 this->AddComponentTypeImpl(CommonTypeName<T>().GetFullName(), createComponent);
73}
74
78template<class T>
80{
81 this->RegisterComponentTypeImpl(TypeName<T>().GetFullName(), &T::Create);
82}
83
88template<class T>
89inline void LibraryBase::RegisterComponentType(const String& typeName)
90{
91 this->RegisterComponentTypeImpl(typeName, &T::Create);
92}
93
94} // end of namespace Arp::Base::Acf::Commons
95
96namespace Arp::System::Acf
97{
99}
This interface is used by the Acf to create components dynamically through configuration (....
Definition: IComponentFactory.hpp:20
IComponent::Ptr(*)(ILibrary &library, const String &componentName) FactoryMethod
The prototype of the component factory method, which might be registered to create components.
Definition: IComponentFactory.hpp:24
IComponent::Ptr(*)(Application &application, const String &componentName) FactoryMethodCompat
The deprecated prototype of the component factory method, which might be registered to create compone...
Definition: IComponentFactory.hpp:27
std::shared_ptr< IComponent > Ptr
The pointer type of this interface.
Definition: IComponent.hpp:83
Any Acf Library shall implement this interface.
Definition: ILibrary.hpp:20
This class serves as base class of all Library classes in Arp component projects.
Definition: LibraryBase.hpp:18
IComponentFactory::FactoryMethod FactoryMethod
The prototype of the component factory method.
Definition: LibraryBase.hpp:23
LibraryBase & operator=(LibraryBase &&arg) noexcept
The default move-assignment operator.
LibraryBase(LibraryBase &&arg) noexcept
The default move constructor.
void RegisterComponentType(void)
Registers a type of a component of this library.
Definition: LibraryBase.hpp:79
void AddComponentType(void)
Registers a type of a component of this library.
Definition: LibraryBase.hpp:65
~LibraryBase(void) override
The default destructor.
IComponentFactory::FactoryMethodCompat FactoryMethodCompat
The deprecated prototype of the component factory method.
Definition: LibraryBase.hpp:24
This class compounds Arp build version and infos.
Definition: ArpVersion.hpp:21
This (meta programming) class provides the type-name according the CLS (common language specification...
Definition: CommonTypeName.hxx:33
Adapter class to implement PImpl idiom.
Definition: PimplPtr.hxx:15
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
This (meta programming) class provides the C++ type-name of the as template argument passed type.
Definition: TypeName.hxx:20
This is the namespace of the Application Component Framework.
Definition: ComponentBase.hpp:72