PLCnext API Documentation 24.0.0.71
GenericPayload.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6
7#pragma once
8
10#include "Arp/System/Nm/IPayload.hpp"
11#include "Arp/System/Nm/Notification.hpp"
12
13
14namespace Arp { namespace System { namespace Nm
15{
16
17
19class ARP_CXX_SYMBOL_EXPORT GenericPayload : public IPayload
20{
21public: // typedefs
22 using ValueType = RawPayloadType::value_type;
24
25private: // typedefs
26 using FieldInfos = std::vector<FieldType>;
27
28public: // construction/destruction
32 explicit GenericPayload(const Notification& notification);
33
36
38 GenericPayload(PayloadTypeIdType id, const String& name, const RawPayloadType& payloadArg);
39
41 GenericPayload(PayloadTypeIdType id, const String& name, const Notification& notification);
42
43 ~GenericPayload() override = default;
44
45public: // operations
46 // Methods of IPayload
47 PayloadTypeIdType GetId() const override;
48 const String GetName() const override;
49 const RawPayloadType& GetAsRawPayloadType() const override;
50 const String ToString() const override;
51
52 RawPayloadType&& MoveOutRawPayload();
53
54
56 bool IsReadOnly() const;
57
59 size_t GetFieldCount() const;
60
63 const ValueType& GetFieldValue(size_t fieldIndex) const;
64
67 FieldType GetFieldType(size_t fieldIndex) const;
68
71
74 size_t AddField(FieldType type);
75 void SetFieldValue(size_t fieldIndex, const ValueType& value);
76
77private: // methods
78 void InitializeFields();
79 bool HasAssociatedNotification() const;
80 bool CanFieldBeAdded() const;
81 const String FormatValue(const String& formatString, const ValueType& value) const;
82
83private: // fields
85 String Name;
86 const Notification* NotificationPtr = nullptr;
87 RawPayloadType Payload;
88 FieldInfos Fields;
89 size_t FieldIndexFormatString = 0;
90};
91
92
93}}} // end of namespace Arp::System::Nm
Generic access to a IPayload
Definition: GenericPayload.hpp:20
size_t GetFieldCount() const
Returns the number of fields of the Payload
bool IsReadOnly() const
Returns true if this object is a view to a Notification
FieldType GetFieldType(size_t fieldIndex) const
Returns the FieldType for the given field
const String GetName() const override
Returns the PayloadTypeName
const RawPayloadType & GetAsRawPayloadType() const override
Returns a reference to the raw payload object
GenericPayload(const Notification &notification)
Read only access to a notification
PayloadTypeIdType GetId() const override
Returns the PayloadTypeId
const String ToString() const override
Get a human readable string representation
GenericPayload(PayloadTypeIdType id, const String &name, const Notification &notification)
Manually create a payload
size_t GetFieldIndexFormatString() const
Returnsd the field index of the format string
GenericPayload(PayloadTypeIdType id, const String &name)
Manually create a payload
GenericPayload(PayloadTypeIdType id, const String &name, const RawPayloadType &payloadArg)
Manually create a payload
const ValueType & GetFieldValue(size_t fieldIndex) const
Returns the raw value of a field
size_t AddField(FieldType type)
Adds a field with the given FieldType
Interface for Paylo objects
Definition: IPayload.hpp:19
Contains meta data and paylod of a Notification
Definition: Notification.hpp:22
@ System
System components used by the System, Device, Plc or Io domains.
std::vector< Arp::System::Rsc::Services::RscVariant< RawPayloadTypeLength > > RawPayloadType
type for the internally transferred payloads
Definition: NotificationManagerTypes.hpp:34
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
Root namespace for the PLCnext API