Leviathan  0.8.0.0
Leviathan game engine
Leviathan::NamedVars Class Reference

#include <NamedVars.h>

+ Inheritance diagram for Leviathan::NamedVars:

Public Member Functions

 REFERENCE_COUNTED_PTR_TYPE (NamedVars)
 
DLLEXPORT NamedVars ()
 
DLLEXPORT NamedVars (NamedVars *stealfrom)
 Constructs a NamedVars by stealing variables from another. More...
 
DLLEXPORT NamedVars (const NamedVars &other)
 
DLLEXPORT NamedVars (const std::string &datadump, LErrorReporter *errorreport)
 
DLLEXPORT NamedVars (const std::vector< std::shared_ptr< NamedVariableList >> &variables)
 
DLLEXPORT NamedVars (std::shared_ptr< NamedVariableList > variable)
 
DLLEXPORT NamedVars (NamedVariableList *takevariable)
 
DLLEXPORT NamedVars (sf::Packet &packet)
 Loads a NamedVars object from a packet. More...
 
DLLEXPORT void AddDataToPacket (sf::Packet &packet) const
 Writes this NamedVars to a packet. More...
 
DLLEXPORT ~NamedVars ()
 
DLLEXPORT bool Add (std::shared_ptr< NamedVariableList > value)
 Adds a value. More...
 
DLLEXPORT bool SetValue (const std::string &name, const VariableBlock &value1)
 
DLLEXPORT bool SetValue (const std::string &name, VariableBlock *value1)
 
DLLEXPORT bool SetValue (const std::string &name, const std::vector< VariableBlock *> &values)
 
DLLEXPORT bool SetValue (NamedVariableList &nameandvalues)
 
DLLEXPORT size_t GetValueCount (const std::string &name) const
 
DLLEXPORT bool IsIndexValid (size_t index) const
 
DLLEXPORT VariableBlockGetValueNonConst (const std::string &name)
 
DLLEXPORT const VariableBlockGetValue (const std::string &name) const
 
DLLEXPORT bool GetValue (const std::string &name, VariableBlock &receiver) const
 
DLLEXPORT bool GetValue (const std::string &name, const int &index, VariableBlock &receiver) const
 Gets a VariableBlock from the specified index on the block matching name. More...
 
DLLEXPORT bool GetValue (const int &index, VariableBlock &receiver) const
 Gets constant value from vector index. More...
 
DLLEXPORT bool GetValues (const std::string &name, std::vector< const VariableBlock *> &receiver) const
 
DLLEXPORT std::shared_ptr< NamedVariableListGetValueDirect (const std::string &name) const
 
DLLEXPORT NamedVariableListGetValueDirectRaw (const std::string &name) const
 
DLLEXPORT NamedVariableListGetValueDirectRaw (size_t index) const
 
template<class T >
bool GetValueAndConvertTo (const std::string &name, T &receiver) const
 
DLLEXPORT std::vector< VariableBlock * > * GetValues (const std::string &name)
 
DLLEXPORT std::string Serialize (const std::string &lineprefix="") const
 Serializes this object into a string representation. More...
 
ScriptSafeVariableBlockGetScriptCompatibleValue (const std::string &name)
 Finds and returns the first value in a list matching name. More...
 
bool AddScriptCompatibleValue (ScriptSafeVariableBlock *value)
 
DLLEXPORT int GetVariableType (const std::string &name) const
 
DLLEXPORT int GetVariableType (Lock &guard, size_t index) const
 
int GetVariableType (size_t index) const
 
DLLEXPORT int GetVariableTypeOfAll (const std::string &name) const
 
DLLEXPORT int GetVariableTypeOfAll (Lock &guard, size_t index) const
 
int GetVariableTypeOfAll (size_t index) const
 
DLLEXPORT std::string GetName (size_t index)
 
DLLEXPORT bool GetName (size_t index, std::string &name) const
 
DLLEXPORT void SetName (Lock &guard, size_t index, const std::string &name)
 
void SetName (size_t index, const std::string &name)
 
DLLEXPORT void SetName (const std::string &oldname, const std::string &name)
 
DLLEXPORT bool CompareName (size_t index, const std::string &name) const
 
DLLEXPORT void AddVar (NamedVariableList *newvaluetoadd)
 
DLLEXPORT void AddVar (std::shared_ptr< NamedVariableList > values)
 
DLLEXPORT void AddVar (const std::string &name, VariableBlock *valuetosteal)
 
DLLEXPORT void Remove (size_t index)
 
DLLEXPORT void Remove (const std::string &name)
 
DLLEXPORT void RemoveIfExists (const std::string &name, Lock &guard)
 Removes a value with the given name if it exists. More...
 
DLLEXPORT bool LoadVarsFromFile (const std::string &file, LErrorReporter *errorreport)
 
DLLEXPORT std::vector< std::shared_ptr< NamedVariableList > > * GetVec ()
 
DLLEXPORT void SetVec (std::vector< std::shared_ptr< NamedVariableList >> &vec)
 
DLLEXPORT size_t GetVariableCount () const
 Returns the size of the internal variable vector. More...
 
 operator bool () const
 
size_t Find (const std::string &name) const
 
DLLEXPORT size_t Find (Lock &guard, const std::string &name) const
 
template<class T >
bool ShouldAddValueIfNotFoundOrWrongType (const std::string &name)
 
- 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...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 

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 ()
 
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Detailed Description

Todo:
Make all methods throw exceptions on invalid operations

Definition at line 182 of file NamedVars.h.

Constructor & Destructor Documentation

◆ NamedVars() [1/8]

NamedVars::NamedVars ( )

Definition at line 777 of file NamedVars.cpp.

777  : Variables()
778 {
779  // nothing to initialize //
780 }

◆ NamedVars() [2/8]

DLLEXPORT NamedVars::NamedVars ( NamedVars stealfrom)

Constructs a NamedVars by stealing variables from another.

Note
The other object will be empty after this

Definition at line 791 of file NamedVars.cpp.

791  : Variables(stealfrom->Variables)
792 {
793  stealfrom->Variables.clear();
794 }

◆ NamedVars() [3/8]

NamedVars::NamedVars ( const NamedVars other)

Definition at line 781 of file NamedVars.cpp.

782 {
783  // deep copy is required here //
784  Variables.reserve(other.Variables.size());
785  for(size_t i = 0; i < other.Variables.size(); i++) {
786  Variables.push_back(
787  shared_ptr<NamedVariableList>(new NamedVariableList(*other.Variables[i])));
788  }
789 }
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27

◆ NamedVars() [4/8]

DLLEXPORT NamedVars::NamedVars ( const std::string &  datadump,
LErrorReporter errorreport 
)
Todo:
Allow predefined values

Definition at line 796 of file NamedVars.cpp.

796  :
797  Variables()
798 {
799 
800  // load data directly to vector //
801  if(!NamedVariableList::ProcessDataDump(datadump, Variables, errorreport, NULL)) {
802 
803  // error happened //
804 #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
805  throw InvalidArgument("datadump processing failed");
806 #else
807  StateIsInvalid = true;
808  return;
809 #endif // ALTERNATIVE_EXCEPTIONS_FATAL
810  }
811 }
static DLLEXPORT bool ProcessDataDump(const std::string &data, std::vector< std::shared_ptr< NamedVariableList >> &vec, LErrorReporter *errorreport, std::map< std::string, std::shared_ptr< VariableBlock >> *predefined=NULL)
Definition: NamedVars.cpp:609

◆ NamedVars() [5/8]

DLLEXPORT Leviathan::NamedVars::NamedVars ( const std::vector< std::shared_ptr< NamedVariableList >> &  variables)

◆ NamedVars() [6/8]

DLLEXPORT Leviathan::NamedVars::NamedVars ( std::shared_ptr< NamedVariableList variable)

◆ NamedVars() [7/8]

DLLEXPORT NamedVars::NamedVars ( NamedVariableList takevariable)
Parameters
takevariablenew allocated ptr that will be owned by this object

Definition at line 824 of file NamedVars.cpp.

824  : Variables(1)
825 {
826  Variables[0] = std::shared_ptr<NamedVariableList>(takevariable);
827 }

◆ NamedVars() [8/8]

DLLEXPORT NamedVars::NamedVars ( sf::Packet &  packet)

Loads a NamedVars object from a packet.

Definition at line 835 of file NamedVars.cpp.

836 {
837  // First get the size //
838  int isize;
839 
840  if(!(packet >> isize)) {
841 #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
842  throw InvalidArgument("packet has invalid format");
843 #else
844  StateIsInvalid = true;
845  return;
846 #endif // ALTERNATIVE_EXCEPTIONS_FATAL
847  }
848 
849  // Reserve space //
850  Variables.reserve(isize);
851 
852  for(int i = 0; i < isize; i++) {
853 
854  shared_ptr<NamedVariableList> newvalue(new NamedVariableList(packet));
855 
856  if(!newvalue || !newvalue->IsValid())
857  continue;
858 
859  Variables.push_back(newvalue);
860  }
861 }
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27

◆ ~NamedVars()

NamedVars::~NamedVars ( )

Definition at line 829 of file NamedVars.cpp.

830 {
831  // no need to release due to smart pointers //
832 }

Member Function Documentation

◆ Add()

DLLEXPORT bool NamedVars::Add ( std::shared_ptr< NamedVariableList value)

Adds a value.

Returns
True if created new, false if updated an existing value

Definition at line 879 of file NamedVars.cpp.

880 {
881 
882  GUARD_LOCK();
883  auto index = Find(guard, value->Name);
884  // index check //
885  if(index >= Variables.size()) {
886 
887  Variables.push_back(value);
888  return true;
889  }
890 
891  Variables[index] = value;
892  return false;
893 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ AddDataToPacket()

DLLEXPORT void NamedVars::AddDataToPacket ( sf::Packet &  packet) const

Writes this NamedVars to a packet.

Definition at line 863 of file NamedVars.cpp.

864 {
865  GUARD_LOCK();
866  // First write size //
867  int isize = (int)Variables.size();
868 
869  packet << isize;
870 
871  // Write each individual variable //
872  for(int i = 0; i < isize; i++) {
873 
874  Variables[i]->AddDataToPacket(packet);
875  }
876 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ AddScriptCompatibleValue()

bool NamedVars::AddScriptCompatibleValue ( ScriptSafeVariableBlock value)

For use from scripts

Decrements value refcount

Definition at line 1278 of file NamedVars.cpp.

1279 {
1280 
1281  GUARD_LOCK();
1282 
1283  RemoveIfExists(value->GetName(), guard);
1284 
1285  bool success = false;
1286 
1287  try {
1288 
1289  Variables.push_back(shared_ptr<NamedVariableList>(new NamedVariableList(value)));
1290  success = true;
1291 
1292  } catch(...) {
1293  }
1294 
1295  value->Release();
1296  return success;
1297 }
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27
std::string GetName() const
Definition: DataBlock.h:813
FORCE_INLINE void Release()
removes a reference and deletes the object if reference count reaches zero
DLLEXPORT void RemoveIfExists(const std::string &name, Lock &guard)
Removes a value with the given name if it exists.
Definition: NamedVars.cpp:1224
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ AddVar() [1/3]

DLLEXPORT void NamedVars::AddVar ( NamedVariableList newvaluetoadd)

Definition at line 1193 of file NamedVars.cpp.

1194 {
1195  GUARD_LOCK();
1196  RemoveIfExists(newvaluetoadd->GetName(), guard);
1197  // create new smart pointer and push back //
1198  Variables.push_back(shared_ptr<NamedVariableList>(newvaluetoadd));
1199 }
DLLEXPORT void RemoveIfExists(const std::string &name, Lock &guard)
Removes a value with the given name if it exists.
Definition: NamedVars.cpp:1224
std::string GetName() const
Definition: NamedVars.h:136
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ AddVar() [2/3]

DLLEXPORT void Leviathan::NamedVars::AddVar ( std::shared_ptr< NamedVariableList values)

◆ AddVar() [3/3]

DLLEXPORT void NamedVars::AddVar ( const std::string &  name,
VariableBlock valuetosteal 
)

Definition at line 1201 of file NamedVars.cpp.

1202 {
1203  GUARD_LOCK();
1204  RemoveIfExists(name, guard);
1205  // create new smart pointer and push back //
1206  Variables.push_back(
1207  shared_ptr<NamedVariableList>(new NamedVariableList(name, valuetosteal)));
1208 }
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27
DLLEXPORT void RemoveIfExists(const std::string &name, Lock &guard)
Removes a value with the given name if it exists.
Definition: NamedVars.cpp:1224
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ CompareName()

bool NamedVars::CompareName ( size_t  index,
const std::string &  name 
) const

Definition at line 1178 of file NamedVars.cpp.

1179 {
1180  GUARD_LOCK();
1181 
1182  return Variables[index]->CompareName(name);
1183 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Find() [1/2]

size_t Leviathan::NamedVars::Find ( const std::string &  name) const
inline

Definition at line 363 of file NamedVars.h.

364  {
365  GUARD_LOCK();
366  return Find(guard, name);
367  }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Find() [2/2]

DLLEXPORT size_t NamedVars::Find ( Lock guard,
const std::string &  name 
) const

Definition at line 1251 of file NamedVars.cpp.

1252 {
1253  for(size_t i = 0; i < Variables.size(); i++) {
1254  if(Variables[i]->CompareName(name))
1255  return i;
1256  }
1257 
1258  return std::numeric_limits<size_t>::max();
1259 }
DLLEXPORT bool CompareName(size_t index, const std::string &name) const
Definition: NamedVars.cpp:1178

◆ GetName() [1/2]

string NamedVars::GetName ( size_t  index)

Definition at line 1150 of file NamedVars.cpp.

1151 {
1152  GUARD_LOCK();
1153 
1154  return Variables[index]->GetName();
1155 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetName() [2/2]

DLLEXPORT bool NamedVars::GetName ( size_t  index,
std::string &  name 
) const

Definition at line 1157 of file NamedVars.cpp.

1158 {
1159  GUARD_LOCK();
1160 
1161  Variables[index]->GetName(name);
1162  return true;
1163 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetScriptCompatibleValue()

ScriptSafeVariableBlock * NamedVars::GetScriptCompatibleValue ( const std::string &  name)

Finds and returns the first value in a list matching name.

Warning
For use from scripts

Definition at line 1262 of file NamedVars.cpp.

1263 {
1264  // Use a try block to not throw exceptions to the script engine //
1265  try {
1266  VariableBlock& tmpblock = GetValueNonConst(name);
1267 
1268  // Create script safe version //
1269  return new ScriptSafeVariableBlock(&tmpblock, name);
1270 
1271 
1272  } catch(...) {
1273  // Something failed, return empty handle //
1274  return NULL;
1275  }
1276 }
DLLEXPORT VariableBlock & GetValueNonConst(const std::string &name)
Definition: NamedVars.cpp:953
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
Reference counted version for scripts of VariableBlock.
Definition: DataBlock.h:840

◆ GetValue() [1/4]

DLLEXPORT const VariableBlock * NamedVars::GetValue ( const std::string &  name) const

Definition at line 970 of file NamedVars.cpp.

971 {
972  GUARD_LOCK();
973  auto index = Find(guard, name);
974 
975  if(index >= Variables.size()) {
976 
977 #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
978  throw InvalidArgument("value not found");
979 #else
980  return nullptr;
981 #endif // ALTERNATIVE_EXCEPTIONS_FATAL
982  }
983 
984  return Variables[index]->GetValueDirect();
985 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValue() [2/4]

DLLEXPORT bool NamedVars::GetValue ( const std::string &  name,
VariableBlock receiver 
) const

Definition at line 987 of file NamedVars.cpp.

988 {
989  GUARD_LOCK();
990  auto index = Find(guard, name);
991  // index check //
992  if(index >= Variables.size()) {
993  return false;
994  }
995  // specific operator wanted here //
996  receiver = const_cast<const VariableBlock&>(Variables[index]->GetValue());
997  return true;
998 }
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValue() [3/4]

DLLEXPORT bool NamedVars::GetValue ( const std::string &  name,
const int &  index,
VariableBlock receiver 
) const

Gets a VariableBlock from the specified index on the block matching name.

Definition at line 1000 of file NamedVars.cpp.

1002 {
1003  GUARD_LOCK();
1004 
1005  auto index = Find(guard, name);
1006 
1007  // index check //
1008  if(index >= Variables.size()) {
1009  return false;
1010  }
1011 
1012  // specific operator wanted here //
1013  receiver = const_cast<const VariableBlock&>(Variables[index]->GetValue(nindex));
1014  return true;
1015 }
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValue() [4/4]

DLLEXPORT bool NamedVars::GetValue ( const int &  index,
VariableBlock receiver 
) const

Gets constant value from vector index.

Definition at line 1017 of file NamedVars.cpp.

1018 {
1019  GUARD_LOCK();
1020  // index check //
1021  if(index >= static_cast<int>(Variables.size())) {
1022  return false;
1023  }
1024 
1025  // specific operator wanted here //
1026  receiver = const_cast<const VariableBlock&>(Variables[index]->GetValue(0));
1027  return true;
1028 }
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValueAndConvertTo()

template<class T >
bool Leviathan::NamedVars::GetValueAndConvertTo ( const std::string &  name,
T &  receiver 
) const
inline

Definition at line 257 of file NamedVars.h.

258  {
259  // use try block to catch all exceptions (not found and conversion fail //
260  GUARD_LOCK();
261  try {
262  auto index = Find(guard, name);
263 
264  if(index >= Variables.size())
265  return false;
266 
267  const VariableBlock* tmpblock = Variables[index]->GetValueDirect();
268  if(tmpblock == NULL) {
269  return false;
270  }
271  if(!tmpblock->ConvertAndAssingToVariable<T>(receiver)) {
272 
273  // Unallowed NamedVars block conversion
274  return false;
275  }
276  } catch(...) {
277  // variable not found / wrong type //
278  return false;
279  }
280  // correct variable has been set //
281  return true;
282  }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValueCount()

DLLEXPORT size_t NamedVars::GetValueCount ( const std::string &  name) const

Definition at line 1030 of file NamedVars.cpp.

1031 {
1032  GUARD_LOCK();
1033  auto index = Find(guard, name);
1034  // index check //
1035  if(index >= Variables.size()) {
1036  return 0;
1037  }
1038 
1039  return Variables[index]->GetVariableCount();
1040 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValueDirect()

DLLEXPORT std::shared_ptr< NamedVariableList > NamedVars::GetValueDirect ( const std::string &  name) const

Definition at line 1076 of file NamedVars.cpp.

1078 {
1079  GUARD_LOCK();
1080  auto index = Find(guard, name);
1081  // index check //
1082  if(index >= Variables.size()) {
1083  return NULL;
1084  }
1085  return Variables[index];
1086 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValueDirectRaw() [1/2]

DLLEXPORT NamedVariableList * NamedVars::GetValueDirectRaw ( const std::string &  name) const
Warning
You need to make sure that this is valid while the pointer is used

Definition at line 1088 of file NamedVars.cpp.

1089 {
1090  GUARD_LOCK();
1091  auto index = Find(guard, name);
1092  // index check //
1093  if(index >= Variables.size()) {
1094  return NULL;
1095  }
1096 
1097  return Variables[index].get();
1098 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValueDirectRaw() [2/2]

DLLEXPORT NamedVariableList * Leviathan::NamedVars::GetValueDirectRaw ( size_t  index) const

Definition at line 1100 of file NamedVars.cpp.

1101 {
1102 
1103  if(index >= Variables.size()) {
1104  return nullptr;
1105  }
1106 
1107  return Variables[index].get();
1108 }

◆ GetValueNonConst()

DLLEXPORT VariableBlock & NamedVars::GetValueNonConst ( const std::string &  name)

Definition at line 953 of file NamedVars.cpp.

954 {
955  GUARD_LOCK();
956  auto index = Find(guard, name);
957 
958  if(index >= Variables.size()) {
959 
960 #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
961  throw InvalidArgument("value not found");
962 #else
963  LEVIATHAN_ASSERT(0, "NamedVars name not found");
964 #endif // ALTERNATIVE_EXCEPTIONS_FATAL
965  }
966 
967  return Variables[index]->GetValue();
968 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValues() [1/2]

DLLEXPORT bool NamedVars::GetValues ( const std::string &  name,
std::vector< const VariableBlock *> &  receiver 
) const

Definition at line 1054 of file NamedVars.cpp.

1056 {
1057  GUARD_LOCK();
1058  auto index = Find(guard, name);
1059  // index check //
1060  if(index >= Variables.size()) {
1061  return false;
1062  }
1063  vector<VariableBlock*>& tmpvals = Variables[index]->GetValues();
1064 
1065  vector<const VariableBlock*> tmpconsted(tmpvals.size());
1066 
1067  for(size_t i = 0; i < tmpconsted.size(); i++) {
1068 
1069  tmpconsted[i] = const_cast<const VariableBlock*>(tmpvals[i]);
1070  }
1071 
1072  receiver = tmpconsted;
1073  return true;
1074 }
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetValues() [2/2]

DLLEXPORT vector< VariableBlock * > * NamedVars::GetValues ( const std::string &  name)

Definition at line 1042 of file NamedVars.cpp.

1043 {
1044  GUARD_LOCK();
1045  auto index = Find(guard, name);
1046  // index check //
1047  if(index >= Variables.size()) {
1048  return NULL;
1049  }
1050 
1051  return &Variables[index]->GetValues();
1052 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetVariableCount()

DLLEXPORT size_t NamedVars::GetVariableCount ( ) const

Returns the size of the internal variable vector.

Definition at line 1300 of file NamedVars.cpp.

1301 {
1302  return Variables.size();
1303 }

◆ GetVariableType() [1/3]

DLLEXPORT int NamedVars::GetVariableType ( const std::string &  name) const

Definition at line 1124 of file NamedVars.cpp.

1125 {
1126  GUARD_LOCK();
1127  // call overload //
1128  return GetVariableType(guard, Find(guard, name));
1129 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
DLLEXPORT int GetVariableType(const std::string &name) const
Definition: NamedVars.cpp:1124
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetVariableType() [2/3]

DLLEXPORT int NamedVars::GetVariableType ( Lock guard,
size_t  index 
) const

Definition at line 1131 of file NamedVars.cpp.

1132 {
1133 
1134  return Variables[index]->GetVariableType();
1135 }

◆ GetVariableType() [3/3]

int Leviathan::NamedVars::GetVariableType ( size_t  index) const
inline

Definition at line 309 of file NamedVars.h.

310  {
311  GUARD_LOCK();
312  return GetVariableType(guard, index);
313  }
DLLEXPORT int GetVariableType(const std::string &name) const
Definition: NamedVars.cpp:1124
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetVariableTypeOfAll() [1/3]

DLLEXPORT int NamedVars::GetVariableTypeOfAll ( const std::string &  name) const

Definition at line 1137 of file NamedVars.cpp.

1138 {
1139  GUARD_LOCK();
1140  // call overload //
1141  return GetVariableTypeOfAll(guard, Find(guard, name));
1142 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91
DLLEXPORT int GetVariableTypeOfAll(const std::string &name) const
Definition: NamedVars.cpp:1137

◆ GetVariableTypeOfAll() [2/3]

DLLEXPORT int NamedVars::GetVariableTypeOfAll ( Lock guard,
size_t  index 
) const

Definition at line 1144 of file NamedVars.cpp.

1145 {
1146 
1147  return Variables[index]->GetCommonType();
1148 }

◆ GetVariableTypeOfAll() [3/3]

int Leviathan::NamedVars::GetVariableTypeOfAll ( size_t  index) const
inline

Definition at line 319 of file NamedVars.h.

320  {
321  GUARD_LOCK();
322  return GetVariableTypeOfAll(guard, index);
323  }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91
DLLEXPORT int GetVariableTypeOfAll(const std::string &name) const
Definition: NamedVars.cpp:1137

◆ GetVec()

vector< shared_ptr< NamedVariableList > > * NamedVars::GetVec ( )

Definition at line 1241 of file NamedVars.cpp.

1242 {
1243  return &Variables;
1244 }

◆ IsIndexValid()

DLLEXPORT bool Leviathan::NamedVars::IsIndexValid ( size_t  index) const
inline
Returns
True if index is valid

Definition at line 228 of file NamedVars.h.

229  {
230  return index < Variables.size();
231  }

◆ LoadVarsFromFile()

bool NamedVars::LoadVarsFromFile ( const std::string &  file,
LErrorReporter errorreport 
)

Definition at line 1236 of file NamedVars.cpp.

1237 {
1238  // call datadump loaded with this object's vector //
1239  return FileSystem::LoadDataDump(file, Variables, errorreport);
1240 }
static DLLEXPORT bool LoadDataDump(const std::string &file, std::vector< std::shared_ptr< NamedVariableList >> &vec, LErrorReporter *errorreport)
Definition: FileSystem.cpp:309

◆ operator bool()

Leviathan::NamedVars::operator bool ( ) const
inline

Definition at line 356 of file NamedVars.h.

357  {
358  return !StateIsInvalid;
359  }

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::NamedVars::REFERENCE_COUNTED_PTR_TYPE ( NamedVars  )

◆ Remove() [1/2]

void NamedVars::Remove ( size_t  index)

Definition at line 1210 of file NamedVars.cpp.

1211 {
1212  GUARD_LOCK();
1213 
1214  // smart pointers //
1215  Variables.erase(Variables.begin() + index);
1216 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Remove() [2/2]

DLLEXPORT void NamedVars::Remove ( const std::string &  name)

Definition at line 1218 of file NamedVars.cpp.

1219 {
1220  // call overload //
1221  Remove(Find(name));
1222 }
DLLEXPORT void Remove(size_t index)
Definition: NamedVars.cpp:1210
size_t Find(const std::string &name) const
Definition: NamedVars.h:363

◆ RemoveIfExists()

DLLEXPORT void NamedVars::RemoveIfExists ( const std::string &  name,
Lock guard 
)

Removes a value with the given name if it exists.

Definition at line 1224 of file NamedVars.cpp.

1225 {
1226  // Try to find it //
1227  size_t index = Find(guard, name);
1228 
1229  if(index >= Variables.size())
1230  return;
1231 
1232 
1233  Variables.erase(Variables.begin() + index);
1234 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363

◆ Serialize()

DLLEXPORT std::string Leviathan::NamedVars::Serialize ( const std::string &  lineprefix = "") const

Serializes this object into a string representation.

Parameters
lineprefixAppended before each new line

Definition at line 1110 of file NamedVars.cpp.

1112 {
1113  std::string result;
1114 
1115  for(const auto& variable : Variables) {
1116 
1117  result += lineprefix + variable->ToText(0) + "\n";
1118  }
1119 
1120  return result;
1121 }

◆ SetName() [1/3]

void NamedVars::SetName ( Lock guard,
size_t  index,
const std::string &  name 
)

Definition at line 1165 of file NamedVars.cpp.

1166 {
1167 
1168  Variables[index]->SetName(name);
1169 }

◆ SetName() [2/3]

void Leviathan::NamedVars::SetName ( size_t  index,
const std::string &  name 
)
inline

Definition at line 330 of file NamedVars.h.

331  {
332  GUARD_LOCK();
333  SetName(guard, index, name);
334  }
DLLEXPORT void SetName(Lock &guard, size_t index, const std::string &name)
Definition: NamedVars.cpp:1165
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetName() [3/3]

void NamedVars::SetName ( const std::string &  oldname,
const std::string &  name 
)

Definition at line 1171 of file NamedVars.cpp.

1172 {
1173  GUARD_LOCK();
1174  // call overload //
1175  SetName(guard, Find(guard, oldname), name);
1176 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
DLLEXPORT void SetName(Lock &guard, size_t index, const std::string &name)
Definition: NamedVars.cpp:1165
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetValue() [1/4]

DLLEXPORT bool NamedVars::SetValue ( const std::string &  name,
const VariableBlock value1 
)

Definition at line 895 of file NamedVars.cpp.

896 {
897  GUARD_LOCK();
898  auto index = Find(name);
899 
900  if(index >= Variables.size())
901  return false;
902 
903 
904  Variables[index]->SetValue(value1);
905  return true;
906 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetValue() [2/4]

DLLEXPORT bool NamedVars::SetValue ( const std::string &  name,
VariableBlock value1 
)

Definition at line 908 of file NamedVars.cpp.

909 {
910  GUARD_LOCK();
911  auto index = Find(guard, name);
912 
913  if(index >= Variables.size())
914  return false;
915 
916 
917  Variables[index]->SetValue(value1);
918  return true;
919 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetValue() [3/4]

DLLEXPORT bool NamedVars::SetValue ( const std::string &  name,
const std::vector< VariableBlock *> &  values 
)

Definition at line 921 of file NamedVars.cpp.

923 {
924  GUARD_LOCK();
925  auto index = Find(name);
926 
927  if(index >= Variables.size())
928  return false;
929 
930 
931  Variables[index]->SetValue(values);
932  return true;
933 }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetValue() [4/4]

DLLEXPORT bool NamedVars::SetValue ( NamedVariableList nameandvalues)

Definition at line 935 of file NamedVars.cpp.

936 {
937  GUARD_LOCK();
938  auto index = Find(nameandvalues.Name);
939  // index check //
940  if(index >= Variables.size()) {
941 
942  Variables.push_back(
943  shared_ptr<NamedVariableList>(new NamedVariableList(nameandvalues)));
944  return true;
945  }
946 
947  nameandvalues.Name.clear();
948  // set values with "swap" //
949  NamedVariableList::SwitchValues(*Variables[index].get(), nameandvalues);
950  return true;
951 }
static DLLEXPORT void SwitchValues(NamedVariableList &receiver, NamedVariableList &donator)
Switches values to a new instance.
Definition: NamedVars.cpp:694
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27
size_t Find(const std::string &name) const
Definition: NamedVars.h:363
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetVec()

void NamedVars::SetVec ( std::vector< std::shared_ptr< NamedVariableList >> &  vec)

Definition at line 1245 of file NamedVars.cpp.

1246 {
1247  GUARD_LOCK();
1248  Variables = vec;
1249 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ ShouldAddValueIfNotFoundOrWrongType()

template<class T >
bool Leviathan::NamedVars::ShouldAddValueIfNotFoundOrWrongType ( const std::string &  name)
inline

Definition at line 372 of file NamedVars.h.

373  {
374  size_t index = Find(name);
375 
376  if(index >= Variables.size()) {
377  // Add //
378  return true;
379  }
380  // Check is type correct //
381  if(!Variables[(size_t)index]->CanAllBeCastedToType<T>()) {
382  // Incorrect types in the variables //
383  return true;
384  }
385 
386  // No need to do anything //
387  return false;
388  }
size_t Find(const std::string &name) const
Definition: NamedVars.h:363

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