PLCnext API Documentation 25.0.2.69
RscComponentServiceImplBase.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/Commons/Exceptions/InvalidCastException.hpp"
10#include "Arp/Base/Acf/Commons/IComponent.hpp"
11
12namespace Arp::Base::Rsc::Commons::Services
13{
14
15// type imports
17
25{
26public: // construction
27 explicit RscComponentServiceImplBase(IComponent& component);
28
29public: // operations
30 template<class T>
31 T& GetComponent(void);
32 IComponent& GetComponent(void);
33
34private: // fields
35 IComponent& component;
36};
37
39// inline methods of class RscComponentServiceImplBase
40
45template<class T>
47{
48 // type imports
50
51 if (!IsInstanceOfType<T>(this->component))
52 {
53 throw InvalidCastException("RSC service component '{0}' does not implement required interface '{1}'.",
54 this->component.GetFullName(),
56 }
57 // else
58 return dynamic_cast<T&>(this->component);
59}
60
61} // end of namespace Arp::Base::Rsc::Commons::Services
This is the most important basic interface of the Arp platform. Any component shall implement this in...
Definition: IComponent.hpp:79
virtual String GetFullName(void) const =0
Gets the full qualified name of this component
This exception is thrown when an invalid cast occurs.
Definition: InvalidCastException.hpp:17
String GetFullName(void) const
Gets the full type-name of this instance.
Definition: TypeNameBase.cpp:101
This (meta programming) class provides the C++ type-name of the as template argument passed type.
Definition: TypeName.hxx:20
Base class for RSC component services. Holds a reference to the associated component.
Definition: RscComponentServiceImplBase.hpp:25
T & GetComponent(void)
Gets a reference to the associated component.
Definition: RscComponentServiceImplBase.hpp:46