PLCnext API Documentation  22.9.0.33
GenericPayload.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 
7 #pragma once
8 
9 #include "Arp/System/Nm/IPayload.hpp"
10 #include "Arp/System/Nm/Notification.hpp"
11 
12 
13 namespace Arp { namespace System { namespace Nm
14 {
15 
16 
18 class GenericPayload : public IPayload
19 {
20 public: // typedefs
21  using ValueType = RawPayloadType::value_type;
23 
24 private: // typedefs
25  using FieldInfos = std::vector<FieldType>;
26 
27 public: // construction/destruction
31  explicit GenericPayload(const Notification& notification);
32 
35 
37  GenericPayload(PayloadTypeIdType id, const String& name, const RawPayloadType& payloadArg);
38 
40  GenericPayload(PayloadTypeIdType id, const String& name, const Notification& notification);
41 
42  ~GenericPayload() override = default;
43 
44 public: // operations
45  // Methods of IPayload
46  PayloadTypeIdType GetId() const override;
47  const String GetName() const override;
48  const RawPayloadType& GetAsRawPayloadType() const override;
49  const String ToString() const override;
50 
51  RawPayloadType&& MoveOutRawPayload();
52 
53 
55  bool IsReadOnly() const;
56 
58  size_t GetFieldCount() const;
59 
62  const ValueType& GetFieldValue(size_t fieldIndex) const;
63 
66  FieldType GetFieldType(size_t fieldIndex) const;
67 
69  size_t GetFieldIndexFormatString() const;
70 
73  size_t AddField(FieldType type);
74  void SetFieldValue(size_t fieldIndex, const ValueType& value);
75 
76 private: // methods
77  void InitializeFields();
78  bool HasAssociatedNotification() const;
79  bool CanFieldBeAdded() const;
80  const String FormatValue(const String& formatString, const ValueType& value) const;
81 
82 private: // fields
84  String Name;
85  const Notification* NotificationPtr = nullptr;
86  RawPayloadType Payload;
87  FieldInfos Fields;
88  size_t FieldIndexFormatString = 0;
89 };
90 
91 
92 }}} // end of namespace Arp::System::Nm
Generic access to a IPayload
Definition: GenericPayload.hpp:19
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 ValueType & GetFieldValue(size_t fieldIndex) const
Returns the raw value of a 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
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
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType....
Definition: RscType.hpp:37
Root namespace for the PLCnext API