Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Event Class Reference

Class that represents a statically defined event. More...

#include <Event.h>

+ Inheritance diagram for Leviathan::Event:

Public Member Functions

DLLEXPORT Event (sf::Packet &packet)
 Loads this event from a packet. More...
 
DLLEXPORT Event (EVENT_TYPE type, BaseEventData *data)
 Creates a new event. More...
 
DLLEXPORT ~Event ()
 
DLLEXPORT EVENT_TYPE GetType () const
 Gets the Type of the event. More...
 
DLLEXPORT void AddDataToPacket (sf::Packet &packet) const
 Saves this event to a packet. More...
 
DLLEXPORT FloatEventDataGetFloatDataForEvent () const
 Gets the data if this is an event that has only one integer data member. More...
 
 REFERENCE_COUNTED_PTR_TYPE (Event)
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef () const
 
FORCE_INLINE void Release () const
 removes a reference and deletes the object if reference count reaches zero More...
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 
int32_t GetRefCount () const
 Returns the reference count. More...
 

Protected Attributes

EVENT_TYPE Type
 Events type. More...
 
BaseEventDataData
 Direct pointer to the data. More...
 

Additional Inherited Members

- Public Types inherited from Leviathan::ReferenceCounted
using basepointer = boost::intrusive_ptr< ReferenceCounted >
 
using refcountedpointer = boost::intrusive_ptr< ReferenceCounted >
 
- Static Public Member Functions inherited from Leviathan::ReferenceCounted
template<class ActualType >
static boost::intrusive_ptr< ActualType > WrapPtr (ActualType *ptr)
 Creates an intrusive_ptr from raw pointer. More...
 
template<class ActualType , class... Args>
static boost::intrusive_ptr< ActualType > MakeShared (Args &&... args)
 Constructs a new instance and wraps it. More...
 
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
 
virtual DLLEXPORT ~ReferenceCounted ()
 

Detailed Description

Class that represents a statically defined event.

Definition at line 106 of file Event.h.

Constructor & Destructor Documentation

◆ Event() [1/2]

DLLEXPORT Leviathan::Event::Event ( sf::Packet &  packet)

Loads this event from a packet.

Definition at line 43 of file Event.cpp.

44 {
45  // Get the type from the packet //
46  int tmptype;
47 
48  if(!(packet >> tmptype)) {
49 
50  throw InvalidArgument("packet has invalid format");
51  }
52 
53  // Set our type //
54  Type = static_cast<EVENT_TYPE>(tmptype);
55 
56  // Load based on type //
57  switch(Type) {
59  case EVENT_TYPE_TICK: {
60  Data = new FloatEventData(packet);
61  break;
62  }
63  default:
64  // No data required //
65  Data = NULL;
66  }
67 }
EVENT_TYPE Type
Events type.
Definition: Event.h:133
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:136
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:90

◆ Event() [2/2]

DLLEXPORT Leviathan::Event::Event ( EVENT_TYPE  type,
BaseEventData data 
)

Creates a new event.

Warning
Funky things can happen if the type doesn't match the type of data

Definition at line 8 of file Event.cpp.

8  :
9  Type(type), Data(data)
10 {
11  // Check that types that require values have values //
12  if(!Data) {
13  // Check that the event has data //
15 
16  throw InvalidArgument("Event that requires data, didn't get it");
17  }
18  }
19 }
EVENT_TYPE Type
Events type.
Definition: Event.h:133
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:136

◆ ~Event()

Event::~Event ( )

Definition at line 21 of file Event.cpp.

22 {
23  // Delete our data //
25 }
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:136
#define SAFE_DELETE(x)
Definition: Define.h:151

Member Function Documentation

◆ AddDataToPacket()

DLLEXPORT void Leviathan::Event::AddDataToPacket ( sf::Packet &  packet) const

Saves this event to a packet.

Definition at line 33 of file Event.cpp.

34 {
35  // Add the type first //
36  packet << (int)Type;
37 
38  // Add the data object //
39  if(Data)
40  Data->AddDataToPacket(packet);
41 }
virtual void AddDataToPacket(sf::Packet &packet)=0
Adds this to a packet for retrieving it later.
EVENT_TYPE Type
Events type.
Definition: Event.h:133
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:136

◆ GetFloatDataForEvent()

DLLEXPORT FloatEventData * Leviathan::Event::GetFloatDataForEvent ( ) const

Gets the data if this is an event that has only one integer data member.

Definition at line 70 of file Event.cpp.

71 {
73  return static_cast<FloatEventData*>(Data);
74  return NULL;
75 }
EVENT_TYPE Type
Events type.
Definition: Event.h:133
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:136

◆ GetType()

DLLEXPORT EVENT_TYPE Leviathan::Event::GetType ( ) const

Gets the Type of the event.

Definition at line 27 of file Event.cpp.

28 {
29  return Type;
30 }
EVENT_TYPE Type
Events type.
Definition: Event.h:133

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::Event::REFERENCE_COUNTED_PTR_TYPE ( Event  )

Member Data Documentation

◆ Data

BaseEventData* Leviathan::Event::Data
protected

Direct pointer to the data.

Definition at line 136 of file Event.h.

◆ Type

EVENT_TYPE Leviathan::Event::Type
protected

Events type.

Definition at line 133 of file Event.h.


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