Leviathan  0.8.0.0
Leviathan game engine
Leviathan::GenericEvent Class Reference

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

#include <Event.h>

+ Inheritance diagram for Leviathan::GenericEvent:

Public Member Functions

DLLEXPORT GenericEvent (sf::Packet &packet)
 Constructs this object from a packet. More...
 
DLLEXPORT GenericEvent (const std::string &type, const NamedVars &copyvals)
 Constructs a generic event. More...
 
DLLEXPORT GenericEvent (const std::string &type)
 Constructs a generic event without any values. More...
 
DLLEXPORT GenericEvent (std::string *takeownershipstr, NamedVars *takeownershipvars)
 Constructor that takes the pointers as it's own. More...
 
DLLEXPORT ~GenericEvent ()
 
DLLEXPORT void AddDataToPacket (sf::Packet &packet) const
 Serializes this event to a packet. More...
 
DLLEXPORT const NamedVars GetVariablesConst () const
 Gets this event's variables. More...
 
DLLEXPORT NamedVarsGetVariables ()
 Returns a direct pointer to this objects variables. More...
 
DLLEXPORT NamedVarsGetNamedVarsRefCounted ()
 Proxy for script to get Variables. More...
 
DLLEXPORT std::string * GetTypePtr ()
 Returns the TypeStr ptr. More...
 
DLLEXPORT std::string GetType () const
 Returns the name of the event. More...
 
 REFERENCE_COUNTED_PTR_TYPE (GenericEvent)
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 removes a reference and deletes the object if reference count reaches zero More...
 
int32_t GetRefCount () const
 Returns the reference count. More...
 

Protected Attributes

std::string * TypeStr
 String that defines this event's type. More...
 
NamedVarsVariables
 Pointer to this event's variables. 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 dynamically defined event.

Definition at line 141 of file Event.h.

Constructor & Destructor Documentation

◆ GenericEvent() [1/4]

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

Constructs this object from a packet.

Definition at line 113 of file Event.cpp.

114 {
115  // Load data from the packet //
116  unique_ptr<std::string> tmpstr(new std::string());
117  if(!(packet >> *tmpstr)) {
118 
119  throw InvalidArgument("packet has invalid format");
120  }
121 
122  // Try to get the named variables //
123  unique_ptr<NamedVars> tmpvars(new NamedVars(packet));
124 
125  // Take the string away from the smart pointer //
126  TypeStr = tmpstr.release();
127 
128  // Take the variables away //
129  Variables = tmpvars.release();
130 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ GenericEvent() [2/4]

DLLEXPORT Leviathan::GenericEvent::GenericEvent ( const std::string &  type,
const NamedVars copyvals 
)

Constructs a generic event.

Definition at line 90 of file Event.cpp.

91  :
92  TypeStr(new std::string(type)),
93  Variables(new NamedVars(copyvals))
94 {}
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ GenericEvent() [3/4]

DLLEXPORT Leviathan::GenericEvent::GenericEvent ( const std::string &  type)

Constructs a generic event without any values.

Definition at line 102 of file Event.cpp.

102  :
103  TypeStr(new std::string(type)), Variables(new NamedVars())
104 {}
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ GenericEvent() [4/4]

DLLEXPORT Leviathan::GenericEvent::GenericEvent ( std::string *  takeownershipstr,
NamedVars takeownershipvars 
)

Constructor that takes the pointers as it's own.

Definition at line 96 of file Event.cpp.

97  :
98  TypeStr(takeownershipstr),
99  Variables(takeownershipvars)
100 {}
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ ~GenericEvent()

DLLEXPORT Leviathan::GenericEvent::~GenericEvent ( )

Definition at line 106 of file Event.cpp.

107 {
108  // release memory //
111 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
#define SAFE_RELEASE(x)
Definition: Define.h:114
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182
#define SAFE_DELETE(x)
Definition: Define.h:116

Member Function Documentation

◆ AddDataToPacket()

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

Serializes this event to a packet.

Definition at line 132 of file Event.cpp.

133 {
134  // Add data to the packet //
135  packet << *TypeStr;
136 
137  Variables->AddDataToPacket(packet);
138 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Writes this NamedVars to a packet.
Definition: NamedVars.cpp:866
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ GetNamedVarsRefCounted()

DLLEXPORT NamedVars * Leviathan::GenericEvent::GetNamedVarsRefCounted ( )

Proxy for script to get Variables.

Warning
this function returns the pointer with reference count increased //

Definition at line 160 of file Event.cpp.

161 {
162  Variables->AddRef();
163  return Variables;
164 }
FORCE_INLINE void AddRef()
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ GetType()

DLLEXPORT std::string Leviathan::GenericEvent::GetType ( ) const

Returns the name of the event.

See also
GetTypePtr

Definition at line 145 of file Event.cpp.

146 {
147  return *TypeStr;
148 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179

◆ GetTypePtr()

DLLEXPORT std::string * Leviathan::GenericEvent::GetTypePtr ( )

Returns the TypeStr ptr.

Definition at line 140 of file Event.cpp.

141 {
142  return TypeStr;
143 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179

◆ GetVariables()

DLLEXPORT NamedVars * Leviathan::GenericEvent::GetVariables ( )

Returns a direct pointer to this objects variables.

Definition at line 155 of file Event.cpp.

156 {
157  return Variables;
158 }
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ GetVariablesConst()

DLLEXPORT const NamedVars Leviathan::GenericEvent::GetVariablesConst ( ) const

Gets this event's variables.

Definition at line 150 of file Event.cpp.

151 {
152  return *Variables;
153 }
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::GenericEvent::REFERENCE_COUNTED_PTR_TYPE ( GenericEvent  )

Member Data Documentation

◆ TypeStr

std::string* Leviathan::GenericEvent::TypeStr
protected

String that defines this event's type.

Definition at line 179 of file Event.h.

◆ Variables

NamedVars* Leviathan::GenericEvent::Variables
protected

Pointer to this event's variables.

Definition at line 182 of file Event.h.


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