PLCnext API Documentation 26.0.1.58
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
29 // canonical construction/destruction/assignment
30 LibraryBase(const LibraryBase& arg) = delete;
31 LibraryBase(LibraryBase&& arg)noexcept;
32 LibraryBase& operator=(const LibraryBase& arg) = delete;
34 ~LibraryBase(void)override;
35
36public: // ILibrary operations
37 void Initialize(void)override;
38 void Dispose(void)override;
39 IComponentFactory& GetComponentFactory(void)override;
40 const ArpVersion& GetBuildVersion(void)const override;
41 const ArpVersion& GetLibraryVersion(void)const override;
42 String GetLibraryInfoItem(LibraryInfoKind kind)const override;
43
44public: // factory operations
45 template<class T> void AddComponentType(void);
46 template<class T> void RegisterComponentType(void);
47 template<class T> void RegisterComponentType(const String& typeName);
48
49protected:
50 void SetLibraryInfoItem(LibraryInfoKind kind, const String& value);
51 void SetSdkBuildInfo(const ArpVersion& buildVersion, const String& abiVersion, const String& targetIdentifier);
52
53public: // internal operations
54 Impl& GetImpl(void);
55 const Impl& GetImpl(void)const;
56
57private: // methods
58 void AddComponentTypeImpl(const String& typeName, FactoryMethod factoryMethod);
59 void RegisterComponentTypeImpl(const String& typeName, FactoryMethodCompat factoryMethod);
60
61private: // Impl usings
62 using Pimpl = PimplPtr<Impl>;
63
64private: // Impl fields
65 Pimpl pimpl;
66};
67
70template<class T>
72{
73 auto createComponent = [](ILibrary & library, const String& componentName) -> IComponent::Ptr
74 {
75 return std::make_shared<T>(library, componentName);
76 };
77 this->AddComponentTypeImpl(TypeName<T>().GetFullName(), createComponent);
78 this->AddComponentTypeImpl(CommonTypeName<T>().GetFullName(), createComponent);
79}
80
84template<class T>
86{
87 this->RegisterComponentTypeImpl(TypeName<T>().GetFullName(), &T::Create);
88}
89
94template<class T>
95inline void LibraryBase::RegisterComponentType(const String& typeName)
96{
97 this->RegisterComponentTypeImpl(typeName, &T::Create);
98}
99
100} // end of namespace Arp::Base::Acf::Commons
101
102namespace Arp::System::Acf
103{
105}
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:85
void AddComponentType(void)
Registers a type of a component of this library.
Definition: LibraryBase.hpp:71
~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:75