PLCnext API Documentation 23.6.0.37
TypeIdentifierDeduction.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/CommonTypeName.hxx"
9#include "Arp/System/Core/TypeDeduction.hxx"
10#include "Arp/Plc/Commons/DataTypeEnum.hpp"
11#include "Arp/Plc/Commons/Meta/TypeIdentifier.hpp"
12#include "Arp/Plc/Commons/Meta/TypeSystem/DataTypeDeduction.hxx"
13#include <type_traits>
14namespace Arp { namespace Plc { namespace Commons { namespace Meta { namespace TypeSystem
15{
16
17using namespace Arp::Plc::Commons;
18
20{
21public: // construction/destruction
23 TypeIdentifierDeduction(const char* libraryNamespace);
33 ~TypeIdentifierDeduction(void) = default;
34
35public: // static operations
36 template<class T>
37 TypeIdentifier operator()(const T& value)const;
38
39private: // fields
40 const char* libraryNamespace;
41};
42
44// inline methods of class TypeIdentifierDeduction
45inline TypeIdentifierDeduction::TypeIdentifierDeduction(const char* libraryNamespace)
46 : libraryNamespace(libraryNamespace)
47{
48}
49
50template<class T>
51inline TypeIdentifier TypeIdentifierDeduction::operator()(const T& value)const
52{
53 DataTypeEnum dataType = static_cast<DataType>(DataTypeDeduction<T>());
54 if (!dataType.IsComplex(true))
55 {
57 }
58 if (dataType == DataType::Program)
59 {
60 return TypeIdentifier::Create(CommonTypeName<void>::GetFrom(value), this->libraryNamespace);
61 }
62 // else must deduce typeId
63 String typeName = CommonTypeName <
64 typename std::remove_all_extents <
65 typename std::remove_pointer <
66 typename remove_shared_ptr <
67 typename std::remove_const<T>::type >::type >::type >::type > ();
68
69 return TypeIdentifier::Create(typeName, this->libraryNamespace);
70}
71
72}}}}} // end of namespace Arp::Plc::Commons::Meta::TypeSystem
This (meta programming) class provides the typename according the CLS (common language specification)...
Definition: CommonTypeName.hxx:30
Definition: DataTypeEnum.hpp:16
bool IsComplex(bool useBaseType=true) const
Checks if this data type is complex.
Definition: DataTypeEnum.hpp:145
Identifies a type descriptions
Definition: TypeIdentifier.hpp:24
static TypeIdentifier Create(const String &commonTypeName, const char *libraryNamespace, void *typeTag=nullptr)
Creates a TypeIdentifier
static const TypeIdentifier Empty
Empty instance to enable retruning const&
Definition: TypeIdentifier.hpp:51
Definition: DataTypeDeduction.hxx:16
Definition: TypeIdentifierDeduction.hxx:20
TypeIdentifierDeduction & operator=(TypeIdentifierDeduction &&arg)=default
Move assignment operator.
TypeIdentifierDeduction(const TypeIdentifierDeduction &arg)=default
Copy constructor.
TypeIdentifierDeduction(const char *libraryNamespace)
Constructs an TypeIdentifierDeduction instance.
Definition: TypeIdentifierDeduction.hxx:45
~TypeIdentifierDeduction(void)=default
Destructs this instance and frees all resources.
TypeIdentifierDeduction(TypeIdentifierDeduction &&arg)=default
Move constructor.
TypeIdentifierDeduction & operator=(const TypeIdentifierDeduction &arg)=default
Copy assignment operator.
Namespace for classes shared between PLC components
Definition: PlcStateChangedPayload.hpp:15
DataType
Definition: DataType.hpp:15
@ Program
summary>Component
Root namespace for the PLCnext API
Gets the value type of a shared_ptr.
Definition: TypeDeduction.hxx:90