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 () 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

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 140 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 101 of file Event.cpp.

102 {
103  // Load data from the packet //
104  std::unique_ptr<std::string> tmpstr(new std::string());
105  if(!(packet >> *tmpstr)) {
106 
107  throw InvalidArgument("packet has invalid format");
108  }
109 
110  // Try to get the named variables //
111  std::unique_ptr<NamedVars> tmpvars(new NamedVars(packet));
112 
113  // Take the string away from the smart pointer //
114  TypeStr = tmpstr.release();
115 
116  // Take the variables away //
117  Variables = tmpvars.release();
118 }
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

◆ GenericEvent() [2/4]

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

Constructs a generic event.

Definition at line 77 of file Event.cpp.

78  :
79  TypeStr(new std::string(type)),
80  Variables(new NamedVars(copyvals))
81 {}
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

◆ GenericEvent() [3/4]

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

Constructs a generic event without any values.

Definition at line 89 of file Event.cpp.

89  :
90  TypeStr(new std::string(type)), Variables(new NamedVars())
91 {}
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

◆ GenericEvent() [4/4]

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

Constructor that takes the pointers as it's own.

Definition at line 83 of file Event.cpp.

84  :
85  TypeStr(takeownershipstr),
86  Variables(takeownershipvars)
87 {}
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

◆ ~GenericEvent()

DLLEXPORT Leviathan::GenericEvent::~GenericEvent ( )

Definition at line 93 of file Event.cpp.

94 {
95  // release memory //
98 }
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
#define SAFE_RELEASE(x)
Definition: Define.h:136
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185
#define SAFE_DELETE(x)
Definition: Define.h:151

Member Function Documentation

◆ AddDataToPacket()

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

Serializes this event to a packet.

Definition at line 120 of file Event.cpp.

121 {
122  // Add data to the packet //
123  packet << *TypeStr;
124 
125  Variables->AddDataToPacket(packet);
126 }
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Writes this NamedVars to a packet.
Definition: NamedVars.cpp:866
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

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

150 {
151  Variables->AddRef();
152  return Variables;
153 }
FORCE_INLINE void AddRef() const
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

◆ GetType()

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

Returns the name of the event.

See also
GetTypePtr

Definition at line 134 of file Event.cpp.

135 {
136  return *TypeStr;
137 }
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182

◆ GetTypePtr()

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

Returns the TypeStr ptr.

Definition at line 129 of file Event.cpp.

130 {
131  return TypeStr;
132 }
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182

◆ GetVariables()

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

Returns a direct pointer to this objects variables.

Definition at line 144 of file Event.cpp.

145 {
146  return Variables;
147 }
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

◆ GetVariablesConst()

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

Gets this event's variables.

Definition at line 139 of file Event.cpp.

140 {
141  return *Variables;
142 }
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185

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

◆ Variables

NamedVars* Leviathan::GenericEvent::Variables
protected

Pointer to this event's variables.

Definition at line 185 of file Event.h.


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