PLCnext API Documentation 23.6.0.37
StructNavigator.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/IEnumerator.hxx"
9#include "Arp/Plc/Commons/Meta/DataInfo.hpp"
10#include "Arp/Plc/Commons/Meta/ITypeNavigator.hpp"
11
12//TODO(OR): move to Arp/Plc/Commons/Internal/Meta
13
14namespace Arp { namespace Plc { namespace Commons { namespace Meta
15{
16
19{
20public: // usings
22 using Ptr = std::shared_ptr<StructNavigator>;
23
24public: // Nested types
25
26 // TODO Make this private
28 class Enumerator : public IEnumerator<const DataInfo&>
29 {
30 public: // construction
31 Enumerator(std::vector<DataInfo>& fieldInfos, std::vector<size_t>& offsets, const byte* startAddress);
32
33 public: // overridden operations
34 bool MoveNext(void)override;
35 const DataInfo& GetCurrent(void)override;
36 size_t GetCurrentOffset()const;
37
38 private: // fields
39 std::vector<size_t>& offsets;
40 std::vector<DataInfo>& fieldInfos;
41 const byte* startAddress;
42 size_t index = 0;
43 };
44
45public: // construction/destruction
50 StructNavigator(const TypeIdentifier& typeId, ITypeNavigator& typeNavigator, bool isChanging);
52 StructNavigator(const StructNavigator& arg) = default;
60 ~StructNavigator(void) = default;
61
62public: // setter/getter operations
63
64public: // operations
68 Enumerator GetEnumerator(const byte* address);
69
73 Enumerator GetEnumerator(const DataInfo& dataInfo);
74
78 size_t GetOffset(const String& fieldName);
79
80private: // methods
81
82private: // fields
83 const TypeIdentifier& typeIdentifier;
84 ITypeNavigator& typeNavigator;
85 std::vector<DataInfo> fieldInfos;
86 std::vector<size_t> offsets;
87 bool isChanging = false;
88};
89
91// inline methods of class StructNavigator
92
94{
95 return StructNavigator::Enumerator(this->fieldInfos, this->offsets, address);
96}
97
99{
100 return this->GetEnumerator(dataInfo.GetDataTag().GetDataAddress());
101}
102
104// inline methods of class StructNavigator::Enumerator
105inline size_t StructNavigator::Enumerator::GetCurrentOffset(void)const
106{
107 if (this->index < offsets.size())
108 {
109 return offsets[this->index];
110 }
111 return 0;
112}
113
114}}}} // end of namespace Arp::Plc::Commons::Meta
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.
Definition: IEnumerator.hxx:48
Provides detailed informations for the respective data object.
Definition: DataInfo.hpp:32
DataTag & GetDataTag(void)
Gets the DataTag .
Definition: DataInfo.hpp:183
const byte * GetDataAddress(void) const
For internal use only.
Definition: DataTag.hpp:203
Provide type information
Definition: ITypeNavigator.hpp:19
IEnumerator of DataInfos of a struct
Definition: StructNavigator.hpp:29
const DataInfo & GetCurrent(void) override
Gets the element at the current position.
bool MoveNext(void) override
Moves this enumerator to the next position.
Navigates the children of a struct
Definition: StructNavigator.hpp:19
StructNavigator & operator=(StructNavigator &&arg)=default
Move assignment operator.
StructNavigator(const TypeIdentifier &typeId, ITypeNavigator &typeNavigator, bool isChanging)
Constructs an StructNavigator instance.
Enumerator GetEnumerator(const byte *address)
Gets an IEnumerator based on an address
Definition: StructNavigator.hpp:93
std::shared_ptr< StructNavigator > Ptr
std::shared_ptr to StructNavigator
Definition: StructNavigator.hpp:22
StructNavigator(const StructNavigator &arg)=default
Copy constructor.
~StructNavigator(void)=default
Destructs this instance and frees all resources.
StructNavigator & operator=(const StructNavigator &arg)=default
Copy assignment operator.
size_t GetOffset(const String &fieldName)
Gets the offset of a field in the struct
StructNavigator(StructNavigator &&arg)=default
Move constructor.
Identifies a type descriptions
Definition: TypeIdentifier.hpp:24
Root namespace for the PLCnext API