PLCnext API Documentation  22.9.0.33
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
Arp::System::Nm::SpecializedPayload< PayloadType > Class Template Referenceabstract

Base class for custom Payload classes More...

#include <SpecializedPayload.hpp>

Inheritance diagram for Arp::System::Nm::SpecializedPayload< PayloadType >:
Inheritance graph

Public Types

using ValueType = RawPayloadType::value_type
 
using FieldType = Arp::System::Rsc::Services::RscType
 

Public Member Functions

 SpecializedPayload (const Notification &notification)
 Creates a view on a Notification object More...
 
 SpecializedPayload (const GenericPayload &payloadArg)
 Creates a view on a GenericPayload object More...
 
PayloadTypeIdType GetId () const final
 Returns the PayloadTypeId More...
 
const String GetName () const final
 Returns the PayloadTypeName More...
 
const RawPayloadTypeGetAsRawPayloadType () const final
 Returns a reference to the raw payload object More...
 
const String ToString () const override
 Get a human readable string representation More...
 
RawPayloadType && MoveOutRawPayload ()
 
bool IsReadOnly () const
 Returns true if this object is a view on a Payload More...
 

Static Public Member Functions

static PayloadTypeIdType GetPayloadTypeId ()
 Returns the PayloadTypeId More...
 
static const String GetPayloadTypeName ()
 Returns the PayloadType name More...
 

Protected Member Functions

 SpecializedPayload (const String &formatString)
 Creates a SpecializedPayload with an format string More...
 
void SetFormatString (const String &formatString)
 
template<typename T , typename std::enable_if<(!std::is_same< T, String >::value)&&(!std::is_enum< T >::value) >::type * = nullptr>
size_t AddField ()
 Adds a payload field More...
 
template<typename T , typename std::enable_if< std::is_same< T, String >::value||std::is_enum< T >::value >::type * = nullptr>
size_t AddField ()
 Adds a payload field More...
 
template<typename T , typename std::enable_if< !std::is_enum< T >::value >::type * = nullptr>
void SetFieldValue (size_t fieldIndex, const T &value)
 Sets the value of a payload field More...
 
template<typename T , typename std::enable_if< std::is_enum< T >::value >::type * = nullptr>
void SetFieldValue (size_t fieldIndex, T value)
 Sets the value of a payload field More...
 
template<typename T , typename std::enable_if< !std::is_enum< T >::value >::type * = nullptr>
const T GetFieldValueAs (size_t fieldIndex) const
 Gets a field value with the specified type More...
 
template<typename T , typename std::enable_if< std::is_enum< T >::value >::type * = nullptr>
const T GetFieldValueAs (size_t fieldIndex) const
 Gets a field value with the specified type More...
 
size_t GetFieldCount () const
 Gets the number of fields in the payload More...
 

Static Protected Member Functions

static size_t FieldIndexToFormatStringIndex (size_t fieldIndex)
 

Friends

class LongStringPayloadField
 

Detailed Description

template<typename PayloadType>
class Arp::System::Nm::SpecializedPayload< PayloadType >

Base class for custom Payload classes

Derive from this class to implement a custom notification payload.

Do not change the order of the defined payload fields. Otherwise the fields could be intepreted wrong resulting in exceptions.

Typically a derived class contains a member to store the field index for each payload field. The AddField method should be called using direct member initialization so these calls are generated by the compiler for all constructors. The constructors of this base class should be made avaibale by a using directive. (using SpecializedPaylod::SpecializedPayload;)

Implement a constructor of the derived class taking the payload field values as arguments and use SetFieldValue to store them.

Added Get methods to return the payload field with the correct type.

Constructor & Destructor Documentation

◆ SpecializedPayload() [1/3]

template<typename PayloadType >
Arp::System::Nm::SpecializedPayload< PayloadType >::SpecializedPayload ( const Notification notification)
explicit

Creates a view on a Notification object

The Notification is just referenced so it must stay alive to avoid dangling references.

◆ SpecializedPayload() [2/3]

template<typename PayloadType >
Arp::System::Nm::SpecializedPayload< PayloadType >::SpecializedPayload ( const GenericPayload payloadArg)
explicit

Creates a view on a GenericPayload object

The GenericPayload is just referenced so it must stay alive to avoid dangling references.

◆ SpecializedPayload() [3/3]

template<typename PayloadType >
Arp::System::Nm::SpecializedPayload< PayloadType >::SpecializedPayload ( const String formatString)
explicitprotected

Creates a SpecializedPayload with an format string

Parameters
formatStringFormatstring to generate a huiman readable representation

Member Function Documentation

◆ AddField() [1/2]

template<typename PayloadType >
template<typename T , typename std::enable_if<(!std::is_same< T, String >::value)&&(!std::is_enum< T >::value) >::type * = nullptr>
size_t Arp::System::Nm::SpecializedPayload< PayloadType >::AddField ( )
inlineprotected

Adds a payload field

Returns
field index of the added field

The type of the field is defined by the template parameter T.

◆ AddField() [2/2]

template<typename PayloadType >
template<typename T , typename std::enable_if< std::is_same< T, String >::value||std::is_enum< T >::value >::type * = nullptr>
size_t Arp::System::Nm::SpecializedPayload< PayloadType >::AddField ( )
inlineprotected

Adds a payload field

Returns
field index of the added field

The type of the field is defined by the template parameter T. Specialization for strings and enumerations. Enumerations are stored as strings to enable human readability.

◆ GetAsRawPayloadType()

template<typename PayloadType >
const RawPayloadType & Arp::System::Nm::SpecializedPayload< PayloadType >::GetAsRawPayloadType ( ) const
finalvirtual

Returns a reference to the raw payload object

The reference object must not be destroyed while the reference is used!

Implements Arp::System::Nm::IPayload.

◆ GetFieldCount()

template<typename PayloadType >
size_t Arp::System::Nm::SpecializedPayload< PayloadType >::GetFieldCount ( void  ) const
protected

Gets the number of fields in the payload

Returns
the number of fields in the payload

◆ GetFieldValueAs() [1/2]

template<typename PayloadType >
template<typename T , typename std::enable_if< !std::is_enum< T >::value >::type * = nullptr>
const T Arp::System::Nm::SpecializedPayload< PayloadType >::GetFieldValueAs ( size_t  fieldIndex) const
inlineprotected

Gets a field value with the specified type

Parameters
fieldIndexindex of the field to get
Returns
value of the field as type T

◆ GetFieldValueAs() [2/2]

template<typename PayloadType >
template<typename T , typename std::enable_if< std::is_enum< T >::value >::type * = nullptr>
const T Arp::System::Nm::SpecializedPayload< PayloadType >::GetFieldValueAs ( size_t  fieldIndex) const
inlineprotected

Gets a field value with the specified type

Parameters
fieldIndexindex of the field to get
Returns
value of the field as type T

Specialization for enumerations. Enumerations are stored as strings to enable human readability.

◆ GetId()

template<typename PayloadType >
PayloadTypeIdType Arp::System::Nm::SpecializedPayload< PayloadType >::GetId ( ) const
finalvirtual

Returns the PayloadTypeId

Implements Arp::System::Nm::IPayload.

◆ GetName()

template<typename PayloadType >
const String Arp::System::Nm::SpecializedPayload< PayloadType >::GetName ( ) const
finalvirtual

Returns the PayloadTypeName

Implements Arp::System::Nm::IPayload.

◆ GetPayloadTypeId()

template<typename PayloadType >
PayloadTypeIdType Arp::System::Nm::SpecializedPayload< PayloadType >::GetPayloadTypeId
static

Returns the PayloadTypeId

This funtion uses the NotificationManager internally to query the id.

◆ GetPayloadTypeName()

template<typename PayloadType >
const String Arp::System::Nm::SpecializedPayload< PayloadType >::GetPayloadTypeName
static

Returns the PayloadType name

The payload type name is generated from the class name

◆ IsReadOnly()

template<typename PayloadType >
bool Arp::System::Nm::SpecializedPayload< PayloadType >::IsReadOnly

Returns true if this object is a view on a Payload

◆ SetFieldValue() [1/2]

template<typename PayloadType >
template<typename T , typename std::enable_if< !std::is_enum< T >::value >::type * = nullptr>
void Arp::System::Nm::SpecializedPayload< PayloadType >::SetFieldValue ( size_t  fieldIndex,
const T &  value 
)
inlineprotected

Sets the value of a payload field

Parameters
fieldIndexindex of the field to set
valuenew value

◆ SetFieldValue() [2/2]

template<typename PayloadType >
template<typename T , typename std::enable_if< std::is_enum< T >::value >::type * = nullptr>
void Arp::System::Nm::SpecializedPayload< PayloadType >::SetFieldValue ( size_t  fieldIndex,
value 
)
inlineprotected

Sets the value of a payload field

Parameters
fieldIndexindex of the field to set
valuenew value

Specialization for enumerations. Enumerations are stored as strings to enable human readability.

◆ SetFormatString()

template<typename PayloadType >
void Arp::System::Nm::SpecializedPayload< PayloadType >::SetFormatString ( const String formatString)
protected

< summary>Sets the formatString This function should only be used, if the FormatString cannot be determined as a constructor parameter. summary>Retuns the index in the format string for a given payload field

◆ ToString()

template<typename PayloadType >
const String Arp::System::Nm::SpecializedPayload< PayloadType >::ToString ( ) const
overridevirtual

Get a human readable string representation

Implements Arp::System::Nm::IPayload.


The documentation for this class was generated from the following file: