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 173 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 116 of file Event.cpp.

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

◆ GenericEvent() [2/4]

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

Constructs a generic event.

Definition at line 92 of file Event.cpp.

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

◆ GenericEvent() [3/4]

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

Constructs a generic event without any values.

Definition at line 104 of file Event.cpp.

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

◆ GenericEvent() [4/4]

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

Constructor that takes the pointers as it's own.

Definition at line 98 of file Event.cpp.

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

◆ ~GenericEvent()

DLLEXPORT Leviathan::GenericEvent::~GenericEvent ( )

Definition at line 108 of file Event.cpp.

109 {
110  // release memory //
113 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:215
#define SAFE_RELEASE(x)
Definition: Define.h:126
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:218
#define SAFE_DELETE(x)
Definition: Define.h:141

Member Function Documentation

◆ AddDataToPacket()

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

Serializes this event to a packet.

Definition at line 135 of file Event.cpp.

136 {
137  // Add data to the packet //
138  packet << *TypeStr;
139 
140  Variables->AddDataToPacket(packet);
141 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:215
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:218

◆ 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 164 of file Event.cpp.

165 {
166  Variables->AddRef();
167  return Variables;
168 }
FORCE_INLINE void AddRef()
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:218

◆ GetType()

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

Returns the name of the event.

See also
GetTypePtr

Definition at line 149 of file Event.cpp.

150 {
151  return *TypeStr;
152 }
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:215

◆ GetTypePtr()

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

Returns the TypeStr ptr.

Definition at line 144 of file Event.cpp.

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

◆ GetVariables()

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

Returns a direct pointer to this objects variables.

Definition at line 159 of file Event.cpp.

160 {
161  return Variables;
162 }
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:218

◆ GetVariablesConst()

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

Gets this event's variables.

Definition at line 154 of file Event.cpp.

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

◆ 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 215 of file Event.h.

◆ Variables

NamedVars* Leviathan::GenericEvent::Variables
protected

Pointer to this event's variables.

Definition at line 218 of file Event.h.


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