SEDNL  .
Simple Event Driven Network Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | List of all members
SedNL::Event Class Reference

A user event. More...

#include <Event.hpp>

Public Member Functions

 Event (std::string name="")
 Construct an empty event. More...
 
 Event (std::string name, const Packet &packet)
 Construct an event from a packet. More...
 
const Packetget_packet () const noexcept
 Return a reference to the packet handled. More...
 
const std::string & get_name () const noexcept
 Return the event name. More...
 
ByteArray get_header () const
 Compute the binary header of an event. More...
 
ByteArray pack () const
 Compute a binary string representing the event. More...
 
void swap (Event &event) noexcept
 

Detailed Description

A user event.

The Event object is an event as send by TCPConnect::send or received by EventListener and given to your callbacks through EventConsumer.

Event are basically a "named Packet", where Packet contain the data you want to send / you just received.

//Create an event
Event event("hit_monster", make_packet(damage));
//Send it
connection.send(event);
//Extract data from an event (make a mutable copy)
std::string event_name = event.get_name();
Packet packet = event.get_packet();

Definition at line 36 of file Event.hpp.

Constructor & Destructor Documentation

SedNL::Event::Event ( std::string  name = "")
inline

Construct an empty event.

Parameters
[in]nameName of the event.

Definition at line 46 of file Event.ipp.

SedNL::Event::Event ( std::string  name,
const Packet packet 
)
inline

Construct an event from a packet.

Parameters
[in]nameName of the event.
[in]packetThe data attached.

Definition at line 50 of file Event.ipp.

Member Function Documentation

ByteArray SedNL::Event::get_header ( ) const

Compute the binary header of an event.

Low level function, used by the implementation.

You probably don't want to use it.

Returns
The binary header.
const std::string & SedNL::Event::get_name ( ) const
inlinenoexcept

Return the event name.

Notice it's actualy a const reference to the handler. Make a copy if you expect the event to die before the string.

Returns
A handler to the event name.

Definition at line 54 of file Event.ipp.

const Packet & SedNL::Event::get_packet ( ) const
inlinenoexcept

Return a reference to the packet handled.

Once this event is destructed, the packet will be destructed and the reference invalid.

Returns
The currently handled packet.

Definition at line 59 of file Event.ipp.

ByteArray SedNL::Event::pack ( ) const

Compute a binary string representing the event.

Low level function. Return the concatenated value of Event::get_header() and Packet::get_data().

Returns
The serialised event as a binary string.
void SedNL::Event::swap ( Event event)
inlinenoexcept

Swap two events.

Swap the content of event with the content of the current event.

Parameters
[in,out]eventto swap.

Definition at line 31 of file Event.ipp.


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