PLCnext API Documentation 24.0.0.71
TypeDefinition.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/Enumerator.hxx"
9#include "Arp/Plc/Commons/Meta/TypeInfo.hpp"
10#include "Arp/Plc/Commons/Meta/TypeSystem/FieldDefinition.hpp"
11#include <vector>
12#include <initializer_list>
13
14namespace Arp { namespace Plc { namespace Commons { namespace Meta { namespace TypeSystem
15{
16
17class TypeDomain;
18class FieldDefinition;
19
23{
24 friend class TypeDomain;
25 friend class FieldDefinition;
26
27public: // typedefs
28 using Fields = std::vector<FieldDefinition>;
29 using FieldList = std::initializer_list<FieldDefinition>;
30
31public: // nested typed
32 // TODO Make this private
34 class ChildTypeInfoEnumerator : public Enumerator<ChildTypeInfo>
35 {
36 public: // construction/destruction
38
39 public: // IEnumerator<TypeInfo> oeprations
40 bool MoveNext(void) override;
41
42 private: // fields
43 Fields::const_iterator begin;
44 Fields::const_iterator end;
45 };
46
47public: // construction/destruction
48 TypeDefinition(void) = default;
50 TypeDefinition(DataType dataType, const String& typeName, size_t size, size_t alignment, const FieldList& fields);
52 TypeDefinition(DataType dataType, const String& typeName, size_t size, size_t alignment, StandardAttribute standardAttributes, const FieldList& fields);
54 TypeDefinition(DataType dataType, const String& typeName, size_t size, size_t alignment, StandardAttribute standardAttributes, const CustomAttributes& customAttributes, const FieldList& fields);
56 TypeDefinition(const TypeDefinition& arg) = default;
60 TypeDefinition& operator=(const TypeDefinition& arg) = default;
64 ~TypeDefinition(void) = default;
65
66public: // setter/getter operations
68 TypeInfo& GetTypeInfo(void);
70 const TypeInfo& GetTypeInfo(void)const;
72 Fields& GetFields(void);
74 const Fields& GetFields(void)const;
75
76public: // operations
79
85 void ReserveFields(size_t numFields);
86
91
92private: // methods
93 FieldDefinition* GetField(const String& name);
94 void ResolveType(const String& libraryNamespace);
95
96private: // fields
97 String typeName;
98 TypeInfo typeInfo;
99 Fields fields;
100};
101
103// inline methods of class TypeDefinition
105{
106 return this->typeInfo;
107}
108
109inline const TypeInfo& TypeDefinition::GetTypeInfo()const
110{
111 return this->typeInfo;
112}
113
114inline TypeDefinition::Fields& TypeDefinition::GetFields()
115{
116 return this->fields;
117}
118
119inline const TypeDefinition::Fields& TypeDefinition::GetFields()const
120{
121 return this->fields;
122}
123
125{
126 return std::make_shared<ChildTypeInfoEnumerator>(*this);
127}
128
129
130}}}}} // end of namespace Arp::Plc::Commons::Meta::TypeSystem
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:22
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.
Definition: IEnumerator.hxx:48
Provides detailed type information within TypeBrowser interface.
Definition: TypeInfo.hpp:28
Defines meta infomration about one field in a type
Definition: FieldDefinition.hpp:19
IEnumerator over the children of the type
Definition: TypeDefinition.hpp:35
bool MoveNext(void) override
Moves this enumerator to the next position.
Defines the meta information of a type
Definition: TypeDefinition.hpp:23
void AddField(FieldDefinition &&field)
Add infomration about one field
IEnumerator< ChildTypeInfo >::Ptr CreateChildTypeInfoEnumerator(void)
Returns an IEnumerator over the type's fields as ChildTypeInfo
Definition: TypeDefinition.hpp:124
TypeInfo & GetTypeInfo(void)
Returns the TypeInfo of this type
Definition: TypeDefinition.hpp:104
TypeDefinition(DataType dataType, const String &typeName, size_t size, size_t alignment, StandardAttribute standardAttributes, const FieldList &fields)
Constructs an TypeDefinition instance.
TypeDefinition(TypeDefinition &&arg)=default
Move constructor.
Fields & GetFields(void)
Returns a reference to the type's fields
Definition: TypeDefinition.hpp:114
TypeDefinition & operator=(const TypeDefinition &arg)=default
Copy assignment operator.
TypeDefinition & operator=(TypeDefinition &&arg)=default
Move assignment operator.
TypeDefinition(const TypeDefinition &arg)=default
Copy constructor.
~TypeDefinition(void)=default
Destructs this instance and frees all resources.
TypeDefinition(DataType dataType, const String &typeName, size_t size, size_t alignment, const FieldList &fields)
Constructs an TypeDefinition instance.
const Fields & GetFields(void) const
Returns a reference to the type's fields
void ReserveFields(size_t numFields)
Allocate memory for fields
const TypeInfo & GetTypeInfo(void) const
Returns the TypeInfo of this type
TypeDefinition(DataType dataType, const String &typeName, size_t size, size_t alignment, StandardAttribute standardAttributes, const CustomAttributes &customAttributes, const FieldList &fields)
Constructs an TypeDefinition instance.
Container for the type information of a library
Definition: TypeDomain.hpp:26
std::vector< CustomAttribute > CustomAttributes
List of type attributes TypeAttribute.
Definition: CustomAttributes.hpp:15
StandardAttribute
Standard attributes to types
Definition: StandardAttribute.hpp:18
DataType
Definition: DataType.hpp:15
Root namespace for the PLCnext API