Leviathan  0.8.0.0
Leviathan game engine
DataBlock.h
Go to the documentation of this file.
1 #pragma once
2 // ------------------------------------ //
3 #include "Define.h"
4 // ------------------------------------ //
5 // ---- includes ---- //
6 #include "../../Common/ReferenceCounted.h"
7 #include "../../Utility/Convert.h"
8 #include <map>
9 #include <memory>
10 
11 #ifdef SFML_PACKETS
12 #include "../../Common/SFMLPackets.h"
13 #endif
14 
15 #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
16 #include "../../Exceptions.h"
17 #endif
18 
19 
20 static_assert(sizeof(short) == 2, "Short must be 2 bytes for datablocks to work accross the network");
21 
22 #define DATABLOCK_TYPE_INT 3
23 #define DATABLOCK_TYPE_FLOAT 4
24 #define DATABLOCK_TYPE_BOOL 5
25 #define DATABLOCK_TYPE_WSTRING 6
26 #define DATABLOCK_TYPE_STRING 7
27 #define DATABLOCK_TYPE_CHAR 8
28 #define DATABLOCK_TYPE_DOUBLE 9
29 #define DATABLOCK_TYPE_VOIDPTR 11
30 
31 #define DATABLOCK_TYPE_ERROR 9000
32 #define DATABLOCK_TYPE_UNINITIALIZED 10000
33 
34 namespace Leviathan{
35 
36  // forward declaration //
37  template<class DBlockT> class DataBlock;
38 
39  // template struct for getting right type for right type...
40  template<class T>
42 
43  static const short TVal = DATABLOCK_TYPE_ERROR;
44  };
45  // specification values //
46 
47 #define NAMERESOLVERTEMPLATEINSTANTIATION(DType, TVALDEFINE) template<> struct DataBlockNameResolver<DType>{ static const short TVal = TVALDEFINE;};
48 
57  // for conversion check to work //
59 
60  // static class used to convert DataBlocks from different types to other types //
61  template<class FromDataBlockType, class TargetType>
63  public:
64  // conversion function that templates overload //
65  static inline TargetType DoConvert(const FromDataBlockType* block){
66  LEVIATHAN_ASSERT(0, "conversion not possible");
67  return TargetType();
68  }
69  static const bool AllowedConversion = false;
70  };
71 
72  // conversion templates //
73  template<class DBlockTDT, class T>
75  // handles operator class() functions
76  static inline T DoConversionNonPtr(const DataBlock<DBlockTDT>* block){
77  // direct conversion check //
78  //if(DataBlockNameResolver<T>::TVal == block->Type){
79  // // just return //
80  // return *block->Value;
81  //}
82  return DataBlockConverter<DataBlock<DBlockTDT>, T>::DoConvert(block);
83  }
84  // handles operator class*() functions
85  static inline T* DoConversionPtr(DataBlock<DBlockTDT>* block){
86  // direct conversion check //
88  // just return //
89  // Already type checked so force the pointer type //
90  return reinterpret_cast<T*>(block->Value);
91  }
92  // cannot return converted value //
93 //#pragma message ("cannot return pointer from converted type")
94  LEVIATHAN_ASSERT(0, "return pointer of converted value not possible");
95  return NULL;
96  }
97  // functions used to check is conversion allowed //
98  static inline bool IsConversionAllowedNonPtr(const DataBlock<DBlockTDT>* block){
99  // check types //
100  if(DataBlockNameResolver<T>::TVal == block->Type){
101  // same type, is allowed always //
102  return true;
103  }
104  // use templates to see if there is a template that allows this //
105  return DataBlockConverter<DataBlock<DBlockTDT>, T>::AllowedConversion;
106  }
107  static inline bool IsConversionAllowedPtr(const DataBlock<DBlockTDT>* block){
108  // check types //
109  if(DataBlockNameResolver<T>::TVal == block->Type){
110  // same type, is allowed always //
111  return true;
112  }
113  // different types, cannot be returned as pointer //
114  return false;
115  }
116  };
117 
118  // templates for getting AngelScript type id from template //
119  template<class TypeToFetchID>
121 
122  static inline int GetTypeIDFromTemplated(){
123  return -1;
124  }
125  };
126 
127  // non template base class for pointers //
129  public:
130  // virtual destructor for deleting through base pointers //
131  inline virtual ~DataBlockAll(){
132 
133 
134  }
135 
136  // function used in deep copy //
137  DLLEXPORT virtual DataBlockAll* AllocateNewFromThis() const = 0;
138 
139 
140  // comparison operator //
141  inline bool operator ==(const DataBlockAll &other){
142 
143  // just compare types here //
144  return Type == other.Type;
145  }
146 
147  short Type;
148 
149  protected:
150  // private constructor to make sure that no instances of this class exist //
152 
153  }
154 
155  };
156 
157 
160  template<class DBlockT>
161  class DataBlock : public DataBlockAll{
162  struct _U{};
163  public:
166  explicit DataBlock(const _U &forceempty) : Value(NULL){
167 
169  }
170 
171  DataBlock(const DBlockT &val) : Value(new DBlockT(val)){
172 
173  // use templates to get type //
175  }
176  DataBlock(DBlockT* val) : Value(val){
177 
178  // use templates to get type //
180  }
181 
182  #ifdef SFML_PACKETS
183 
184  DLLEXPORT DataBlock(sf::Packet &packet);
185 
186  DLLEXPORT void AddDataToPacket(sf::Packet &packet);
187  #endif //SFML_PACKETS
188 
189  DataBlock(const DataBlock &otherdeepcopy) : 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  }
196 
197 
198  virtual ~DataBlock(){
199  // erase memory //
201  }
202  // deep copy operator //
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  }
218 
219  // function used in deep copy //
221 
222  return static_cast<DataBlockAll*>((new DataBlock<DBlockT>(
223  const_cast<const DataBlock<DBlockT>&>(*this))));
224  }
225 
226  // shallow copy operator //
227  // copies just the pointer over (fast for copies that don't need both copies //
228  static inline DataBlock* CopyConstructor(DataBlock* arg){
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  }
241 
242  // comparison operator //
243  inline bool operator ==(const DataBlock<DBlockT> &other){
244 
245  // compare values with default operator //
246  return *Value == *other.Value;
247  }
248 
249 
250  // value getting operators //
251  template<class ConvertT>
252  operator ConvertT() const{
253 
255  }
256  // explicit so that this doesn't get called all the time with invalid values and such //
257  template<class ConvertT>
258  /*explicit*/ operator ConvertT*(){
259 
261  }
262 
263  // conversion checkers //
264  template<class ConvertT>
266  // check it //
268  }
269 
270  template<class ConvertT>
272  // check it //
274  }
275 
276  //private:
277 
278  DBlockT* Value;
279  };
280 
283  template<class DBlockT>
284  class DataBlock<DBlockT*> : public DataBlockAll{
285  public:
286  DataBlock() : Value(NULL){
287 
288  Type = DATABLOCK_TYPE_ERROR;
289  }
290  DataBlock(const DBlockT* val) : Value(val){
291 
292  // use templates to get type //
294  }
295  DataBlock(DBlockT* val) : Value(val){
296 
297  // use templates to get type //
299  }
300  // not actually working on ptr types //
301  DataBlock(const DataBlock &otherdeepcopy) : Value(otherdeepcopy.Value){
302 
303  // copy type //
304  Type = otherdeepcopy.Type;
305  }
306 
307  virtual ~DataBlock(){
308  }
309 
310  // deep copy operator //
311  DataBlock& operator =(const DataBlock& arg){
312  // copy type //
313  Type = arg.Type;
314  Value = arg.Value;
315  // avoid performance issues //
316  return *this;
317  }
318 
319  // function used in deep copy //
321 
322  return static_cast<DataBlockAll*>((new DataBlock<DBlockT*>(const_cast<const DataBlock<DBlockT*>&>(*this))));
323  }
324 
325  // shallow copy operator //
326  // copies just the pointer over (fast for copies that don't need both copies //
327  static inline DataBlock* CopyConstructor(DataBlock* arg){
328 
329  std::unique_ptr<DataBlock> block(new DataBlock());
330 
331  block.get()->Type = arg->Type;
332  // copy pointer //
333  block.get()->Value = arg->Value;
334 
335  // destroy original //
336  arg->Value = NULL;
337 
338  return block.release();
339  }
340 
341  // comparison operator //
342  inline bool operator ==(const DataBlock<DBlockT> &other){
343 
344  // compare values with default operator //
345  return Value == other.Value;
346  }
347 
348  // value getting operators //
349  template<class ConvertT>
350  operator ConvertT() const{
351  //LEVIATHAN_ASSERT(false, "data block pointer cannot be made into value");
352  //return ConvertT();
353  return reinterpret_cast<ConvertT>(Value);
354  }
355  // explicit so that this doesn't get called all the time with invalid values and such //
356  template<class ConvertT>
357  explicit operator ConvertT*(){
358 
360  }
361 
362  // conversion checkers //
363  template<class ConvertT>
365  // check it //
366  return false;
367  }
368 
369  template<class ConvertT>
371  // check it //
373  }
374 
375  DBlockT* Value;
376  };
377 
378 
379 
380  // define specific types //
381 
390 
391  // template class for converting Type values to data types //
392  template<int TValue>
394 
395  static const DataBlockAll* Conversion(const DataBlockAll* bl){
396  return bl;
397  }
399  return bl;
400  }
401  };
402 
403 
404  // type resolver specifications //
405 #define TVALRESOLVERTYPE(BlockTypeT, DEFINEDValT) template<> struct TvalToTypeResolver<DEFINEDValT>{\
406  static const BlockTypeT* Conversion(const DataBlockAll* bl){\
407  return static_cast<const BlockTypeT*>(bl);}; \
408  static BlockTypeT* Conversion(DataBlockAll* bl){return static_cast<BlockTypeT*>(bl);}};
409 
418 
419 
426  public:
427 
430 
431  }
432 
433  // constructors that accept any type of DataBlock //
434  template<class DBRType>
436 
437  BlockData = static_cast<DataBlockAll*>(block);
438  }
439  // constructors that accept basic types //
440  VariableBlock(const int &var){
441  BlockData = static_cast<DataBlockAll*>(new IntBlock(var));
442  }
443  VariableBlock(const bool &var, bool isactuallybooltype){
444  BlockData = static_cast<DataBlockAll*>(new BoolBlock(var));
445  }
446  VariableBlock(const std::string &var){
447  BlockData = static_cast<DataBlockAll*>(new StringBlock(var));
448  }
449  VariableBlock(const std::wstring &var){
450  BlockData = static_cast<DataBlockAll*>(new WstringBlock(var));
451  }
452  VariableBlock(const double &var){
453  BlockData = static_cast<DataBlockAll*>(new DoubleBlock(var));
454  }
455  VariableBlock(const float &var){
456  BlockData = static_cast<DataBlockAll*>(new FloatBlock(var));
457  }
458  VariableBlock(const char &var){
459  BlockData = static_cast<DataBlockAll*>(new CharBlock(var));
460  }
461  VariableBlock(void* var){
462  BlockData = static_cast<DataBlockAll*>(new VoidPtrBlock(var));
463  }
464 
465 
466  #ifdef SFML_PACKETS
467 
469  DLLEXPORT VariableBlock(sf::Packet &packet);
470 
471 
473  DLLEXPORT void AddDataToPacket(sf::Packet &packet) const;
474 
475  #endif //SFML_PACKETS
476 
477  // deep copy constructor //
479  // copy data //
481  }
482 
483  // constructor for creating this from std::wstring //
484  DLLEXPORT VariableBlock(const std::string &valuetoparse, std::map<std::string,
485  std::shared_ptr<VariableBlock>>* predefined);
486 
487  // non template constructor //
489 
490  BlockData = block;
491  }
492  // destructor that releases data //
493  virtual ~VariableBlock(){
494 
496  }
497 
498  // getting function //
500 
501  return BlockData;
502  }
503 
504  inline const DataBlockAll* GetBlockConst() const{
505 
506  return static_cast<const DataBlockAll*>(BlockData);
507  }
508 
509  // operators //
510  // Checks is this valid //
511  bool IsValid() const {
512 
513  if (!BlockData)
514  return false;
515 
516  return true;
517  }
518 
519  // copy operators //
520  // shallow copy (when both instances aren't wanted //
522  // release existing value (if any) //
523  if(BlockData){
525  }
526 
527  // copy pointer //
528  BlockData = arg->BlockData;
529 
530  // destroy original //
531  arg->BlockData = NULL;
532 
533  // avoid performance issues //
534  return *this;
535  }
536 
537  template<class DBlockTP>
539  // release existing value (if any) //
540  if(BlockData){
542  }
543 
544  // copy pointer //
545  BlockData = static_cast<DataBlockAll*>(arg);
546 
547  // avoid performance issues //
548  return *this;
549  }
550 
551  // deep copy //
553  // release existing value (if any) //
554  if(BlockData){
556  }
557 
558  // copy data //
560 
561  // avoid performance issues //
562  return *this;
563  }
564 
566  inline bool operator ==(const VariableBlock &other) const{
567  // returns false if either block is NULL //
568  if(BlockData == NULL || other.BlockData == NULL)
569  return false;
570  // if different types cannot match //
571  if(BlockData->Type != other.BlockData->Type)
572  return false;
573  // need to check if values match //
577  else if(BlockData->Type == DATABLOCK_TYPE_FLOAT)
580  else if(BlockData->Type == DATABLOCK_TYPE_BOOL)
589  else if(BlockData->Type == DATABLOCK_TYPE_CHAR)
595 
596  // type that shouldn't be used is used //
597  LEVIATHAN_ASSERT(0, "unallowed datatype in datablock");
598  return false;
599  }
600 
602  inline bool operator !=(const VariableBlock &other) const{
603 
604  return !(*this == other);
605  }
606 
607 
608  // templated operators //
609  template<class ConvertT>
610  inline operator ConvertT() const{
611  // cast DataBlock to derived type //
614  else if(BlockData->Type == DATABLOCK_TYPE_FLOAT)
616  else if(BlockData->Type == DATABLOCK_TYPE_BOOL)
622  else if(BlockData->Type == DATABLOCK_TYPE_CHAR)
626 
627  // type that shouldn't be used is used //
628  LEVIATHAN_ASSERT(0, "unallowed datatype in datablock");
629  return ConvertT();
630  }
631  template<class ConvertT>
632  inline operator ConvertT*(){
633  // check does types match //
635 
638  else if(BlockData->Type == DATABLOCK_TYPE_FLOAT)
640  else if(BlockData->Type == DATABLOCK_TYPE_BOOL)
646  else if(BlockData->Type == DATABLOCK_TYPE_CHAR)
652  }
653  // non matching types //
654  LEVIATHAN_ASSERT(0, "unallowed cast from type to another with return pointer");
655  return NULL;
656  }
657 
658 
659  // verifying functions //
660 
661  // conversion checkers //
662  template<class ConvertT>
663  inline bool IsConversionAllowedNonPtr() const{
664  // check it //
667  IsConversionAllowedNonPtr<ConvertT>();
668  else if(BlockData->Type == DATABLOCK_TYPE_FLOAT)
670  IsConversionAllowedNonPtr<ConvertT>();
671  else if(BlockData->Type == DATABLOCK_TYPE_BOOL)
673  IsConversionAllowedNonPtr<ConvertT>();
676  IsConversionAllowedNonPtr<ConvertT>();
679  IsConversionAllowedNonPtr<ConvertT>();
680  else if(BlockData->Type == DATABLOCK_TYPE_CHAR)
682  IsConversionAllowedNonPtr<ConvertT>();
685  IsConversionAllowedNonPtr<ConvertT>();
688  IsConversionAllowedNonPtr<ConvertT>();
689 
690  LEVIATHAN_ASSERT(0, "invalid datablock type");
691  return false;
692  }
693 
694  template<class ConvertT>
695  inline bool IsConversionAllowedPtr() const{
696  // check it //
699  IsConversionAllowedPtr<ConvertT>();
700  else if(BlockData->Type == DATABLOCK_TYPE_FLOAT)
702  IsConversionAllowedPtr<ConvertT>();
703  else if(BlockData->Type == DATABLOCK_TYPE_BOOL)
705  IsConversionAllowedPtr<ConvertT>();
708  IsConversionAllowedPtr<ConvertT>();
711  IsConversionAllowedPtr<ConvertT>();
712  else if(BlockData->Type == DATABLOCK_TYPE_CHAR)
714  IsConversionAllowedPtr<ConvertT>();
717  IsConversionAllowedPtr<ConvertT>();
720  IsConversionAllowedPtr<ConvertT>();
721 
722  LEVIATHAN_ASSERT(0, "invalid datablock type");
723  return false;
724  }
725 
726  // templated assignment conversion operator //
727  template<class ConvertT>
728  inline bool ConvertAndAssingToVariable(ConvertT &var) const{
729  // return if not allowed conversion //
730  if(!IsConversionAllowedNonPtr<ConvertT>()){
731  //Logger::Get()->Warning(L"VariableBlock: conversion not allowed");
732  return false;
733  }
734  // assign directly to the wanted value, should be faster than converting returning and then assigning //
735  var = this->operator ConvertT();
736 
737  // assignment succeeded //
738  return true;
739  }
740 
742  template<class ConvertT>
743  inline ConvertT ConvertAndReturnVariable() const{
744  // return if not allowed conversion //
745  if(!IsConversionAllowedNonPtr<ConvertT>()){
746  //Logger::Get()->Warning(L"VariableBlock: conversion not allowed");
747  return ConvertT(0);
748  }
749 
750  // return conversion result //
751  return this->operator ConvertT();
752  }
753 
754  protected:
755  // data storing //
757 
758  };
759 
760 
763  public:
764  // constructors that accept any type of DataBlock //
765  template<class DBRType>
766  NamedVariableBlock(DataBlock<DBRType>* block, const std::string &name) :
767  VariableBlock(block), Name(name)
768  {
769 
770  }
771 
772  // non template constructor //
773  NamedVariableBlock(DataBlockAll* block, const std::string &name) :
774  VariableBlock(block), Name(name)
775  {
776 
777  }
778 
779  // constructors that accept basic types //
780  NamedVariableBlock(const int &var, const std::string &name) :
781  VariableBlock(var), Name(name)
782  {
783  }
784  NamedVariableBlock(const bool &var, bool isactuallybooltype, const std::string &name) :
785  VariableBlock(var, isactuallybooltype), Name(name)
786  {
787  }
788  NamedVariableBlock(const std::string &var, const std::string &name) :
789  VariableBlock(var), Name(name)
790  {
791  }
792  NamedVariableBlock(const std::wstring &var, const std::string &name) :
793  VariableBlock(var), Name(name)
794  {
795  }
796  NamedVariableBlock(const double &var, const std::string &name) :
797  VariableBlock(var), Name(name)
798  {
799  }
800  NamedVariableBlock(const float &var, const std::string &name) :
801  VariableBlock(var), Name(name)
802  {
803  }
804  NamedVariableBlock(const char &var, const std::string &name) :
805  VariableBlock(var), Name(name)
806  {
807  }
808  NamedVariableBlock(void* var, const std::string &name) :
809  VariableBlock(var), Name(name)
810  {
811  }
812 
813  inline std::string GetName() const{
814  return Name;
815  }
816 
817  inline bool CompareName(const std::string &str) const{
818 
819  return Name == str;
820  }
821 
822  inline std::string& GetNameChangeable(){
823 
824  return Name;
825  }
826 
827  protected:
828 
829  std::string Name;
830  };
831 
832 #ifdef LEVIATHAN_USING_ANGELSCRIPT
841  public:
842 
843  template<class BlockBaseType>
845  const std::string &name) :
846  NamedVariableBlock(block, name)
847  {
848  // getting typeid //
850  }
851 
852  DLLEXPORT ScriptSafeVariableBlock(VariableBlock* copyfrom, const std::string &name);
853 
854 
855  bool IsValidType(){
856  return ASTypeID > 0 ? true: false;
857  }
858 
859  // script proxy functions //
861  return ConvertAndReturnVariable<int>();
862  }
864 
865  return ConvertAndReturnVariable<std::string>();
866  }
867 
868  protected:
869 
870  int ASTypeID;
871  };
872 #endif //LEVIATHAN_USING_ANGELSCRIPT
873 
874  // Stream operators //
875  DLLEXPORT std::ostream& operator <<(std::ostream &stream,
876  const Leviathan::VariableBlock &value);
877 
878 
879  // conversion template specifications //
880 #define CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(BlockTypeName, ToConvertTypeName, ConvertActionToDo) template<> \
881  class DataBlockConverter<BlockTypeName, ToConvertTypeName>{public: \
882  static inline ToConvertTypeName DoConvert(const BlockTypeName* block){ \
883  return ConvertActionToDo;}; \
884  static const bool AllowedConversion = true;};
885 #define CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCKDEFAULT(BlockTypeName, ToConvertTypeName) \
886  template<> class DataBlockConverter<BlockTypeName, ToConvertTypeName>{public: \
887  static inline ToConvertTypeName DoConvert(const BlockTypeName* block){ \
888  return (ToConvertTypeName)(*block->Value);}; \
889  static const bool AllowedConversion = true;};
890 
891  // std::wstring and std::string conversions with templates //
892  template<class FromDataBlockType>
893  class DataBlockConverter<FromDataBlockType, std::wstring>{
894  public:
895  static inline std::wstring DoConvert(const FromDataBlockType* block){
896  return std::to_wstring(*block->Value);
897  }
898  static const bool AllowedConversion = true;
899  };
900  template<class FromDataBlockType>
901  class DataBlockConverter<FromDataBlockType, std::string>{
902  public:
903  static inline std::string DoConvert(const FromDataBlockType* block){
904  return Convert::ToString(*block->Value);
905  }
906  static const bool AllowedConversion = true;
907  };
908 
909 
910 
911 
912  // ------------------ IntBlock conversions ------------------ //
914  CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(IntBlock, bool, (*block->Value) != 0);
918 
919  // ------------------ FloatBlock conversions ------------------ //
921  CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(FloatBlock, bool, (*block->Value) != 0);
925  // ------------------ BoolBlock conversions ------------------ //
930 
931  // ------------------ CharBlock conversions ------------------ //
933  CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(CharBlock, bool, (*block->Value) != 0);
937  // ------------------ DoubleBlock conversions ------------------ //
939  CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(DoubleBlock, bool, (*block->Value) != 0);
943 
944  // little different std::string block definitions //
945  // ------------------ WstringBlock conversions ------------------ //
946  CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(WstringBlock, std::wstring, (*block->Value));
948  Convert::Utf16ToUtf8(*block->Value));
950  Convert::WstringFromBoolToInt(*block->Value) != 0);
952  Convert::WstringTo<float>(*block->Value));
954  Convert::WstringTo<double>(*block->Value));
956  (char)Convert::WstringTo<wchar_t>(*block->Value));
958  Convert::WstringTo<int>(*block->Value));
960  CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(StringBlock, std::string, (*block->Value));
962  Convert::Utf8ToUtf16(*block->Value));
964  Convert::StringFromBoolToInt(*block->Value) != 0);
966  Convert::StringTo<float>(*block->Value));
968  Convert::StringTo<double>(*block->Value));
970  Convert::StringTo<char>(*block->Value));
972  Convert::StringTo<int>(*block->Value));
973 
974 }
975 
976 #ifdef LEAK_INTO_GLOBAL
978 #endif
979 
static const bool AllowedConversion
Definition: DataBlock.h:69
DataBlock< float > FloatBlock
Definition: DataBlock.h:383
VariableBlock(const float &var)
Definition: DataBlock.h:455
static DataBlockAll * Conversion(DataBlockAll *bl)
Definition: DataBlock.h:398
VariableBlock & operator=(VariableBlock *arg)
Definition: DataBlock.h:521
DataBlock(const DBlockT *val)
Definition: DataBlock.h:290
DataBlock(const DataBlock &otherdeepcopy)
Definition: DataBlock.h:189
NamedVariableBlock(const char &var, const std::string &name)
Definition: DataBlock.h:804
static TargetType DoConvert(const FromDataBlockType *block)
Definition: DataBlock.h:65
static const short TVal
Definition: DataBlock.h:43
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCKDEFAULT(IntBlock, float)
std::string ConvertAndReturnProxyString()
Definition: DataBlock.h:863
static DLLEXPORT int StringFromBoolToInt(const std::string &i)
Definition: Convert.cpp:29
bool IsConversionAllowedPtr() const
Definition: DataBlock.h:695
bool CompareName(const std::string &str) const
Definition: DataBlock.h:817
CONVERSIONTEMPLATESPECIFICATIONFORDATABLOCK(IntBlock, int,(*block->Value))
NamedVariableBlock(const std::string &var, const std::string &name)
Definition: DataBlock.h:788
static T DoConversionNonPtr(const DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:76
static bool IsConversionAllowedNonPtr(const DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:98
static DLLEXPORT std::string Utf16ToUtf8(const std::wstring &utf16str)
Encodes an UTF8 string from a wide string (wstring/utf16)
Definition: Convert.cpp:108
DataBlock< std::wstring > WstringBlock
Definition: DataBlock.h:385
bool operator==(const DataBlockAll &other)
Definition: DataBlock.h:141
bool operator==(const VariableBlock &other) const
comparison operator
Definition: DataBlock.h:566
static DLLEXPORT std::wstring Utf8ToUtf16(const std::string &utf8str)
Decodes an UTF8 string to an UTF16 string (wide string/wstring)
Definition: Convert.cpp:76
virtual DataBlockAll * AllocateNewFromThis() const
Definition: DataBlock.h:320
VariableBlock()
Default empty constructor, block has no value of any kind.
Definition: DataBlock.h:429
DataBlock< double > DoubleBlock
Definition: DataBlock.h:388
VariableBlock(const double &var)
Definition: DataBlock.h:452
virtual DataBlockAll * AllocateNewFromThis() const
Definition: DataBlock.h:220
VariableBlock(void *var)
Definition: DataBlock.h:461
NAMERESOLVERTEMPLATEINSTANTIATION(int, DATABLOCK_TYPE_INT)
ConvertT ConvertAndReturnVariable() const
Definition: DataBlock.h:743
NamedVariableBlock(const double &var, const std::string &name)
Definition: DataBlock.h:796
VariableBlock(DataBlockAll *block)
Definition: DataBlock.h:488
VariableBlock(DataBlock< DBRType > *block)
Definition: DataBlock.h:435
#define DATABLOCK_TYPE_INT
Definition: DataBlock.h:22
bool operator!=(const VariableBlock &other) const
Opposite of the comparison operator.
Definition: DataBlock.h:602
std::string GetName() const
Definition: DataBlock.h:813
#define DATABLOCK_TYPE_VOIDPTR
Definition: DataBlock.h:29
DataBlockAll * BlockData
Definition: DataBlock.h:756
static bool IsConversionAllowedPtr(const DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:107
DataBlock(const DataBlock &otherdeepcopy)
Definition: DataBlock.h:301
static DLLEXPORT int WstringFromBoolToInt(const std::wstring &i)
Definition: Convert.cpp:22
#define DATABLOCK_TYPE_WSTRING
Definition: DataBlock.h:25
VariableBlock(const bool &var, bool isactuallybooltype)
Definition: DataBlock.h:443
Reference counted version for scripts of VariableBlock.
Definition: DataBlock.h:840
NamedVariableBlock(const std::wstring &var, const std::string &name)
Definition: DataBlock.h:792
ScriptSafeVariableBlock(DataBlock< BlockBaseType > *block, const std::string &name)
Definition: DataBlock.h:844
NamedVariableBlock(DataBlock< DBRType > *block, const std::string &name)
Definition: DataBlock.h:766
#define DATABLOCK_TYPE_FLOAT
Definition: DataBlock.h:23
DataBlock< bool > BoolBlock
Definition: DataBlock.h:384
bool ConvertAndAssingToVariable(ConvertT &var) const
Definition: DataBlock.h:728
DataBlock< void * > VoidPtrBlock
Definition: DataBlock.h:389
VariableBlock(const char &var)
Definition: DataBlock.h:458
DataBlock & operator=(const DataBlock &arg)
Definition: DataBlock.h:203
DataBlock(const DBlockT &val)
Definition: DataBlock.h:171
#define DATABLOCK_TYPE_STRING
Definition: DataBlock.h:26
virtual ~DataBlock()
Definition: DataBlock.h:198
DataBlock(DBlockT *val)
Definition: DataBlock.h:176
static DataBlock * CopyConstructor(DataBlock *arg)
Definition: DataBlock.h:228
bool operator==(const ScriptAccess &lhs, const AccessFlags &rhs)
Definition: AccessMask.h:59
virtual DLLEXPORT DataBlockAll * AllocateNewFromThis() const =0
bool IsValid() const
Definition: DataBlock.h:511
bool IsConversionAllowedNonPtr() const
Definition: DataBlock.h:663
NamedVariableBlock(const float &var, const std::string &name)
Definition: DataBlock.h:800
#define DATABLOCK_TYPE_DOUBLE
Definition: DataBlock.h:28
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:104
NamedVariableBlock(void *var, const std::string &name)
Definition: DataBlock.h:808
NamedVariableBlock(DataBlockAll *block, const std::string &name)
Definition: DataBlock.h:773
static std::string ToString(const T &val)
Definition: Convert.h:72
DataBlockAll * GetBlock()
Definition: DataBlock.h:499
TVALRESOLVERTYPE(IntBlock, DATABLOCK_TYPE_INT)
VariableBlock(const std::wstring &var)
Definition: DataBlock.h:449
const DataBlockAll * GetBlockConst() const
Definition: DataBlock.h:504
DataBlock< int > IntBlock
Definition: DataBlock.h:382
DLLEXPORT void AddDataToPacket(sf::Packet &packet)
Definition: DataBlock.cpp:180
static DataBlock * CopyConstructor(DataBlock *arg)
Definition: DataBlock.h:327
bool operator==(const DataBlock< DBlockT > &other)
Definition: DataBlock.h:243
Main DataBlock class.
Definition: DataBlock.h:37
static const DataBlockAll * Conversion(const DataBlockAll *bl)
Definition: DataBlock.h:395
#define DATABLOCK_TYPE_ERROR
Definition: DataBlock.h:31
VariableBlock(const int &var)
Definition: DataBlock.h:440
NamedVariableBlock(const bool &var, bool isactuallybooltype, const std::string &name)
Definition: DataBlock.h:784
bool IsConversionAllowedPtr() const
Definition: DataBlock.h:271
#define DLLEXPORT
Definition: Include.h:84
#define DATABLOCK_TYPE_BOOL
Definition: DataBlock.h:24
std::string & GetNameChangeable()
Definition: DataBlock.h:822
DataBlock< std::string > StringBlock
Definition: DataBlock.h:386
VariableBlock(const std::string &var)
Definition: DataBlock.h:446
#define DATABLOCK_TYPE_UNINITIALIZED
Definition: DataBlock.h:32
bool IsConversionAllowedNonPtr() const
Definition: DataBlock.h:364
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
#define SAFE_DELETE(x)
Definition: Define.h:153
bool IsConversionAllowedNonPtr() const
Definition: DataBlock.h:265
VariableBlock(const VariableBlock &arg)
Definition: DataBlock.h:478
static std::wstring DoConvert(const FromDataBlockType *block)
Definition: DataBlock.h:895
DataBlock variant with name.
Definition: DataBlock.h:762
#define DATABLOCK_TYPE_CHAR
Definition: DataBlock.h:27
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Stores data to a packet.
Definition: DataBlock.cpp:195
DataBlock< char > CharBlock
Definition: DataBlock.h:387
static T * DoConversionPtr(DataBlock< DBlockTDT > *block)
Definition: DataBlock.h:85
DataBlock(const _U &forceempty)
Creates an uninitialized block of type non.
Definition: DataBlock.h:166
DLLEXPORT std::ostream & operator<<(std::ostream &stream, const VariableBlock &value)
Definition: DataBlock.cpp:284
static std::string DoConvert(const FromDataBlockType *block)
Definition: DataBlock.h:903
NamedVariableBlock(const int &var, const std::string &name)
Definition: DataBlock.h:780