OpenClonk
C4Value Class Reference

#include <C4Value.h>

Public Member Functions

 C4Value ()
 
 C4Value (const C4Value &nValue)
 
 C4Value (C4Value &&nValue) noexcept
 
 C4Value (bool data)
 
 C4Value (int data)
 
 C4Value (long data)
 
 C4Value (C4PropListStatic *p)
 
 C4Value (C4Def *p)
 
 C4Value (C4Object *pObj)
 
 C4Value (C4Effect *p)
 
 C4Value (C4String *pStr)
 
 C4Value (const char *s)
 
 C4Value (const StdStrBuf &s)
 
 C4Value (C4ValueArray *pArray)
 
 C4Value (C4AulFunc *pFn)
 
 C4Value (C4PropList *p)
 
 C4Value (C4ObjectPtr p)
 
template<typename T >
 C4Value (Nillable< T > v)
 
C4Valueoperator= (const C4Value &nValue)
 
 ~C4Value ()
 
int32_t getInt () const
 
bool getBool () const
 
C4ObjectgetObj () const
 
C4DefgetDef () const
 
C4PropListgetPropList () const
 
C4StringgetStr () const
 
C4ValueArraygetArray () const
 
C4AulFuncgetFunction () const
 
int32_t _getInt () const
 
bool _getBool () const
 
C4Object_getObj () const
 
C4Def_getDef () const
 
C4String_getStr () const
 
C4ValueArray_getArray () const
 
C4AulFunc_getFunction () const
 
C4PropList_getPropList () const
 
bool operator! () const
 
 operator const void * () const
 
void Set (const C4Value &nValue)
 
void SetInt (int32_t i)
 
void SetBool (bool b)
 
void SetString (C4String *Str)
 
void SetArray (C4ValueArray *Array)
 
void SetFunction (C4AulFunc *Fn)
 
void SetPropList (C4PropList *PropList)
 
void SetObjectEnum (int i)
 
void Set0 ()
 
bool operator== (const C4Value &Value2) const
 
bool operator!= (const C4Value &Value2) const
 
bool IsIdenticalTo (const C4Value &cmp) const
 
C4Valueoperator+= (int32_t by)
 
C4Valueoperator++ ()
 
C4Value operator++ (int)
 
C4Valueoperator-- ()
 
C4Value operator-- (int)
 
C4V_Data GetData () const
 
C4V_Type GetType () const
 
C4V_Type GetTypeEx () const
 
const char * GetTypeName () const
 
void Denumerate (C4ValueNumbers *)
 
StdStrBuf GetDataString (int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
 
StdStrBuf ToJSON (int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
 
ALWAYS_INLINE bool CheckParConversion (C4V_Type vtToType) const
 
ALWAYS_INLINE bool CheckConversion (C4V_Type vtToType) const
 
void CompileFunc (StdCompiler *pComp, C4ValueNumbers *)
 

Static Public Member Functions

static bool WarnAboutConversion (C4V_Type Type, C4V_Type vtToType)
 
static constexpr bool IsNullableType (C4V_Type Type)
 

Friends

class C4PropList
 

Detailed Description

Definition at line 72 of file C4Value.h.

Constructor & Destructor Documentation

◆ C4Value() [1/18]

C4Value::C4Value ( )
inline

Definition at line 76 of file C4Value.h.

76 { Data = nullptr; }

◆ C4Value() [2/18]

C4Value::C4Value ( const C4Value nValue)
inline

Definition at line 78 of file C4Value.h.

78  : Data(nValue.Data), Type(nValue.Type)
79  { AddDataRef(); }

◆ C4Value() [3/18]

ALWAYS_INLINE C4Value::C4Value ( C4Value &&  nValue)
noexcept

Definition at line 345 of file C4Value.h.

345  :
346  Data(nValue.Data), Type(nValue.Type)
347 {
348  if (Type == C4V_PropList)
349  {
350  Data.PropList->AddRef(this);
351  Data.PropList->DelRef(&nValue);
352  }
353  nValue.Type = C4V_Nil; nValue.Data = nullptr;
354 }
@ C4V_PropList
Definition: C4Value.h:28
@ C4V_Nil
Definition: C4Value.h:25
C4PropList * PropList
Definition: C4Value.h:54

References C4V_Nil, C4V_PropList, and C4V_Data::PropList.

◆ C4Value() [4/18]

C4Value::C4Value ( bool  data)
inlineexplicit

Definition at line 82 of file C4Value.h.

82  : Type(C4V_Bool)
83  { Data.Int = data; }
@ C4V_Bool
Definition: C4Value.h:27
intptr_t Int
Definition: C4Value.h:52

References C4V_Data::Int.

◆ C4Value() [5/18]

C4Value::C4Value ( int  data)
inlineexplicit

Definition at line 84 of file C4Value.h.

84  : Type(C4V_Int)
85  { Data.Int = data; }
@ C4V_Int
Definition: C4Value.h:26

References C4V_Data::Int.

◆ C4Value() [6/18]

C4Value::C4Value ( long  data)
inlineexplicit

Definition at line 86 of file C4Value.h.

86  : Type(C4V_Int)
87  { Data.Int = int32_t(data); }

References C4V_Data::Int.

◆ C4Value() [7/18]

C4Value::C4Value ( C4PropListStatic p)
explicit

Definition at line 63 of file C4Value.cpp.

63 : C4Value(static_cast<C4PropList *>(p)) {}
C4Value()
Definition: C4Value.h:76

◆ C4Value() [8/18]

C4Value::C4Value ( C4Def p)
explicit

Definition at line 64 of file C4Value.cpp.

64 : C4Value(static_cast<C4PropList *>(p)) {}

◆ C4Value() [9/18]

C4Value::C4Value ( C4Object pObj)
explicit

Definition at line 65 of file C4Value.cpp.

65 : C4Value(static_cast<C4PropList *>(p)) {}

◆ C4Value() [10/18]

C4Value::C4Value ( C4Effect p)
explicit

Definition at line 66 of file C4Value.cpp.

66 : C4Value(static_cast<C4PropList *>(p)) {}

◆ C4Value() [11/18]

C4Value::C4Value ( C4String pStr)
inlineexplicit

Definition at line 92 of file C4Value.h.

92  : Type(pStr ? C4V_String : C4V_Nil)
93  { Data.Str = pStr; AddDataRef(); }
@ C4V_String
Definition: C4Value.h:29
C4String * Str
Definition: C4Value.h:55

References C4V_Data::Str.

◆ C4Value() [12/18]

C4Value::C4Value ( const char *  s)
inlineexplicit

Definition at line 94 of file C4Value.h.

94  : Type(s ? C4V_String : C4V_Nil)
95  { Data.Str = s ? ::Strings.RegString(s) : nullptr; AddDataRef(); }
#define s
C4StringTable Strings
Definition: C4Globals.cpp:42
C4String * RegString(StdStrBuf String)

References C4StringTable::RegString(), s, C4V_Data::Str, and Strings.

Here is the call graph for this function:

◆ C4Value() [13/18]

C4Value::C4Value ( const StdStrBuf s)
inlineexplicit

Definition at line 96 of file C4Value.h.

96  : Type(s.isNull() ? C4V_Nil : C4V_String)
97  { Data.Str = s.isNull() ? nullptr: ::Strings.RegString(s); AddDataRef(); }

References C4StringTable::RegString(), s, C4V_Data::Str, and Strings.

Here is the call graph for this function:

◆ C4Value() [14/18]

C4Value::C4Value ( C4ValueArray pArray)
inlineexplicit

Definition at line 98 of file C4Value.h.

98  : Type(pArray ? C4V_Array : C4V_Nil)
99  { Data.Array = pArray; AddDataRef(); }
@ C4V_Array
Definition: C4Value.h:30
C4ValueArray * Array
Definition: C4Value.h:56

References C4V_Data::Array.

◆ C4Value() [15/18]

C4Value::C4Value ( C4AulFunc pFn)
inlineexplicit

Definition at line 100 of file C4Value.h.

100  : Type(pFn ? C4V_Function : C4V_Nil)
101  { Data.Fn = pFn; AddDataRef(); }
@ C4V_Function
Definition: C4Value.h:31
C4AulFunc * Fn
Definition: C4Value.h:57

References C4V_Data::Fn.

◆ C4Value() [16/18]

C4Value::C4Value ( C4PropList p)
inlineexplicit

Definition at line 102 of file C4Value.h.

102  : Type(p ? C4V_PropList : C4V_Nil)
103  { Data.PropList = p; AddDataRef(); }

References C4V_Data::PropList.

◆ C4Value() [17/18]

C4Value::C4Value ( C4ObjectPtr  p)
inline

Definition at line 104 of file C4Value.h.

104 : C4Value(p.operator C4Object *()) {}

◆ C4Value() [18/18]

template<typename T >
C4Value::C4Value ( Nillable< T >  v)
inline

Definition at line 105 of file C4Value.h.

105 : C4Value(v.IsNil() ? C4Value() : C4Value(v.operator T())) {}
bool IsNil() const
Definition: C4AulDefFunc.h:58

◆ ~C4Value()

C4Value::~C4Value ( )
inline

Definition at line 109 of file C4Value.h.

109 { DelDataRef(Data, Type); }

Member Function Documentation

◆ _getArray()

C4ValueArray* C4Value::_getArray ( ) const
inline

Definition at line 127 of file C4Value.h.

127 { return Data.Array; }

References C4V_Data::Array.

Referenced by C4ValueConv< C4ValueArray * >::_FromC4V(), C4ValueNumbers::CompileValue(), C4ValueArraySortArrayElementcomp::operator()(), and C4ValueArray::SetSlice().

Here is the caller graph for this function:

◆ _getBool()

bool C4Value::_getBool ( ) const
inline

Definition at line 123 of file C4Value.h.

123 { return !! Data.Int; }

References C4V_Data::Int.

Referenced by C4ValueConv< bool >::_FromC4V().

Here is the caller graph for this function:

◆ _getDef()

C4Def * C4Value::_getDef ( ) const

Definition at line 83 of file C4Value.cpp.

84 {
85  return Data.PropList ? Data.PropList->GetDef() : nullptr;
86 }
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:654

References C4PropList::GetDef(), and C4V_Data::PropList.

Referenced by C4ValueConv< C4Def * >::_FromC4V().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getFunction()

C4AulFunc* C4Value::_getFunction ( ) const
inline

Definition at line 128 of file C4Value.h.

128 { return Data.Fn; }

References C4V_Data::Fn.

Referenced by C4ValueConv< C4AulFunc * >::_FromC4V().

Here is the caller graph for this function:

◆ _getInt()

◆ _getObj()

C4Object * C4Value::_getObj ( ) const

Definition at line 73 of file C4Value.cpp.

74 {
75  return Data.PropList ? Data.PropList->GetObject() : nullptr;
76 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:636

References C4PropList::GetObject(), and C4V_Data::PropList.

Referenced by C4ValueConv< C4Object * >::_FromC4V(), C4SortObjectSTL::operator()(), and C4SortObjectByValue::PrepareCache().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getPropList()

◆ _getStr()

C4String* C4Value::_getStr ( ) const
inline

Definition at line 126 of file C4Value.h.

126 { return Data.Str; }

References C4V_Data::Str.

Referenced by C4ValueConv< C4String * >::_FromC4V(), C4Game::GetTranslatedString(), C4ValueArraySortStringscomp::operator()(), and C4ValueArraySortcomp::operator()().

Here is the caller graph for this function:

◆ CheckConversion()

ALWAYS_INLINE bool C4Value::CheckConversion ( C4V_Type  vtToType) const
inline

Definition at line 189 of file C4Value.h.

190  {
191  switch (vtToType)
192  {
193  case C4V_Nil: return Type == C4V_Nil;
194  case C4V_Int: return Type == C4V_Nil || Type == C4V_Int || Type == C4V_Bool;
195  case C4V_Bool: return true;
196  case C4V_PropList: return Type == C4V_PropList;
197  case C4V_String: return Type == C4V_String;
198  case C4V_Array: return Type == C4V_Array;
199  case C4V_Function: return Type == C4V_Function;
200  case C4V_Any: return true;
201  case C4V_Object: return Type == C4V_PropList && FnCnvObject();
202  case C4V_Def: return Type == C4V_PropList && FnCnvDef();
203  case C4V_Effect: return Type == C4V_PropList && FnCnvEffect();
204  default: assert(!"C4Value::CheckConversion: impossible conversion target"); return false;
205  }
206  }
@ C4V_Object
Definition: C4Value.h:38
@ C4V_Any
Definition: C4Value.h:37
@ C4V_Def
Definition: C4Value.h:39
@ C4V_Effect
Definition: C4Value.h:40

References C4V_Any, C4V_Array, C4V_Bool, C4V_Def, C4V_Effect, C4V_Function, C4V_Int, C4V_Nil, C4V_Object, C4V_PropList, and C4V_String.

Referenced by getArray(), getBool(), getDef(), getFunction(), getInt(), getObj(), getPropList(), getStr(), C4ValueArraySortcomp::operator()(), C4Command::Set(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the caller graph for this function:

◆ CheckParConversion()

ALWAYS_INLINE bool C4Value::CheckParConversion ( C4V_Type  vtToType) const
inline

Definition at line 171 of file C4Value.h.

172  {
173  switch (vtToType)
174  {
175  case C4V_Nil: return Type == C4V_Nil || (Type == C4V_Int && !*this);
176  case C4V_Int: return Type == C4V_Int || Type == C4V_Nil || Type == C4V_Bool;
177  case C4V_Bool: return true;
178  case C4V_PropList: return Type == C4V_PropList || Type == C4V_Nil || (Type == C4V_Int && !*this);
179  case C4V_String: return Type == C4V_String || Type == C4V_Nil || (Type == C4V_Int && !*this);
180  case C4V_Array: return Type == C4V_Array || Type == C4V_Nil || (Type == C4V_Int && !*this);
181  case C4V_Function: return Type == C4V_Function || Type == C4V_Nil || (Type == C4V_Int && !*this);
182  case C4V_Any: return true;
183  case C4V_Object: return (Type == C4V_PropList && FnCnvObject()) || Type == C4V_Nil || (Type == C4V_Int && !*this);
184  case C4V_Def: return (Type == C4V_PropList && FnCnvDef()) || Type == C4V_Nil || (Type == C4V_Int && !*this);
185  case C4V_Effect: return (Type == C4V_PropList && FnCnvEffect()) || Type == C4V_Nil || (Type == C4V_Int && !*this);
186  default: assert(!"C4Value::CheckParConversion: impossible conversion target"); return false;
187  }
188  }

References C4V_Any, C4V_Array, C4V_Bool, C4V_Def, C4V_Effect, C4V_Function, C4V_Int, C4V_Nil, C4V_Object, C4V_PropList, and C4V_String.

◆ CompileFunc()

void C4Value::CompileFunc ( StdCompiler pComp,
C4ValueNumbers numbers 
)

Definition at line 300 of file C4Value.cpp.

301 {
302  // Type
303  bool deserializing = pComp->isDeserializer();
304  char cC4VID;
305  if (!deserializing)
306  {
307  assert(Type != C4V_Nil || !Data);
308  switch (Type)
309  {
310  case C4V_Nil:
311  cC4VID = 'n'; break;
312  case C4V_Int:
313  cC4VID = 'i'; break;
314  case C4V_Bool:
315  cC4VID = 'b'; break;
316  case C4V_PropList:
317  if (getPropList()->IsStatic())
318  cC4VID = 'D';
319  else if (getPropList()->IsNumbered())
320  cC4VID = 'O';
321  else
322  cC4VID = 'E';
323  break;
324  case C4V_Array:
325  cC4VID = 'E'; break;
326  case C4V_Function:
327  cC4VID = 'D'; break;
328  case C4V_String:
329  cC4VID = 's'; break;
330  default:
331  assert(false);
332  }
333  }
334  pComp->Character(cC4VID);
335  // Data
336  int32_t iTmp;
337  switch (cC4VID)
338  {
339  case 'i':
340  iTmp = Data.Int;
341  pComp->Value(iTmp);
342  SetInt(iTmp);
343  break;
344 
345  case 'b':
346  iTmp = Data.Int;
347  pComp->Value(iTmp);
348  SetBool(!!iTmp);
349  break;
350 
351  case 'E':
352  if (!deserializing)
353  iTmp = numbers->GetNumberForValue(this);
354  pComp->Value(iTmp);
355  if (deserializing)
356  {
357  Data.Int = iTmp; // must be denumerated later
358  Type = C4V_Enum;
359  }
360  break;
361 
362  case 'O':
363  if (!deserializing)
365  pComp->Value(iTmp);
366  if (deserializing)
367  {
368  Data.Int = iTmp; // must be denumerated later
369  Type = C4V_C4ObjectEnum;
370  }
371  break;
372 
373  case 'D':
374  {
375  if (!pComp->isDeserializer())
376  {
377  const C4PropList * p = getPropList();
378  if (getFunction())
379  {
380  p = Data.Fn->Parent;
381  assert(p);
382  assert(p->GetFunc(Data.Fn->GetName()) == Data.Fn);
383  assert(p->IsStatic());
384  }
385  p->IsStatic()->RefCompileFunc(pComp, numbers);
386  if (getFunction())
387  {
389  StdStrBuf s; s.Ref(Data.Fn->GetName());
391  }
392  }
393  else
394  {
395  StdStrBuf s;
396  C4Value temp;
398  if (!::ScriptEngine.GetGlobalConstant(s.getData(), &temp))
399  pComp->excCorrupt("Cannot find global constant %s", s.getData());
400  while(pComp->Separator(StdCompiler::SEP_PART))
401  {
402  C4PropList * p = temp.getPropList();
403  if (!p)
404  pComp->excCorrupt("static proplist %s is not a proplist anymore", s.getData());
406  C4String * c4s = ::Strings.FindString(s.getData());
407  if (!c4s || !p->GetPropertyByS(c4s, &temp))
408  pComp->excCorrupt("Cannot find property %s in %s", s.getData(), GetDataString().getData());
409  }
410  Set(temp);
411  }
412  break;
413  }
414 
415  case 's':
416  {
417  StdStrBuf s;
418  if (!deserializing)
419  s = Data.Str->GetData();
420  pComp->Value(s);
421  if (deserializing)
423  break;
424  }
425 
426  // FIXME: remove these three once Game.txt were re-saved with current version
427  case 'c':
428  if (deserializing)
430  break;
431 
432  case 't':
433  if (deserializing)
435  break;
436 
437  case 'g':
438  if (deserializing)
440  break;
441 
442  case 'n':
443  case 'A': // compat with OC 5.1
444  if (deserializing)
445  Set0();
446  // doesn't have a value, so nothing to store
447  break;
448 
449  default:
450  // shouldn't happen
451  pComp->excCorrupt("unknown C4Value type tag '%c'", cC4VID);
452  break;
453  }
454 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4GameScriptHost GameScript
@ C4V_C4ObjectEnum
Definition: C4Value.h:34
@ C4V_Enum
Definition: C4Value.h:33
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
const char * GetName() const
Definition: C4AulFunc.h:56
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
bool GetGlobalConstant(const char *szName, C4Value *pTargetValue)
Definition: C4Aul.cpp:133
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4Value ScenPrototype
Definition: C4ScriptHost.h:165
C4Value ScenPropList
Definition: C4ScriptHost.h:164
C4AulFunc * GetFunc(C4PropertyName k) const
Definition: C4PropList.h:109
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:89
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:726
virtual C4PropListNumbered * GetPropListNumbered()
Definition: C4PropList.cpp:672
void RefCompileFunc(StdCompiler *pComp, C4ValueNumbers *numbers) const
Definition: C4PropList.cpp:216
StdStrBuf GetData() const
Definition: C4StringTable.h:50
C4String * FindString(const char *strString) const
void SetPropList(C4PropList *PropList)
Definition: C4Value.h:141
StdStrBuf GetDataString(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
Definition: C4Value.cpp:131
void SetBool(bool b)
Definition: C4Value.h:137
void Set0()
Definition: C4Value.h:332
void SetInt(int32_t i)
Definition: C4Value.h:136
void Set(const C4Value &nValue)
Definition: C4Value.h:134
C4AulFunc * getFunction() const
Definition: C4Value.h:119
C4PropList * getPropList() const
Definition: C4Value.h:116
void SetString(C4String *Str)
Definition: C4Value.h:138
uint32_t GetNumberForValue(C4Value *v)
Definition: C4Value.cpp:287
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
virtual void Character(char &rChar)=0
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References C4V_Array, C4V_Bool, C4V_C4ObjectEnum, C4V_Enum, C4V_Function, C4V_Int, C4V_Nil, C4V_PropList, C4V_String, StdCompiler::Character(), StdCompiler::excCorrupt(), C4StringTable::FindString(), C4V_Data::Fn, GameScript, C4String::GetData(), GetDataString(), C4PropList::GetFunc(), getFunction(), C4AulScriptEngine::GetGlobalConstant(), C4AulFunc::GetName(), C4ValueNumbers::GetNumberForValue(), C4PropList::GetPropertyByS(), C4AulScriptEngine::GetPropList(), getPropList(), C4PropList::GetPropListNumbered(), C4V_Data::Int, StdCompiler::isDeserializer(), C4PropList::IsStatic(), mkParAdapt(), C4PropListNumbered::Number, C4AulFunc::Parent, StdCompiler::RCT_ID, C4PropListStatic::RefCompileFunc(), C4StringTable::RegString(), s, C4GameScriptHost::ScenPropList, C4GameScriptHost::ScenPrototype, ScriptEngine, StdCompiler::SEP_PART, StdCompiler::Separator(), Set(), Set0(), SetBool(), SetInt(), SetPropList(), SetString(), C4V_Data::Str, Strings, and StdCompiler::Value().

Here is the call graph for this function:

◆ Denumerate()

void C4Value::Denumerate ( C4ValueNumbers numbers)

Definition at line 251 of file C4Value.cpp.

252 {
253  switch (Type)
254  {
255  case C4V_Enum:
256  Set(numbers->GetValue(Data.Int)); break;
257  case C4V_Array:
258  Data.Array->Denumerate(numbers); break;
259  case C4V_PropList:
260  // objects and effects are denumerated via the main object list
261  if (!Data.PropList->IsNumbered() && !Data.PropList->IsStatic())
262  Data.PropList->Denumerate(numbers);
263  break;
264  case C4V_C4ObjectEnum:
265  {
267  if (pObj)
268  // set
269  SetPropList(pObj);
270  else
271  {
272  // object: invalid value - set to zero
273  LogF("ERROR: Object number %d is missing.", int(Data.Int));
274  Set0();
275  }
276  }
277  default: break;
278  }
279 }
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
virtual bool IsNumbered() const
Definition: C4PropList.h:92
virtual void Denumerate(C4ValueNumbers *)
Definition: C4PropList.cpp:321
static C4PropList * GetByNumber(int32_t iNumber)
Definition: C4PropList.cpp:51
void Denumerate(C4ValueNumbers *)
const C4Value & GetValue(uint32_t)
Definition: C4Value.cpp:243

References C4V_Data::Array, C4V_Array, C4V_C4ObjectEnum, C4V_Enum, C4V_PropList, C4PropList::Denumerate(), C4ValueArray::Denumerate(), C4PropListNumbered::GetByNumber(), C4ValueNumbers::GetValue(), C4V_Data::Int, C4PropList::IsNumbered(), C4PropList::IsStatic(), LogF(), C4V_Data::PropList, Set(), Set0(), and SetPropList().

Referenced by C4Player::CompileFunc(), C4Command::Denumerate(), C4PropList::Denumerate(), C4Effect::Denumerate(), and C4GameScriptHost::Denumerate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getArray()

C4ValueArray* C4Value::getArray ( ) const
inline

Definition at line 118 of file C4Value.h.

118 { return CheckConversion(C4V_Array) ? Data.Array : nullptr; }
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189

References C4V_Data::Array, C4V_Array, and CheckConversion().

Referenced by C4MapScriptAlgoModifier::C4MapScriptAlgoModifier(), C4MapScriptAlgoPolygon::C4MapScriptAlgoPolygon(), C4ValueToMatrix(), C4FindObject::CreateByValue(), C4SortObject::CreateByValue(), C4Object::DrawLine(), C4Object::GetParallaxity(), C4PropList::GetPropertyArray(), C4MapScriptAlgo::GetXYProps(), C4ScriptGuiWindowAction::Init(), C4MapScriptMatTexMask::Init(), C4Object::IsVisible(), C4ParticleValueProvider::Set(), C4ScriptGuiWindowProperty::Set(), C4ParticleProperties::SetCollisionFunc(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBool()

bool C4Value::getBool ( ) const
inline

Definition at line 113 of file C4Value.h.

113 { return CheckConversion(C4V_Bool) ? !! Data : false; }

References C4V_Bool, and CheckConversion().

Referenced by AlgoScript(), C4MapScriptAlgoRndChecker::C4MapScriptAlgoRndChecker(), C4FindObjectFunc::Check(), C4FindObjectProperty::Check(), C4Command::Dig(), C4PropList::GetPropertyBool(), C4Object::IsVisible(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetData()

C4V_Data C4Value::GetData ( ) const
inline

Definition at line 160 of file C4Value.h.

160 { return Data; }

Referenced by ComparisonImpl(), C4ValueNumbers::GetNumberForValue(), IsIdenticalTo(), operator const void *(), and operator!().

Here is the caller graph for this function:

◆ GetDataString()

StdStrBuf C4Value::GetDataString ( int  depth = 10,
const class C4PropListStatic ignore_reference_parent = nullptr 
) const

Definition at line 131 of file C4Value.cpp.

132 {
133  // ouput by type info
134  switch (GetType())
135  {
136  case C4V_Int:
137  return FormatString("%ld", static_cast<long>(Data.Int));
138  case C4V_Bool:
139  return StdStrBuf(Data ? "true" : "false");
140  case C4V_PropList:
141  {
142  if (Data.PropList == ScriptEngine.GetPropList())
143  return StdStrBuf("Global");
144  C4Object * Obj = Data.PropList->GetObject();
145  if (Obj == Data.PropList)
146  return FormatString("Object(%d)", Obj->Number);
147  const C4PropListStatic * Def = Data.PropList->IsStatic();
148  if (Def)
149  if (!ignore_reference_parent || Def->GetParent() != ignore_reference_parent)
150  return Def->GetDataString();
151  C4Effect * fx = Data.PropList->GetEffect();
152  StdStrBuf DataString;
153  DataString = (fx ? "effect {" : "{");
154  Data.PropList->AppendDataString(&DataString, ", ", depth, Def && ignore_reference_parent);
155  DataString.AppendChar('}');
156  return DataString;
157  }
158  case C4V_String:
159  return (Data.Str && Data.Str->GetCStr()) ? FormatString(R"("%s")", Data.Str->GetCStr()) : StdStrBuf("(nullstring)");
160  case C4V_Array:
161  {
162  if (depth <= 0 && Data.Array->GetSize())
163  {
164  return StdStrBuf("[...]");
165  }
166  StdStrBuf DataString;
167  DataString = "[";
168  for (int32_t i = 0; i < Data.Array->GetSize(); i++)
169  {
170  if (i) DataString.Append(", ");
171  DataString.Append(std::move(Data.Array->GetItem(i).GetDataString(depth - 1)));
172  }
173  DataString.AppendChar(']');
174  return DataString;
175  }
176  case C4V_Function:
177  return Data.Fn->GetFullName();
178  case C4V_Nil:
179  return StdStrBuf("nil");
180  default:
181  return StdStrBuf("-unknown type- ");
182  }
183 }
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
virtual StdStrBuf GetFullName() const
Definition: C4AulFunc.cpp:38
virtual C4Effect * GetEffect()
Definition: C4PropList.cpp:678
void AppendDataString(StdStrBuf *out, const char *delim, int depth=3, bool ignore_reference_parent=false) const
Definition: C4PropList.cpp:487
StdStrBuf GetDataString() const
Definition: C4PropList.cpp:229
const C4PropListStatic * GetParent() const
Definition: C4PropList.h:275
const char * GetCStr() const
Definition: C4StringTable.h:49
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
int32_t GetSize() const
Definition: C4ValueArray.h:36
C4V_Type GetType() const
Definition: C4Value.h:161
void AppendChar(char cChar)
Definition: StdBuf.h:588
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

References C4V_Bool, C4V_Int, C4V_PropList, FormatString(), C4AulScriptEngine::GetPropList(), GetType(), C4V_Data::Int, C4V_Data::PropList, and ScriptEngine.

Referenced by C4PropList::AppendDataString(), CompileFunc(), C4Object::Draw(), C4Game::GetTranslatedString(), C4AulScriptContext::ReturnDump(), and C4PropertyPath::SetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDef()

C4Def * C4Value::getDef ( ) const

Definition at line 78 of file C4Value.cpp.

79 {
80  return CheckConversion(C4V_Def) ? Data.PropList->GetDef() : nullptr;
81 }

References C4V_Def, CheckConversion(), C4PropList::GetDef(), and C4V_Data::PropList.

Referenced by C4ValueConv< C4ID >::_FromC4V(), C4Command::Acquire(), C4Command::Activate(), C4Command::Fail(), C4Command::Get(), C4Object::GetDragImage(), C4Command::Put(), and C4ScriptGuiWindowProperty::Set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFunction()

C4AulFunc* C4Value::getFunction ( ) const
inline

Definition at line 119 of file C4Value.h.

119 { return CheckConversion(C4V_Function) ? Data.Fn : nullptr; }

References C4V_Function, CheckConversion(), and C4V_Data::Fn.

Referenced by CompileFunc(), C4ScriptHost::CopyPropList(), C4EditCursor::DoContextMenu(), C4PropList::EnumerateOwnFuncs(), C4PropList::GetFunc(), and C4ScriptHost::UnlinkOwnedFunctions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInt()

◆ getObj()

C4Object * C4Value::getObj ( ) const

Definition at line 68 of file C4Value.cpp.

69 {
70  return CheckConversion(C4V_Object) ? Data.PropList->GetObject() : nullptr;
71 }

References C4V_Object, CheckConversion(), C4PropList::GetObject(), and C4V_Data::PropList.

Referenced by C4FindObjectInArray::Check(), C4EditCursor::Draw(), C4Object::GetDragImage(), C4ScriptGuiWindowAction::Init(), C4EditCursorSelection::ObjectCount(), C4Landscape::P::PostFreeShape(), and C4Object::PutAwayUnusedObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPropList()

◆ getStr()

C4String* C4Value::getStr ( ) const
inline

Definition at line 117 of file C4Value.h.

117 { return CheckConversion(C4V_String) ? Data.Str : nullptr; }

References C4V_String, CheckConversion(), and C4V_Data::Str.

Referenced by C4FindObjectProcedure::Check(), C4ScriptGuiWindow::CreateFromPropList(), C4EditCursor::DoContextMenu(), C4Object::GetInfoString(), C4PropList::GetPropertyP(), C4PropList::GetPropertyStr(), C4Game::GetTranslatedString(), C4ScriptGuiWindowAction::Init(), C4MapScriptMatTexMask::Init(), C4ValueArraySortStringscomp::operator()(), C4ValueArraySortcomp::operator()(), C4ScriptGuiWindowProperty::Set(), C4Effect::SetPropertyByS(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetType()

C4V_Type C4Value::GetType ( ) const
inline

◆ GetTypeEx()

C4V_Type C4Value::GetTypeEx ( ) const

Definition at line 623 of file C4Value.cpp.

624 {
625  // Return type including types derived from prop list types (such as C4V_Def)
626  if (Type == C4V_PropList)
627  {
628  if (FnCnvEffect()) return C4V_Effect;
629  if (FnCnvObject()) return C4V_Object;
630  if (FnCnvDef()) return C4V_Def;
631  }
632  return Type;
633 }

References C4V_Def, C4V_Effect, C4V_Object, and C4V_PropList.

◆ GetTypeName()

const char* C4Value::GetTypeName ( ) const
inline

Definition at line 164 of file C4Value.h.

164 { return GetC4VName(GetType()); }
const char * GetC4VName(const C4V_Type Type)
Definition: C4Value.cpp:32

References GetC4VName(), and GetType().

Referenced by C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsIdenticalTo()

bool C4Value::IsIdenticalTo ( const C4Value cmp) const
inline

Definition at line 149 of file C4Value.h.

149 { return GetType()==cmp.GetType() && GetData()==cmp.GetData(); }
C4V_Data GetData() const
Definition: C4Value.h:160

References GetData(), and GetType().

Referenced by C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsNullableType()

static constexpr bool C4Value::IsNullableType ( C4V_Type  Type)
inlinestaticconstexpr

Definition at line 212 of file C4Value.h.

213  { return Type == C4V_Int || Type == C4V_Bool; }

References C4V_Bool, and C4V_Int.

Referenced by Nillable< T >::operator=().

Here is the caller graph for this function:

◆ operator const void *()

C4Value::operator const void * ( ) const
inline

Definition at line 132 of file C4Value.h.

132 { return GetData() ? this : nullptr; } // To allow use of C4Value in conditions

References GetData().

Here is the call graph for this function:

◆ operator!()

bool C4Value::operator! ( ) const
inline

Definition at line 131 of file C4Value.h.

131 { return !GetData(); }

References GetData().

Here is the call graph for this function:

◆ operator!=()

bool C4Value::operator!= ( const C4Value Value2) const

Definition at line 618 of file C4Value.cpp.

619 {
620  return !(*this == Value2);
621 }

◆ operator++() [1/2]

C4Value& C4Value::operator++ ( )
inline

Definition at line 154 of file C4Value.h.

154 { Data.Int++; Type=C4V_Int; return *this; }

References C4V_Int, and C4V_Data::Int.

◆ operator++() [2/2]

C4Value C4Value::operator++ ( int  )
inline

Definition at line 155 of file C4Value.h.

155 { C4Value old = *this; ++(*this); return old; }

◆ operator+=()

C4Value& C4Value::operator+= ( int32_t  by)
inline

Definition at line 153 of file C4Value.h.

153 { Data.Int += by; Type=C4V_Int; return *this; }

References C4V_Int, and C4V_Data::Int.

◆ operator--() [1/2]

C4Value& C4Value::operator-- ( )
inline

Definition at line 156 of file C4Value.h.

156 { Data.Int--; Type=C4V_Int; return *this; }

References C4V_Int, and C4V_Data::Int.

◆ operator--() [2/2]

C4Value C4Value::operator-- ( int  )
inline

Definition at line 157 of file C4Value.h.

157 { C4Value old = *this; --(*this); return old; }

◆ operator=()

C4Value& C4Value::operator= ( const C4Value nValue)
inline

Definition at line 107 of file C4Value.h.

107 { Set(nValue); return *this; }

References Set().

Here is the call graph for this function:

◆ operator==()

bool C4Value::operator== ( const C4Value Value2) const

Definition at line 570 of file C4Value.cpp.

571 {
572  // recursion guard using a linked list of Seen structures on the stack
573  // NOT thread-safe
574  struct Seen
575  {
576  Seen *prev;
577  const C4Value *left;
578  const C4Value *right;
579  inline Seen(Seen *prev, const C4Value *left, const C4Value *right):
580  prev(prev), left(left), right(right) {}
581  inline bool operator == (const Seen& other)
582  {
583  return left == other.left && right == other.right;
584  }
585  inline bool recursion(Seen *new_top)
586  {
587  for (Seen *s = this; s; s = s->prev)
588  if (*s == *new_top)
589  return true;
590  return false;
591  }
592  inline Seen *first()
593  {
594  Seen *s = this;
595  while (s->prev) s = s->prev;
596  return s;
597  }
598  };
599  static Seen *top = nullptr;
600  Seen here(top, this, &Value2);
601 
602  bool recursion = top && top->recursion(&here);
603  if (recursion)
604  {
605  Seen *first = top->first();
606  // GetDataString is fine for circular values
607  LogF("Caught infinite recursion comparing %s and %s",
608  first->left->GetDataString().getData(),
609  first->right->GetDataString().getData());
610  return false;
611  }
612  top = &here;
613  bool result = ComparisonImpl(*this, Value2);
614  top = here.prev;
615  return result;
616 }
bool ComparisonImpl(const C4Value &Value1, const C4Value &Value2)
Definition: C4Value.cpp:540
bool operator==(const C4Value &Value2) const
Definition: C4Value.cpp:570

References ComparisonImpl(), C4ScriptGuiWindowPropertyName::left, LogF(), C4ScriptGuiWindowPropertyName::right, s, and C4ScriptGuiWindowPropertyName::top.

Here is the call graph for this function:

◆ Set()

void C4Value::Set ( const C4Value nValue)
inline

Definition at line 134 of file C4Value.h.

134 { Set(nValue.Data, nValue.Type); }

References Set().

Referenced by CompileFunc(), Denumerate(), operator=(), C4ParticleProperties::Set(), Set(), SetArray(), SetBool(), SetFunction(), SetInt(), SetObjectEnum(), SetPropList(), and SetString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set0()

ALWAYS_INLINE void C4Value::Set0 ( )

Definition at line 332 of file C4Value.h.

333 {
334  C4V_Data oData = Data;
335  C4V_Type oType = Type;
336 
337  // change
338  Data = nullptr;
339  Type = C4V_Nil;
340 
341  // clean up (save even if Data was 0 before)
342  DelDataRef(oData, oType);
343 }
C4V_Type
Definition: C4Value.h:24

References C4V_Nil.

Referenced by C4Effect::C4Effect(), C4Player::C4Player(), C4PropList::Clear(), C4GameScriptHost::Clear(), C4Effect::ClearPointers(), C4Effect::CompileFunc(), CompileFunc(), C4Command::Default(), Denumerate(), C4GameMessage::Init(), C4ValueArraySortPropertycomp::operator()(), C4SoundModifier::Release(), C4PropList::RemoveCyclicPrototypes(), C4PropList::ResetProperty(), C4Game::SetGlobalSoundModifier(), C4Player::SetSoundModifier(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the caller graph for this function:

◆ SetArray()

void C4Value::SetArray ( C4ValueArray Array)
inline

Definition at line 139 of file C4Value.h.

139 { C4V_Data d; d.Array = Array; Set(d, C4V_Array); }

References C4V_Data::Array, C4V_Array, and Set().

Referenced by C4ValueNumbers::CompileValue(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBool()

void C4Value::SetBool ( bool  b)
inline

Definition at line 137 of file C4Value.h.

137 { C4V_Data d; d.Int = b; Set(d, C4V_Bool); }
#define b

References b, C4V_Bool, C4V_Data::Int, and Set().

Referenced by CompileFunc(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFunction()

void C4Value::SetFunction ( C4AulFunc Fn)
inline

Definition at line 140 of file C4Value.h.

140 { C4V_Data d; d.Fn = Fn; Set(d, C4V_Function); }

References C4V_Function, C4V_Data::Fn, and Set().

Referenced by C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetInt()

void C4Value::SetInt ( int32_t  i)
inline

Definition at line 136 of file C4Value.h.

136 { C4V_Data d; d.Int = i; Set(d, C4V_Int); }

References C4V_Int, C4V_Data::Int, and Set().

Referenced by C4Command::Activate(), CompileFunc(), C4Command::InitEvaluation(), C4Command::Set(), and C4AulCompiler::ConstexprEvaluator::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetObjectEnum()

void C4Value::SetObjectEnum ( int  i)
inline

Definition at line 142 of file C4Value.h.

142 { C4V_Data d; d.Int = i; Set(d, C4V_C4ObjectEnum); }

References C4V_C4ObjectEnum, C4V_Data::Int, and Set().

Referenced by C4Effect::CompileFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPropList()

void C4Value::SetPropList ( C4PropList PropList)
inline

Definition at line 141 of file C4Value.h.

141 { C4V_Data d; d.PropList = PropList; Set(d, C4V_PropList); }

References C4V_PropList, C4V_Data::PropList, and Set().

Referenced by C4Effect::C4Effect(), C4SoundModifier::C4SoundModifier(), CompileFunc(), C4ValueNumbers::CompileValue(), Denumerate(), C4GameMessage::Init(), C4Game::InitScriptEngine(), C4GameScriptHost::Load(), C4GameScriptHost::LoadData(), C4Game::SetGlobalSoundModifier(), C4PropList::SetPropertyByS(), and C4Player::SetSoundModifier().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetString()

void C4Value::SetString ( C4String Str)
inline

Definition at line 138 of file C4Value.h.

138 { C4V_Data d; d.Str = Str; Set(d, C4V_String); }

References C4V_String, Set(), and C4V_Data::Str.

Referenced by CompileFunc(), and C4Game::GetTranslatedString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToJSON()

StdStrBuf C4Value::ToJSON ( int  depth = 10,
const class C4PropListStatic ignore_reference_parent = nullptr 
) const

Definition at line 189 of file C4Value.cpp.

190 {
191  // ouput by type info
192  switch (GetType())
193  {
194  case C4V_Int:
195  return FormatString("%ld", static_cast<long>(Data.Int));
196  case C4V_Bool:
197  return StdStrBuf(Data ? "true" : "false");
198  case C4V_PropList:
199  {
200  const C4PropListStatic * Def = Data.PropList->IsStatic();
201  if (Def)
202  if (!ignore_reference_parent || Def->GetParent() != ignore_reference_parent)
203  return Def->ToJSON();
204  return Data.PropList->ToJSON(depth, Def && ignore_reference_parent);
205  }
206  case C4V_String:
207  if (Data.Str && Data.Str->GetCStr())
208  {
209  StdStrBuf str = Data.Str->GetData();
210  str.EscapeString();
211  str.Replace("\n", R"(\n)");
212  return FormatString(R"("%s")", str.getData());
213  }
214  else
215  {
216  return StdStrBuf("null");
217  }
218  case C4V_Array:
219  {
220  if (depth <= 0 && Data.Array->GetSize())
221  {
222  throw C4JSONSerializationError("maximum depth reached");
223  }
224  StdStrBuf DataString;
225  DataString = "[";
226  for (int32_t i = 0; i < Data.Array->GetSize(); i++)
227  {
228  if (i) DataString.Append(",");
229  DataString.Append(std::move(Data.Array->GetItem(i).ToJSON(depth - 1)));
230  }
231  DataString.AppendChar(']');
232  return DataString;
233  }
234  case C4V_Function:
235  throw C4JSONSerializationError("cannot serialize function");
236  case C4V_Nil:
237  return StdStrBuf("null");
238  default:
239  throw C4JSONSerializationError("unknown type");
240  }
241 }
StdStrBuf ToJSON(int depth=10, bool ignore_reference_parent=false) const
Definition: C4PropList.cpp:515
StdStrBuf ToJSON(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
Definition: C4Value.cpp:189
void EscapeString()
Definition: StdBuf.h:669
int Replace(const char *szOld, const char *szNew, size_t iStartSearch=0)
Definition: StdBuf.cpp:284
const char * getData() const
Definition: StdBuf.h:442

References StdStrBuf::Append(), StdStrBuf::AppendChar(), C4V_Data::Array, C4V_Array, C4V_Bool, C4V_Function, C4V_Int, C4V_Nil, C4V_PropList, C4V_String, StdStrBuf::EscapeString(), FormatString(), C4String::GetCStr(), StdStrBuf::getData(), C4String::GetData(), C4ValueArray::GetItem(), C4PropListStatic::GetParent(), C4ValueArray::GetSize(), GetType(), C4V_Data::Int, C4PropList::IsStatic(), C4V_Data::PropList, StdStrBuf::Replace(), C4V_Data::Str, C4PropList::ToJSON(), and ToJSON().

Referenced by C4PropList::ToJSON(), and ToJSON().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WarnAboutConversion()

bool C4Value::WarnAboutConversion ( C4V_Type  Type,
C4V_Type  vtToType 
)
static

Definition at line 111 of file C4Value.cpp.

112 {
113  switch (vtToType)
114  {
115  case C4V_Nil: return Type != C4V_Nil && Type != C4V_Any;
116  case C4V_Int: return Type != C4V_Int && Type != C4V_Nil && Type != C4V_Bool && Type != C4V_Any;
117  case C4V_Bool: return false;
118  case C4V_PropList: return Type != C4V_PropList && Type != C4V_Effect && Type != C4V_Def && Type != C4V_Object && Type != C4V_Nil && Type != C4V_Any;
119  case C4V_String: return Type != C4V_String && Type != C4V_Nil && Type != C4V_Any;
120  case C4V_Array: return Type != C4V_Array && Type != C4V_Nil && Type != C4V_Any;
121  case C4V_Function: return Type != C4V_Function && Type != C4V_Nil && Type != C4V_Any;
122  case C4V_Any: return false;
123  case C4V_Def: return Type != C4V_Def && Type != C4V_Object && Type != C4V_PropList && Type != C4V_Nil && Type != C4V_Any;
124  case C4V_Object: return Type != C4V_Object && Type != C4V_PropList && Type != C4V_Nil && Type != C4V_Any;
125  case C4V_Effect: return Type != C4V_Effect && Type != C4V_PropList && Type != C4V_Nil && Type != C4V_Any;
126  default: assert(!"C4Value::ConvertTo: impossible conversion target"); return false;
127  }
128 }

References C4V_Any, C4V_Array, C4V_Bool, C4V_Def, C4V_Effect, C4V_Function, C4V_Int, C4V_Nil, C4V_Object, C4V_PropList, and C4V_String.

Friends And Related Function Documentation

◆ C4PropList

friend class C4PropList
friend

Definition at line 235 of file C4Value.h.


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