PLCnext API Documentation  21.0.0.35466
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 using namespace Arp::System::Commons;
16 
21 {
22 public: // construction/destruction
26  ~RscComponentServiceImplBase(void) = default;
27 
28 public: // setter/getter operations
29 
30 public: // operations
37  template<class T>
38  T& GetComponent(void);
39 
44  IComponent& GetComponent(void);
45 
46 private: // fields
47  IComponent& component;
48 };
49 
51 // inline methods of class RscComponentServiceImplBase
53  : component(componentArg)
54 {
55 }
56 
57 template<class T>
59 {
60  if (!IsInstanceOfType<T>(this->component))
61  {
62  throw InvalidCastException("Rsc service component '{0}' does not implement reqested interface '{1}'.", this->component.GetFullName(), TypeName<T>().GetCommonName());
63  }
64  // else
65  return dynamic_cast<T&>(this->component);
66 }
67 
69 {
70  return this->component;
71 }
72 
73 }}}} // 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:77
This exception is used when an invalid cast occurs.
Definition: InvalidCastException.hpp:14
RscComponentServiceImplBase(IComponent &component)
Constructs an RscComponentServiceImplBase instance.
Definition: RscComponentServiceImplBase.hpp:52
Root namespace for the PLCnext API
Base class for Rsc component service implementations. Contains reference to associated component...
Definition: RscComponentServiceImplBase.hpp:20
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:58
This is the namespace of the Application Component Framework.
Definition: ComponentBase.hpp:12
Namespace for basic functions of the framework
Definition: Console.hpp:14