PLCnext API Documentation  22.3.0.20
RscComponentServiceImplBase.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/TypeName.hxx"
9 #include "Arp/System/Commons/Exceptions/InvalidCastException.hpp"
10 #include "Arp/System/Acf/IComponent.hpp"
11 namespace Arp { namespace System { namespace Rsc { namespace Services
12 {
13 
14 using namespace Arp::System::Acf;
15 
20 {
21 public: // construction/destruction
25  ~RscComponentServiceImplBase(void) = default;
26 
27 public: // setter/getter operations
28 
29 public: // operations
36  template<class T>
37  T& GetComponent(void);
38 
43  IComponent& GetComponent(void);
44 
45 private: // fields
46  IComponent& component;
47 };
48 
50 // inline methods of class RscComponentServiceImplBase
52  : component(componentArg)
53 {
54 }
55 
56 template<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
virtual String GetFullName(void) const =0
Gets the full qualified name of this component
This (meta programming) class provides the C++ typename of the as template argument passed type...
Definition: TypeName.hxx:55
This is the most important basic interface of the Arp platform. Any component shall implement this in...
Definition: IComponent.hpp:80
This exception is used when an invalid cast occurs.
Definition: InvalidCastException.hpp:14
RscComponentServiceImplBase(IComponent &component)
Constructs an RscComponentServiceImplBase instance.
Definition: RscComponentServiceImplBase.hpp:51
Root namespace for the PLCnext API
Base class for Rsc component service implementations. Contains reference to associated component...
Definition: RscComponentServiceImplBase.hpp:19
System components used by the System, Device, Plc or Io domains.
T & GetComponent(void)
Gets a reference to the associated service. Throws if T doesn&#39;t match type of component.
Definition: RscComponentServiceImplBase.hpp:57
This is the namespace of the Application Component Framework.
Definition: ComponentBase.hpp:12