PLCnext API Documentation 23.6.0.37
RscComponentServiceImplBase.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/TypeName.hxx"
9#include "Arp/System/Commons/Exceptions/InvalidCastException.hpp"
10#include "Arp/System/Acf/IComponent.hpp"
11namespace Arp { namespace System { namespace Rsc { namespace Services
12{
13
14using namespace Arp::System::Acf;
15
20{
21public: // construction/destruction
26
27public: // setter/getter operations
28
29public: // operations
36 template<class T>
37 T& GetComponent(void);
38
44
45private: // fields
46 IComponent& component;
47};
48
50// inline methods of class RscComponentServiceImplBase
52 : component(componentArg)
53{
54}
55
56template<class T>
58{
60
61 if (!IsInstanceOfType<T>(this->component))
62 {
63 throw InvalidCastException("Rsc service component '{0}' does not implement reqested interface '{1}'.", this->component.GetFullName(), TypeName<T>().GetCommonName());
64 }
65 // else
66 return dynamic_cast<T&>(this->component);
67}
68
70{
71 return this->component;
72}
73
74}}}} // end of namespace Arp::System::Rsc::Services
This is the most important basic interface of the Arp platform. Any component shall implement this in...
Definition: IComponent.hpp:81
virtual String GetFullName(void) const =0
Gets the full qualified name of this component
This exception is used when an invalid cast occurs.
Definition: InvalidCastException.hpp:15
Base class for Rsc component service implementations. Contains reference to associated component.
Definition: RscComponentServiceImplBase.hpp:20
T & GetComponent(void)
Gets a reference to the associated service. Throws if T doesn't match type of component.
Definition: RscComponentServiceImplBase.hpp:57
RscComponentServiceImplBase(IComponent &component)
Constructs an RscComponentServiceImplBase instance.
Definition: RscComponentServiceImplBase.hpp:51
~RscComponentServiceImplBase(void)=default
Destructs this instance and frees all resources.
This (meta programming) class provides the C++ typename of the as template argument passed type.
Definition: TypeName.hxx:67
String GetCommonName(void) const
Gets the common name of the as template parameter given type according to the CLS.
Definition: TypeName.hxx:156
This is the namespace of the Application Component Framework.
Definition: ComponentBase.hpp:13
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API