HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::UID::UID Class Reference

Wrapper around UID_T pointer's. More...

#include <uids.h>

+ Inheritance diagram for HF::UID::UID:
+ Collaboration diagram for HF::UID::UID:

Public Member Functions

 UID (UID_T *_uid, bool _owner=false)
 Constructor. More...
 
 UID (UID &&other)
 Move constructor. More...
 
 UID (const UID &other)
 Copy constructor. More...
 
uint8_t type () const
 Type of the UID. More...
 
uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (Common::ByteArray &array, uint16_t offset) 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)
 Read a message from a ByteArray. More...
 
UIDoperator= (const UID &other)
 Copy assignment operator. More...
 
UIDoperator= (UID &&other)
 Move assignment operator. More...
 
UIDoperator= (UID_T *_uid)
 Use the given pointer as the pointer of the underlining UID to wrap around of. More...
 
int compare (const UID &other) const
 Compare the current UID with the given UID. More...
 
int compare (const UID_T &other) const
 Compare the current UID with the given UID. More...
 
UID_T const * raw () const
 Get the underling wrapped UID_T pointer. More...
 
float changed (const UID &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::Common::Serializable
virtual ~Serializable ()
 Destructor.
 

Detailed Description

Wrapper around UID_T pointer's.

This class can either wrap an existing pointer (i.e. a pointer to an object it doesn't own) or wrap a pointer to an object that was created based on an existing object. In this case the clone object is owned by this class instance.

The destructor of this class will delete the object it owns.

Definition at line 531 of file uids.h.

Constructor & Destructor Documentation

◆ UID() [1/3]

HF::UID::UID::UID ( UID_T _uid,
bool  _owner = false 
)
inline

Constructor.

Parameters
[in]_uidpointer to the UID being wrapped.
[in]_ownertake ownership of the pointer being wrapped.

Definition at line 550 of file uids.h.

550  :
551  _raw(_uid), owner(_owner)
552  {
553  assert(_uid != nullptr);
554  }

◆ UID() [2/3]

HF::UID::UID::UID ( UID &&  other)
inline

Move constructor.

Parameters
[in]otherUID to move from.

Definition at line 561 of file uids.h.

561  : _raw(other._raw), owner(other.owner)
562  {
563  other.owner = false;
564  }

◆ UID() [3/3]

HF::UID::UID::UID ( const UID other)
inline

Copy constructor.

The underling UID_T is cloned and this object takes ownership of it.

Parameters
[in]otherUID to copy from.

Definition at line 573 of file uids.h.

573  : _raw(other._raw->clone()), owner(true)
574  {}

Member Function Documentation

◆ changed()

float HF::UID::UID::changed ( const UID other) const
inline

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.

Definition at line 710 of file uids.h.

References UNUSED.

711  {
712  UNUSED(other);
713  return 0.0;
714  }
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.

◆ compare() [1/2]

int HF::UID::UID::compare ( const UID other) const
inline

Compare the current UID with the given UID.

This function returns a value less that 0 if the current UID object order is lower that the given UID, 0 if the UIDs represent the same entity and a value greater that 0 if current UID object is above the given UID.

Parameters
[in]othera pointer to a UID object to compare to.
Return values
<0the current UID is lower that the given UID.
0the current UID is the same as given UID.
>0the current UID is greater that the given UID.

Definition at line 688 of file uids.h.

References HF::UID::UID_T::compare().

689  {
690  return _raw->compare(*(other._raw));
691  }
virtual int compare(const UID_T &other) const
Compare the current UID with the given UID.
Definition: uids.h:88
+ Here is the call graph for this function:

◆ compare() [2/2]

int HF::UID::UID::compare ( const UID_T other) const
inline

Compare the current UID with the given UID.

This function returns a value less that 0 if the current UID object order is lower that the given UID, 0 if the UIDs represent the same entity and a value greater that 0 if current UID object is above the given UID.

Parameters
[in]othera pointer to a UID object to compare to.
Return values
<0the current UID is lower that the given UID.
0the current UID is the same as given UID.
>0the current UID is greater that the given UID.

Definition at line 694 of file uids.h.

References HF::UID::UID_T::compare().

695  {
696  return _raw->compare(other);
697  }
virtual int compare(const UID_T &other) const
Compare the current UID with the given UID.
Definition: uids.h:88
+ Here is the call graph for this function:

◆ operator=() [1/3]

UID& HF::UID::UID::operator= ( const UID other)
inline

Copy assignment operator.

Parameters
[in]otherUID to copy from.
Returns
a reference to this object.

Definition at line 627 of file uids.h.

References HF::Common::Cloneable< T >::clone().

628  {
629  // Ship if same object.
630  if (this == &other)
631  {
632  return *this;
633  }
634 
635  // Delete current wrapped object if owner.
636  if (this->owner)
637  {
638  delete this->_raw;
639  }
640 
641  // Clone wrapped UID_T and take ownership of the clone.
642  this->_raw = other._raw->clone();
643  this->owner = true;
644 
645  return *this;
646  }
virtual T * clone() const =0
Create a clone object of the object where this method is being called.
+ Here is the call graph for this function:

◆ operator=() [2/3]

UID& HF::UID::UID::operator= ( UID &&  other)
inline

Move assignment operator.

Parameters
[in]otherUID to move from.
Returns
a reference to this object.

Definition at line 655 of file uids.h.

656  {
657  std::swap(this->_raw, other._raw);
658  std::swap(this->owner, other.owner);
659 
660  return *this;
661  }

◆ operator=() [3/3]

UID& HF::UID::UID::operator= ( UID_T _uid)
inline

Use the given pointer as the pointer of the underlining UID to wrap around of.

Warning
the class takes ownership of the pointer and will delete the associated object when it is destructed.
Parameters
_uidpointer to the UID_T object instance to manage.
Returns
reference to self.

Definition at line 674 of file uids.h.

675  {
676  if (owner)
677  {
678  delete this->_raw;
679  }
680 
681  _raw = _uid;
682  owner = true;
683 
684  return *this;
685  }

◆ pack()

uint16_t HF::UID::UID::pack ( Common::ByteArray array,
uint16_t  offset 
) 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 609 of file uids.h.

References HF::UID::UID_T::pack().

Referenced by hello_msg_t::pack().

610  {
611  return _raw->pack(array, offset);
612  }
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.
Definition: uids.h:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raw()

UID_T const* HF::UID::UID::raw ( ) const
inline

Get the underling wrapped UID_T pointer.

Returns
the underling wrapped UID_T pointer.

Definition at line 704 of file uids.h.

705  {
706  return _raw;
707  }

◆ size()

uint16_t HF::UID::UID::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 604 of file uids.h.

References HF::UID::UID_T::size().

Referenced by hello_msg_t::size().

605  {
606  return _raw->size();
607  }
uint16_t size() const
Number bytes needed to serialize the message.
Definition: uids.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ type()

uint8_t HF::UID::UID::type ( ) const
inline

Type of the UID.

See also
HF::UID::Type.
Returns
type of the UID.

Definition at line 589 of file uids.h.

References HF::UID::UID_T::type().

590  {
591  return _raw->type();
592  }
virtual uint8_t type() const =0
Type of the UID.
+ Here is the call graph for this function:

◆ unpack()

uint16_t HF::UID::UID::unpack ( const Common::ByteArray array,
uint16_t  offset 
)
virtual

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.

Referenced by hello_msg_t::unpack().

+ Here is the caller graph for this function:

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