HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Attributes::Attribute< T, _Owner, typename > Struct Template Reference

Helper template class to declare an attribute with the given T type. More...

#include <attributes.h>

+ Inheritance diagram for HF::Attributes::Attribute< T, _Owner, typename >:
+ Collaboration diagram for HF::Attributes::Attribute< T, _Owner, typename >:

Public Member Functions

 Attribute (const uint16_t interface, const uint8_t uid, const HF::Interface *__owner, T data, bool writable=false)
 Attribute template constructor. More...
 
 Attribute (const uint16_t interface, const uint8_t uid, bool writable=false)
 Attribute template constructor. More...
 
 Attribute (const uint16_t interface, const uint8_t uid, T data, bool writable=false)
 Attribute template constructor. More...
 
HF::Interface const * owner () const
 Pointer to the interface that owns this attribute. More...
 
uint16_t size (bool with_uid) const
 Number bytes needed to serialize the message. More...
 
uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (Common::ByteArray &array, uint16_t offset, bool with_uid) const
 Write the object on to a ByteArray so it can be sent over the network. More...
 
uint16_t pack (Common::ByteArray &array, uint16_t offset=0) const
 Write the object on to a ByteArray so it can be sent over the network. More...
 
uint16_t unpack (const Common::ByteArray &array, uint16_t offset, bool with_uid)
 Read a message from a ByteArray. More...
 
uint16_t unpack (const Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 
IAttributeclone () const
 Create a clone object of the object where this method is being called. More...
 
int compare (const IAttribute &other) const
 Compare this attribute with the given attribute in other. More...
 
float changed (const IAttribute &other) const
 This method is used to get the percentage of change that the attribute has in relation to the value present in other. More...
 
- Public Member Functions inherited from HF::Attributes::AbstractAttribute
uint8_t uid () const
 Attribute's UID. More...
 
bool isWritable () const
 Indicate if the attribute is writable. More...
 
uint16_t interface () const
 Return the UID of the interface the attribute belongs to. More...
 
- Public Member Functions inherited from HF::Common::Serializable
virtual ~Serializable ()
 Destructor.
 

Additional Inherited Members

- Protected Attributes inherited from HF::Attributes::AbstractAttribute
const uint16_t _itf_uid
 Interface this attribute belongs to. More...
 
const uint8_t _uid
 Attribute unique identifier. More...
 
const bool _writable
 Attribute access mode. More...
 

Detailed Description

template<typename T, typename _Owner = void, typename = void>
struct HF::Attributes::Attribute< T, _Owner, typename >

Helper template class to declare an attribute with the given T type.

Template Parameters
Tunderling data type for the attribute.
_Ownerunderling data type for the attribute's owner.

Definition at line 349 of file attributes.h.

Constructor & Destructor Documentation

◆ Attribute() [1/3]

template<typename T, typename _Owner = void, typename = void>
HF::Attributes::Attribute< T, _Owner, typename >::Attribute ( const uint16_t  interface,
const uint8_t  uid,
const HF::Interface __owner,
data,
bool  writable = false 
)
inline

Attribute template constructor.

Parameters
[in]interfaceattribute's interface UID.
[in]uidattribute's UID.
[in]dataattribute's value.
[in]__ownerpointer to attribute's interface owner object.
[in]writableattribute's writable information.

Definition at line 360 of file attributes.h.

361  :
362  AbstractAttribute(interface, uid, writable), helper(data), _owner(__owner)
363  {}
uint16_t interface() const
Return the UID of the interface the attribute belongs to.
Definition: attributes.h:294
uint8_t uid() const
Attribute&#39;s UID.
Definition: attributes.h:284

◆ Attribute() [2/3]

template<typename T, typename _Owner = void, typename = void>
HF::Attributes::Attribute< T, _Owner, typename >::Attribute ( const uint16_t  interface,
const uint8_t  uid,
bool  writable = false 
)
inline

Attribute template constructor.

Parameters
[in]interfaceattribute's interface UID.
[in]uidattribute's UID.
[in]writableattribute's writable information.

Definition at line 372 of file attributes.h.

372  :
373  AbstractAttribute(interface, uid, writable), _owner(nullptr)
374  {}
uint16_t interface() const
Return the UID of the interface the attribute belongs to.
Definition: attributes.h:294
uint8_t uid() const
Attribute&#39;s UID.
Definition: attributes.h:284

◆ Attribute() [3/3]

template<typename T, typename _Owner = void, typename = void>
HF::Attributes::Attribute< T, _Owner, typename >::Attribute ( const uint16_t  interface,
const uint8_t  uid,
data,
bool  writable = false 
)
inline

Attribute template constructor.

Parameters
[in]interfaceattribute's interface UID.
[in]uidattribute's UID.
[in]dataattribute's value.
[in]writableattribute's writable information.

Definition at line 384 of file attributes.h.

384  :
385  AbstractAttribute(interface, uid, writable), helper(data), _owner(nullptr)
386  {}
uint16_t interface() const
Return the UID of the interface the attribute belongs to.
Definition: attributes.h:294
uint8_t uid() const
Attribute&#39;s UID.
Definition: attributes.h:284

Member Function Documentation

◆ changed()

template<typename T, typename _Owner = void, typename = void>
float HF::Attributes::Attribute< T, _Owner, typename >::changed ( const IAttribute< T, _Owner, typename > &  other) const
inlinevirtual

This method is used to get the percentage of change that the attribute has in relation to the value present in other.

Parameters
[in]otherattribute holding a previous value.
Returns
float indicating the percentage of change.

Implements HF::Attributes::IAttribute.

Definition at line 496 of file attributes.h.

497  {
498  int res = AbstractAttribute::compare(other);
499 
500  if (res == 0)
501  {
502  Attribute<T> *temp = (Attribute<T> *) & other;
503  return helper.changed(temp->helper);
504  }
505 
506  return 0.0;
507  }
int compare(const IAttribute &other) const
Compare this attribute with the given attribute in other.
Definition: attributes.h:329

◆ clone()

template<typename T, typename _Owner = void, typename = void>
IAttribute* HF::Attributes::Attribute< T, _Owner, typename >::clone ( ) const
inlinevirtual

Create a clone object of the object where this method is being called.

Returns
a new object that is a clone of this object.

Implements HF::Common::Cloneable< IAttribute >.

Definition at line 477 of file attributes.h.

478  {
479  return new HF::Attributes::Attribute<T>(this->_itf_uid, this->_uid, this->_owner,
480  this->helper.data, this->_writable);
481  }
const bool _writable
Attribute access mode.
Definition: attributes.h:276
T data
Data type instance wrapped.
const uint8_t _uid
Attribute unique identifier.
Definition: attributes.h:275
const uint16_t _itf_uid
Interface this attribute belongs to.
Definition: attributes.h:274
Helper template class to declare an attribute with the given T type.
Definition: attributes.h:349

◆ compare()

template<typename T, typename _Owner = void, typename = void>
int HF::Attributes::Attribute< T, _Owner, typename >::compare ( const IAttribute< T, _Owner, typename > &  other) const
inlinevirtual

Compare this attribute with the given attribute in other.

This method should return < 0 if this attribute is less that, 0 if it is equal and > 0 if greater that the other attribute.

Parameters
[in]otherattribute to compare to.
Return values
<0if attribute less than other;
0if attribute equal to other;
>0if attribute greater than other.

Reimplemented from HF::Attributes::AbstractAttribute.

Definition at line 483 of file attributes.h.

484  {
485  int res = AbstractAttribute::compare(other);
486 
487  if (res == 0)
488  {
489  Attribute<T> *temp = (Attribute<T> *) & other;
490  res = helper.compare(temp->helper);
491  }
492 
493  return res;
494  }
int compare(const IAttribute &other) const
Compare this attribute with the given attribute in other.
Definition: attributes.h:329

◆ owner()

template<typename T, typename _Owner = void, typename = void>
HF::Interface const* HF::Attributes::Attribute< T, _Owner, typename >::owner ( ) const
inlinevirtual

Pointer to the interface that owns this attribute.

This can return nullptr if the attribute was created for a remote interface.

Returns
pointer to the interface that owns this attribute, or nullptr if owner is a remote object.

Implements HF::Attributes::IAttribute.

Definition at line 414 of file attributes.h.

415  {
416  return _owner;
417  }

◆ pack() [1/2]

template<typename T, typename _Owner = void, typename = void>
uint16_t HF::Attributes::Attribute< T, _Owner, typename >::pack ( Common::ByteArray array,
uint16_t  offset,
bool  with_uid 
) const
inlinevirtual

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
[in]with_uidinclude uid field in the serialization.
Returns
the number of bytes written.

Implements HF::Attributes::IAttribute.

Definition at line 429 of file attributes.h.

430  {
431  HF_SERIALIZABLE_CHECK(array, offset, size(with_uid));
432 
433  uint16_t start = offset;
434 
435  if (with_uid)
436  {
437  offset += array.write(offset, uid());
438  }
439 
440  offset += helper.pack(array, offset);
441 
442  return offset - start;
443  }
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
uint16_t pack(ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
uint8_t uid() const
Attribute&#39;s UID.
Definition: attributes.h:284
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:424

◆ pack() [2/2]

template<typename T, typename _Owner = void, typename = void>
uint16_t HF::Attributes::Attribute< T, _Owner, typename >::pack ( Common::ByteArray array,
uint16_t  offset = 0 
) const
inlinevirtual

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Serializable obj;
ByteArray payload(obj.size());
obj.pack(payload);
Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
Returns
the number of bytes written.

Implements HF::Common::Serializable.

Definition at line 445 of file attributes.h.

446  {
447  return helper.pack(array, offset);
448  }
uint16_t pack(ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.

◆ size() [1/2]

template<typename T, typename _Owner = void, typename = void>
uint16_t HF::Attributes::Attribute< T, _Owner, typename >::size ( bool  with_uid) const
inlinevirtual

Number bytes needed to serialize the message.

Parameters
[in]with_uidinclude uid size in the calculation.
Returns
number of bytes the message requires to be serialized.

Implements HF::Attributes::IAttribute.

Definition at line 419 of file attributes.h.

420  {
421  return size() + (with_uid ? sizeof(uint8_t) : 0);
422  }
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:424

◆ size() [2/2]

template<typename T, typename _Owner = void, typename = void>
uint16_t HF::Attributes::Attribute< T, _Owner, typename >::size ( ) const
inlinevirtual

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Implements HF::Common::Serializable.

Definition at line 424 of file attributes.h.

Referenced by HF::Attributes::Attribute< bool >::pack(), HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::pack(), HF::Attributes::Attribute< bool >::size(), HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::size(), HF::Attributes::Attribute< bool >::unpack(), and HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::unpack().

425  {
426  return helper.size();
427  }
uint16_t size() const
Number bytes needed to serialize the message.
+ Here is the caller graph for this function:

◆ unpack() [1/2]

template<typename T, typename _Owner = void, typename = void>
uint16_t HF::Attributes::Attribute< T, _Owner, typename >::unpack ( const Common::ByteArray array,
uint16_t  offset,
bool  with_uid 
)
inlinevirtual

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
[in]with_uidtrue if the uid field was included in the serialization, false otherwise.
Returns
the number of bytes read.

Implements HF::Attributes::IAttribute.

Definition at line 450 of file attributes.h.

451  {
452  HF_SERIALIZABLE_CHECK(array, offset, size(with_uid));
453 
454  uint16_t start = offset;
455 
456  if (with_uid)
457  {
458  uint8_t temp;
459  offset += array.read(offset, temp);
460 
461  if (temp != uid())
462  {
463  return 0;
464  }
465  }
466 
467  offset += helper.unpack(array, offset);
468 
469  return offset - start;
470  }
uint16_t unpack(const ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
uint8_t uid() const
Attribute&#39;s UID.
Definition: attributes.h:284
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:424

◆ unpack() [2/2]

template<typename T, typename _Owner = void, typename = void>
uint16_t HF::Attributes::Attribute< T, _Owner, typename >::unpack ( const Common::ByteArray array,
uint16_t  offset = 0 
)
inlinevirtual

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
Returns
the number of bytes read.

Implements HF::Common::Serializable.

Definition at line 472 of file attributes.h.

473  {
474  return helper.unpack(array, offset);
475  }
uint16_t unpack(const ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.

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