Modulo 5.0.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
modulo_core::communication::SubscriptionInterface Class Reference

Interface class to enable non-templated subscriptions with ROS subscriptions from derived SubscriptionHandler instances through dynamic down-casting. More...

#include <SubscriptionInterface.hpp>

Inheritance diagram for modulo_core::communication::SubscriptionInterface:
modulo_core::communication::SubscriptionHandler< MsgT >

Public Member Functions

 SubscriptionInterface (std::shared_ptr< MessagePairInterface > message_pair=nullptr)
 Constructor with the message pair.
 
 SubscriptionInterface (const SubscriptionInterface &subscription)=default
 Copy constructor from another SubscriptionInterface.
 
virtual ~SubscriptionInterface ()=default
 Default virtual destructor.
 
template<typename MsgT >
std::shared_ptr< SubscriptionHandler< MsgT > > get_handler (bool validate_pointer=true)
 Get a pointer to a derived SubscriptionHandler instance from a SubscriptionInterface pointer.
 
std::shared_ptr< MessagePairInterfaceget_message_pair () const
 Get the pointer to the message pair of the SubscriptionInterface.
 
void set_message_pair (const std::shared_ptr< MessagePairInterface > &message_pair)
 Set the pointer to the message pair of the SubscriptionInterface.
 

Protected Attributes

std::shared_ptr< MessagePairInterfacemessage_pair_
 The pointer to the stored MessagePair instance.
 

Detailed Description

Interface class to enable non-templated subscriptions with ROS subscriptions from derived SubscriptionHandler instances through dynamic down-casting.

Definition at line 19 of file SubscriptionInterface.hpp.

Constructor & Destructor Documentation

◆ SubscriptionInterface()

modulo_core::communication::SubscriptionInterface::SubscriptionInterface ( std::shared_ptr< MessagePairInterface message_pair = nullptr)
explicit

Constructor with the message pair.

Parameters
message_pairThe pointer to the message pair with the data that should be updated through the subscription

Definition at line 5 of file SubscriptionInterface.cpp.

Member Function Documentation

◆ get_handler()

template<typename MsgT >
std::shared_ptr< SubscriptionHandler< MsgT > > modulo_core::communication::SubscriptionInterface::get_handler ( bool  validate_pointer = true)
inline

Get a pointer to a derived SubscriptionHandler instance from a SubscriptionInterface pointer.

If a SubscriptionInterface pointer is used to address a derived SubscriptionHandler instance, this method will return a pointer to that derived instance through dynamic down-casting. The downcast will fail if the base SubscriptionInterface object has no reference count (if the object is not owned by any pointer), or if the derived object is not a correctly typed instance of a SubscriptionHandler. By default, an InvalidPointerCastException is thrown when the downcast fails. If this validation is disabled by setting the validate_pointer flag to false, it will not throw an exception and instead return a null pointer.

Template Parameters
PubTThe ROS publisher type
MsgTThe ROS message type
Exceptions
modulo_core::exceptions::InvalidPointerExceptionif the base SubscriptionInterface object has no reference count and validate_pointer is set to true
modulo_core::exceptions::InvalidPointerCastExceptionif the derived object from the dynamic down-casting is not a correctly typed instance of a SubscriptionHandler
Parameters
validate_pointerIf true, throw an exception when down-casting fails
Returns
A pointer to a derived SubscriptionHandler instance of the desired type, or a null pointer if down-casting failed and validate_pointer was set to false.

Definition at line 74 of file SubscriptionInterface.hpp.

◆ get_message_pair()

std::shared_ptr< MessagePairInterface > modulo_core::communication::SubscriptionInterface::get_message_pair ( ) const

Get the pointer to the message pair of the SubscriptionInterface.

Definition at line 8 of file SubscriptionInterface.cpp.

◆ set_message_pair()

void modulo_core::communication::SubscriptionInterface::set_message_pair ( const std::shared_ptr< MessagePairInterface > &  message_pair)

Set the pointer to the message pair of the SubscriptionInterface.

Exceptions
modulo_core::exceptions::NullPointerExceptionif the provided message pair pointer is null

Definition at line 12 of file SubscriptionInterface.cpp.

Member Data Documentation

◆ message_pair_

std::shared_ptr<MessagePairInterface> modulo_core::communication::SubscriptionInterface::message_pair_
protected

The pointer to the stored MessagePair instance.

Definition at line 70 of file SubscriptionInterface.hpp.


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