Drake
Drake C++ Documentation
Subscriber< Message > Class Template Referencefinal

Detailed Description

template<typename Message>
class drake::lcm::Subscriber< Message >

Subscribes to and stores a copy of the most recent message on a given channel, for some Message type.

All copies of a given Subscriber share the same underlying data. This class does NOT provide any mutex behavior for multi-threaded locking; it should only be used in cases where the governing DrakeLcmInterface::HandleSubscriptions is called from the same thread that owns all copies of this object.

#include <drake/lcm/drake_lcm_interface.h>

Public Member Functions

 Subscriber (DrakeLcmInterface *lcm, const std::string &channel, std::function< void()> on_error={})
 Subscribes to the (non-empty) channel on the given (non-null) lcm instance. More...
 
const Message & message () const
 Returns the most recently received message, or a value-initialized (zeros) message otherwise. More...
 
Message & message ()
 
int64_t count () const
 Returns the total number of received messages. More...
 
int64_tcount ()
 
void clear ()
 Clears all data (sets the message and count to all zeros). More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Subscriber (const Subscriber &)=default
 
Subscriberoperator= (const Subscriber &)=default
 
 Subscriber (Subscriber &&)=default
 
Subscriberoperator= (Subscriber &&)=default
 

Constructor & Destructor Documentation

◆ Subscriber() [1/3]

Subscriber ( const Subscriber< Message > &  )
default

◆ Subscriber() [2/3]

Subscriber ( Subscriber< Message > &&  )
default

◆ Subscriber() [3/3]

Subscriber ( DrakeLcmInterface lcm,
const std::string &  channel,
std::function< void()>  on_error = {} 
)

Subscribes to the (non-empty) channel on the given (non-null) lcm instance.

The lcm pointer is only used during construction; it is not retained by this object. When a undecodable message is received, on_error handler is invoked; when on_error is not provided, an exception will be thrown instead.

Member Function Documentation

◆ clear()

void clear ( )

Clears all data (sets the message and count to all zeros).

◆ count() [1/2]

int64_t count ( ) const

Returns the total number of received messages.

◆ count() [2/2]

int64_t& count ( )

◆ message() [1/2]

const Message& message ( ) const

Returns the most recently received message, or a value-initialized (zeros) message otherwise.

◆ message() [2/2]

Message& message ( )

◆ operator=() [1/2]

Subscriber& operator= ( const Subscriber< Message > &  )
default

◆ operator=() [2/2]

Subscriber& operator= ( Subscriber< Message > &&  )
default

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