8#include "Arp/System/Core/TypeName.hxx"
9#include "Arp/System/Commons/Exceptions/ArgumentException.hpp"
10#include "Arp/System/Nm/GenericPayload.hpp"
11#include "Arp/System/Nm/IPayload.hpp"
12#include "Arp/System/Nm/Notification.hpp"
13#include "Arp/System/Nm/NotificationManager.hpp"
14#include "Arp/System/Nm/RscVariantHelpers.hpp"
15#include "Arp/Base/Rsc/Commons/RscTypeDeduction.hpp"
18namespace Arp {
namespace System {
namespace Nm
23class LongStringPayloadField;
42template<
typename PayloadType>
48 using ValueType = RawPayloadType::value_type;
49 using RscType = Arp::Base::Rsc::Commons::RscType;
50 using FieldType = RscType;
80 const
String ToString() const override;
85 bool IsReadOnly() const;
91 void SetFormatString(const
String& formatString);
95 static
size_t FieldIndexToFormatStringIndex(
size_t fieldIndex);
106 template < typename T, typename
std::enable_if < (!
std::is_same<T,
String>::value)&&
107 (!
std::is_enum<T>::value) >::type* =
nullptr >
119 template < typename T, typename std::enable_if < std::is_same<T, String>::value ||
120 std::is_enum<T>::value >::type* =
nullptr >
123 return this->payload.AddField(Arp::Base::Rsc::Commons::RscType::String);
130 template < typename T, typename std::enable_if < !std::is_enum<T>::value >::type* =
nullptr >
133 this->payload.SetFieldValue(fieldIndex, ValueType(value));
141 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* =
nullptr>
146 this->payload.SetFieldValue(fieldIndex,
static_cast<GenericPayload::ValueType
>(
Enum<T>(value).ToString()));
148 catch (
const std::out_of_range&)
152 static_cast<int>(value),
161 template < typename T, typename std::enable_if < !std::is_enum<T>::value >::type* =
nullptr >
164 const ValueType& value = this->payload.GetFieldValue(fieldIndex);
165 if (value.GetType() == RscType::None)
169 return rscvariant_cast<T>(value);
177 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* =
nullptr>
197 template<
typename PayloadType>
202template<
typename PayloadType>
204 : payload(GetId(), GetName())
206 this->payload.SetFieldValue(this->payload.
GetFieldIndexFormatString(),
static_cast<GenericPayload::ValueType
>(formatString));
210template<
typename PayloadType>
212 : payload(GetId(), GetName(), notification)
217template<
typename PayloadType>
219 : payload(GetId(), GetName(), payloadArg.GetAsRawPayloadType())
224template<
typename PayloadType>
228template<
typename PayloadType>
234 id = SpecializedPayloadHelper::GetINotificationManagerInfo().GetPayloadTypeId(
235 GetPayloadTypeName());
241template<
typename PayloadType>
244 return GetPayloadTypeId();
248template<
typename PayloadType>
255template<
typename PayloadType>
258 return GetPayloadTypeName();
262template<
typename PayloadType>
265 return this->payload.GetAsRawPayloadType();
269template<
typename PayloadType>
272 return this->payload.ToString();
275template<
typename PayloadType>
278 return this->payload.MoveOutRawPayload();
281template<
typename PayloadType>
284 return this->payload.IsReadOnly();
288template<
typename PayloadType>
291 this->payload.SetFieldValue(this->payload.GetFieldIndexFormatString(),
static_cast<GenericPayload::ValueType
>(formatString));
295template<
typename PayloadType>
298 return fieldIndex - 1;
302template<
typename PayloadType>
305 return this->payload.GetFieldCount();
static ArgumentException Create(const char *paramName, const T ¶mValue)
Creates an ArgumentException using a default message.
Definition: ArgumentException.hpp:92
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:21
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
static String Format(const String &format, const Args &... args)
Formats the format string using the .NET/Python syntax with the given variadic arguments.
Definition: String.inl:18
This (meta programming) class provides the C++ type-name of the as template argument passed type.
Definition: TypeName.hxx:20
This class is used to deduct RSC types automatically by compilation.
Definition: RscTypeDeduction.hpp:24
Generic access to a IPayload
Definition: GenericPayload.hpp:20
size_t GetFieldIndexFormatString() const
Returnsd the field index of the format string
Definition: GenericPayload.cpp:148
Interface for information about the Notification Manager
Definition: INotificationManagerInfo.hpp:22
Interface for Paylo objects
Definition: IPayload.hpp:19
Definition: LongStringPayloadField.hpp:19
Contains meta data and paylod of a Notification
Definition: Notification.hpp:20
Helper class to get access to INotificationManagerInfo
Definition: SpecializedPayload.hpp:194
Base class for custom Payload classes
Definition: SpecializedPayload.hpp:44
bool IsReadOnly() const
Returns true if this object is a view on a Payload
Definition: SpecializedPayload.hpp:282
size_t AddField()
Adds a payload field
Definition: SpecializedPayload.hpp:121
void SetFieldValue(size_t fieldIndex, const T &value)
Sets the value of a payload field
Definition: SpecializedPayload.hpp:131
PayloadTypeIdType GetId() const final
Returns the PayloadTypeId
Definition: SpecializedPayload.hpp:242
static const String GetPayloadTypeName()
Returns the PayloadType name
Definition: SpecializedPayload.hpp:249
const RawPayloadType & GetAsRawPayloadType() const final
Returns a reference to the raw payload object
Definition: SpecializedPayload.hpp:263
const String GetName() const final
Returns the PayloadTypeName
Definition: SpecializedPayload.hpp:256
size_t GetFieldCount() const
Gets the number of fields in the payload
Definition: SpecializedPayload.hpp:303
void SetFieldValue(size_t fieldIndex, T value)
Sets the value of a payload field
Definition: SpecializedPayload.hpp:142
void SetFormatString(const String &formatString)
summary>Retuns the index in the format string for a given payload field
Definition: SpecializedPayload.hpp:289
const T GetFieldValueAs(size_t fieldIndex) const
Gets a field value with the specified type
Definition: SpecializedPayload.hpp:162
const String ToString() const override
Get a human readable string representation
Definition: SpecializedPayload.hpp:270
SpecializedPayload(const Notification ¬ification)
Creates a view on a Notification object
Definition: SpecializedPayload.hpp:211
static PayloadTypeIdType GetPayloadTypeId()
Returns the PayloadTypeId
Definition: SpecializedPayload.hpp:229
static Enum Parse(const String &input)
Parses the given input string.
Definition: Enum.ipp:90
std::vector< Arp::Base::Rsc::Commons::RscVariant< RawPayloadTypeLength > > RawPayloadType
type for the internally transferred payloads
Definition: NotificationManagerTypes.hpp:32
Root namespace for the PLCnext API
Namespace of the C++ standard library