Leviathan  0.8.0.0
Leviathan game engine
Leviathan::DataBlock< DBlockT > Class Template Reference

Main DataBlock class. More...

#include <DataBlock.h>

+ Inheritance diagram for Leviathan::DataBlock< DBlockT >:

Public Member Functions

 DataBlock (const _U &forceempty)
 Creates an uninitialized block of type non. More...
 
 DataBlock (const DBlockT &val)
 
 DataBlock (DBlockT *val)
 
DLLEXPORT DataBlock (sf::Packet &packet)
 
DLLEXPORT void AddDataToPacket (sf::Packet &packet)
 
 DataBlock (const DataBlock &otherdeepcopy)
 
virtual ~DataBlock ()
 
DataBlockoperator= (const DataBlock &arg)
 
virtual DataBlockAllAllocateNewFromThis () const
 
bool operator== (const DataBlock< DBlockT > &other)
 
template<class ConvertT >
 operator ConvertT () const
 
template<class ConvertT >
 operator ConvertT * ()
 
template<class ConvertT >
bool IsConversionAllowedNonPtr () const
 
template<class ConvertT >
bool IsConversionAllowedPtr () const
 
- Public Member Functions inherited from Leviathan::DataBlockAll
virtual ~DataBlockAll ()
 
bool operator== (const DataBlockAll &other)
 

Static Public Member Functions

static DataBlockCopyConstructor (DataBlock *arg)
 

Public Attributes

DBlockT * Value
 
- Public Attributes inherited from Leviathan::DataBlockAll
short Type
 

Additional Inherited Members

- Protected Member Functions inherited from Leviathan::DataBlockAll
 DataBlockAll ()
 

Detailed Description

template<class DBlockT>
class Leviathan::DataBlock< DBlockT >

Main DataBlock class.

Todo:
Add move constructor and move assignment operators

Definition at line 37 of file DataBlock.h.

Constructor & Destructor Documentation

◆ DataBlock() [1/5]

template<class DBlockT>
Leviathan::DataBlock< DBlockT >::DataBlock ( const _U &  forceempty)
inlineexplicit

Creates an uninitialized block of type non.

Warning
Calling this will create an invalid block that cannot be casted or used

Definition at line 166 of file DataBlock.h.

166  : Value(NULL){
167 
169  }
#define DATABLOCK_TYPE_UNINITIALIZED
Definition: DataBlock.h:32

◆ DataBlock() [2/5]

template<class DBlockT>
Leviathan::DataBlock< DBlockT >::DataBlock ( const DBlockT &  val)
inline

Definition at line 171 of file DataBlock.h.

171  : Value(new DBlockT(val)){
172 
173  // use templates to get type //
175  }
static const short TVal
Definition: DataBlock.h:43

◆ DataBlock() [3/5]

template<class DBlockT>
Leviathan::DataBlock< DBlockT >::DataBlock ( DBlockT *  val)
inline

Definition at line 176 of file DataBlock.h.

176  : Value(val){
177 
178  // use templates to get type //
180  }
static const short TVal
Definition: DataBlock.h:43

◆ DataBlock() [4/5]

template<class DBlockT >
DLLEXPORT Leviathan::DataBlock< DBlockT >::DataBlock ( sf::Packet &  packet)

Definition at line 187 of file DataBlock.cpp.

188 {
189  // The default one cannot do anything, only the specialized functions can try to do
190  // something
191  throw Exception("this type doesn't support loading from a packet");
192 }
Base class for all exceptions thrown by Leviathan.
Definition: Exceptions.h:10

◆ DataBlock() [5/5]

template<class DBlockT>
Leviathan::DataBlock< DBlockT >::DataBlock ( const DataBlock< DBlockT > &  otherdeepcopy)
inline

Definition at line 189 of file DataBlock.h.

189  : Value(NULL){
190  // allocate new pointer from the other instance //
191  Value = new DBlockT(*otherdeepcopy.Value);
192 
193  // copy type //
194  Type = otherdeepcopy.Type;
195  }

◆ ~DataBlock()

template<class DBlockT>
virtual Leviathan::DataBlock< DBlockT >::~DataBlock ( )
inlinevirtual

Definition at line 198 of file DataBlock.h.

198  {
199  // erase memory //
201  }
#define SAFE_DELETE(x)
Definition: Define.h:153

Member Function Documentation

◆ AddDataToPacket()

template<class DBlockT >
DLLEXPORT void Leviathan::DataBlock< DBlockT >::AddDataToPacket ( sf::Packet &  packet)

Definition at line 180 of file DataBlock.cpp.

181 {
182  // The default one cannot do anything, only the specialized functions can try to do
183  // something
184  throw Exception("this type doesn't support saving to a packet");
185 }
Base class for all exceptions thrown by Leviathan.
Definition: Exceptions.h:10

◆ AllocateNewFromThis()

template<class DBlockT>
virtual DataBlockAll* Leviathan::DataBlock< DBlockT >::AllocateNewFromThis ( ) const
inlinevirtual

Implements Leviathan::DataBlockAll.

Definition at line 220 of file DataBlock.h.

220  {
221 
222  return static_cast<DataBlockAll*>((new DataBlock<DBlockT>(
223  const_cast<const DataBlock<DBlockT>&>(*this))));
224  }

◆ CopyConstructor()

template<class DBlockT>
static DataBlock* Leviathan::DataBlock< DBlockT >::CopyConstructor ( DataBlock< DBlockT > *  arg)
inlinestatic

Definition at line 228 of file DataBlock.h.

228  {
229 
230  std::unique_ptr<DataBlock> block(new DataBlock());
231 
232  block.get()->Type = arg->Type;
233  // copy pointer //
234  block.get()->Value = arg->Value;
235 
236  // destroy original //
237  arg->Value = NULL;
238 
239  return block.release();
240  }
DataBlock(const _U &forceempty)
Creates an uninitialized block of type non.
Definition: DataBlock.h:166

◆ IsConversionAllowedNonPtr()

template<class DBlockT>
template<class ConvertT >
bool Leviathan::DataBlock< DBlockT >::IsConversionAllowedNonPtr ( ) const
inline

Definition at line 265 of file DataBlock.h.

265  {
266  // check it //
268  }
static bool IsConversionAllowedNonPtr(const DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:98

◆ IsConversionAllowedPtr()

template<class DBlockT>
template<class ConvertT >
bool Leviathan::DataBlock< DBlockT >::IsConversionAllowedPtr ( ) const
inline

Definition at line 271 of file DataBlock.h.

271  {
272  // check it //
274  }
static bool IsConversionAllowedPtr(const DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:107

◆ operator ConvertT()

template<class DBlockT>
template<class ConvertT >
Leviathan::DataBlock< DBlockT >::operator ConvertT ( ) const
inline

Definition at line 252 of file DataBlock.h.

252  {
253 
255  }
static T DoConversionNonPtr(const DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:76

◆ operator ConvertT *()

template<class DBlockT>
template<class ConvertT >
Leviathan::DataBlock< DBlockT >::operator ConvertT * ( )
inline

Definition at line 258 of file DataBlock.h.

258  {
259 
261  }
static T * DoConversionPtr(DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:85

◆ operator=()

template<class DBlockT>
DataBlock& Leviathan::DataBlock< DBlockT >::operator= ( const DataBlock< DBlockT > &  arg)
inline

Definition at line 203 of file DataBlock.h.

203  {
204  // release existing value (if any) //
206 
207  // copy type //
208  Type = arg.Type;
209  // skip if other is null value //
210  if(arg.Value == NULL)
211  return *this;
212  // deep copy //
213  Value = new DBlockT(*arg.Value);
214 
215  // avoid performance issues //
216  return *this;
217  }
#define SAFE_DELETE(x)
Definition: Define.h:153

◆ operator==()

template<class DBlockT>
bool Leviathan::DataBlock< DBlockT >::operator== ( const DataBlock< DBlockT > &  other)
inline

Definition at line 243 of file DataBlock.h.

243  {
244 
245  // compare values with default operator //
246  return *Value == *other.Value;
247  }

Member Data Documentation

◆ Value

template<class DBlockT>
DBlockT* Leviathan::DataBlock< DBlockT >::Value

Definition at line 278 of file DataBlock.h.


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