OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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::C4Value ( )
inline

Definition at line 76 of file C4Value.h.

76 { Data = nullptr; }
C4Value::C4Value ( const C4Value nValue)
inline

Definition at line 78 of file C4Value.h.

78  : Data(nValue.Data), NextRef(nullptr), Type(nValue.Type)
79  { AddDataRef(); }
ALWAYS_INLINE C4Value::C4Value ( C4Value &&  nValue)
noexcept

Definition at line 349 of file C4Value.h.

References C4V_Nil, C4V_PropList, and C4V_Data::PropList.

349  :
350  Data(nValue.Data), NextRef(nullptr), Type(nValue.Type)
351 {
352  if (Type == C4V_PropList)
353  {
354  Data.PropList->AddRef(this);
355  Data.PropList->DelRef(&nValue, nValue.NextRef);
356  }
357  nValue.Type = C4V_Nil; nValue.Data = nullptr; nValue.NextRef = nullptr;
358 }
C4PropList * PropList
Definition: C4Value.h:54
C4Value::C4Value ( bool  data)
inlineexplicit

Definition at line 82 of file C4Value.h.

References C4V_Data::Int.

82  : NextRef(nullptr), Type(C4V_Bool)
83  { Data.Int = data; }
intptr_t Int
Definition: C4Value.h:52
C4Value::C4Value ( int  data)
inlineexplicit

Definition at line 84 of file C4Value.h.

References C4V_Data::Int.

84  : NextRef(nullptr), Type(C4V_Int)
85  { Data.Int = data; }
intptr_t Int
Definition: C4Value.h:52
C4Value::C4Value ( long  data)
inlineexplicit

Definition at line 86 of file C4Value.h.

References C4V_Data::Int.

86  : NextRef(nullptr), Type(C4V_Int)
87  { Data.Int = int32_t(data); }
intptr_t Int
Definition: C4Value.h:52
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::C4Value ( C4Def p)
explicit

Definition at line 64 of file C4Value.cpp.

64 : C4Value(static_cast<C4PropList *>(p)) {}
C4Value()
Definition: C4Value.h:76
C4Value::C4Value ( C4Object pObj)
explicit

Definition at line 65 of file C4Value.cpp.

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

Definition at line 66 of file C4Value.cpp.

66 : C4Value(static_cast<C4PropList *>(p)) {}
C4Value()
Definition: C4Value.h:76
C4Value::C4Value ( C4String pStr)
inlineexplicit

Definition at line 92 of file C4Value.h.

References C4V_Data::Str.

92  : NextRef(nullptr), Type(pStr ? C4V_String : C4V_Nil)
93  { Data.Str = pStr; AddDataRef(); }
C4String * Str
Definition: C4Value.h:55
C4Value::C4Value ( const char *  s)
inlineexplicit

Definition at line 94 of file C4Value.h.

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

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

Here is the call graph for this function:

C4Value::C4Value ( const StdStrBuf s)
inlineexplicit

Definition at line 96 of file C4Value.h.

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

96  : NextRef(nullptr), Type(s.isNull() ? C4V_Nil : C4V_String)
97  { Data.Str = s.isNull() ? nullptr: ::Strings.RegString(s); AddDataRef(); }
C4String * RegString(StdStrBuf String)
C4String * Str
Definition: C4Value.h:55
C4StringTable Strings
Definition: C4Globals.cpp:42
bool isNull() const
Definition: StdBuf.h:441

Here is the call graph for this function:

C4Value::C4Value ( C4ValueArray pArray)
inlineexplicit

Definition at line 98 of file C4Value.h.

References C4V_Data::Array.

98  : NextRef(nullptr), Type(pArray ? C4V_Array : C4V_Nil)
99  { Data.Array = pArray; AddDataRef(); }
C4ValueArray * Array
Definition: C4Value.h:56
C4Value::C4Value ( C4AulFunc pFn)
inlineexplicit

Definition at line 100 of file C4Value.h.

References C4V_Data::Fn.

100  : NextRef(nullptr), Type(pFn ? C4V_Function : C4V_Nil)
101  { Data.Fn = pFn; AddDataRef(); }
C4AulFunc * Fn
Definition: C4Value.h:57
C4Value::C4Value ( C4PropList p)
inlineexplicit

Definition at line 102 of file C4Value.h.

References C4V_Data::PropList.

102  : NextRef(nullptr), Type(p ? C4V_PropList : C4V_Nil)
103  { Data.PropList = p; AddDataRef(); }
C4PropList * PropList
Definition: C4Value.h:54
C4Value::C4Value ( C4ObjectPtr  p)
inline

Definition at line 104 of file C4Value.h.

104 : C4Value(p.operator C4Object *()) {}
C4Value()
Definition: C4Value.h:76
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())) {}
C4Value()
Definition: C4Value.h:76
bool IsNil() const
Definition: C4AulDefFunc.h:57
C4Value::~C4Value ( )
inline

Definition at line 109 of file C4Value.h.

109 { DelDataRef(Data, Type, NextRef); }

Member Function Documentation

C4ValueArray* C4Value::_getArray ( ) const
inline

Definition at line 127 of file C4Value.h.

References C4V_Data::Array.

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

127 { return Data.Array; }
C4ValueArray * Array
Definition: C4Value.h:56

Here is the caller graph for this function:

bool C4Value::_getBool ( ) const
inline

Definition at line 123 of file C4Value.h.

References C4V_Data::Int.

Referenced by C4ValueConv< bool >::_FromC4V(), and C4AulCompiler::CodegenAstVisitor::visit().

123 { return !! Data.Int; }
intptr_t Int
Definition: C4Value.h:52

Here is the caller graph for this function:

C4Def * C4Value::_getDef ( ) const

Definition at line 83 of file C4Value.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4AulFunc* C4Value::_getFunction ( ) const
inline

Definition at line 128 of file C4Value.h.

References C4V_Data::Fn.

Referenced by C4ValueConv< C4AulFunc * >::_FromC4V(), and C4AulCompiler::CodegenAstVisitor::visit().

128 { return Data.Fn; }
C4AulFunc * Fn
Definition: C4Value.h:57

Here is the caller graph for this function:

C4Object * C4Value::_getObj ( ) const

Definition at line 73 of file C4Value.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4String* C4Value::_getStr ( ) const
inline

Definition at line 126 of file C4Value.h.

References C4V_Data::Str.

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

126 { return Data.Str; }
C4String * Str
Definition: C4Value.h:55

Here is the caller graph for this function:

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

Definition at line 189 of file C4Value.h.

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

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  }

Here is the caller graph for this function:

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

Definition at line 171 of file C4Value.h.

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

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  }
void C4Value::CompileFunc ( StdCompiler pComp,
C4ValueNumbers numbers 
)

Definition at line 300 of file C4Value.cpp.

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(), StdStrBuf::getData(), GetDataString(), C4PropList::GetFunc(), getFunction(), C4AulScriptEngine::GetGlobalConstant(), C4AulFunc::GetName(), C4ValueNumbers::GetNumberForValue(), C4PropList::GetPropertyByS(), getPropList(), C4AulScriptEngine::GetPropList(), C4PropList::GetPropListNumbered(), C4V_Data::Int, StdCompiler::isDeserializer(), C4PropList::IsStatic(), mkParAdapt(), C4PropListNumbered::Number, C4AulFunc::Parent, StdCompiler::RCT_ID, StdStrBuf::Ref(), 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().

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 }
const char * getData() const
Definition: StdBuf.h:442
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
StdStrBuf GetData() const
Definition: C4StringTable.h:50
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4GameScriptHost GameScript
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4String * FindString(const char *strString) const
const char * GetName() const
Definition: C4AulFunc.h:56
C4AulFunc * GetFunc(C4PropertyName k) const
Definition: C4PropList.h:105
C4String * RegString(StdStrBuf String)
C4AulFunc * Fn
Definition: C4Value.h:57
bool GetGlobalConstant(const char *szName, C4Value *pTargetValue)
void Set0()
Definition: C4Value.h:336
void SetBool(bool b)
Definition: C4Value.h:137
C4String * Str
Definition: C4Value.h:55
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
StdStrBuf GetDataString(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
Definition: C4Value.cpp:131
void Set(const C4Value &nValue)
Definition: C4Value.h:134
void SetString(C4String *Str)
Definition: C4Value.h:138
uint32_t GetNumberForValue(C4Value *v)
Definition: C4Value.cpp:287
intptr_t Int
Definition: C4Value.h:52
C4StringTable Strings
Definition: C4Globals.cpp:42
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:757
C4Value ScenPropList
Definition: C4ScriptHost.h:163
void RefCompileFunc(StdCompiler *pComp, C4ValueNumbers *numbers) const
Definition: C4PropList.cpp:240
C4Value ScenPrototype
Definition: C4ScriptHost.h:164
void Value(const T &rStruct)
Definition: StdCompiler.h:161
void SetInt(int32_t i)
Definition: C4Value.h:136
virtual bool isDeserializer()
Definition: StdCompiler.h:53
void Ref(const char *pnData)
Definition: StdBuf.h:455
virtual void Character(char &rChar)=0
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
void SetPropList(C4PropList *PropList)
Definition: C4Value.h:141
virtual C4PropListNumbered * GetPropListNumbered()
Definition: C4PropList.cpp:703
#define s
C4AulFunc * getFunction() const
Definition: C4Value.h:119
C4PropList * getPropList() const
Definition: C4Value.h:116

Here is the call graph for this function:

void C4Value::Denumerate ( C4ValueNumbers numbers)

Definition at line 251 of file C4Value.cpp.

References C4V_Data::Array, C4V_Array, C4V_C4ObjectEnum, C4V_Enum, C4V_PropList, C4ValueArray::Denumerate(), C4PropList::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(), C4Effect::Denumerate(), C4PropList::Denumerate(), C4GameScriptHost::Denumerate(), and C4Game::InitGame().

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 }
void Denumerate(C4ValueNumbers *)
static C4PropList * GetByNumber(int32_t iNumber)
Definition: C4PropList.cpp:75
void Set0()
Definition: C4Value.h:336
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
void Set(const C4Value &nValue)
Definition: C4Value.h:134
virtual void Denumerate(C4ValueNumbers *)
Definition: C4PropList.cpp:350
intptr_t Int
Definition: C4Value.h:52
C4ValueArray * Array
Definition: C4Value.h:56
void SetPropList(C4PropList *PropList)
Definition: C4Value.h:141
virtual bool IsNumbered() const
Definition: C4PropList.h:88
const C4Value & GetValue(uint32_t)
Definition: C4Value.cpp:243
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:260
C4PropList * PropList
Definition: C4Value.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

C4ValueArray* C4Value::getArray ( ) const
inline

Definition at line 118 of file C4Value.h.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Value::getBool ( ) const
inline

Definition at line 113 of file C4Value.h.

References C4V_Bool, and CheckConversion().

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

113 { return CheckConversion(C4V_Bool) ? !! Data : false; }
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189

Here is the call graph for this function:

Here is the caller graph for this function:

C4V_Data C4Value::GetData ( ) const
inline

Definition at line 160 of file C4Value.h.

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

160 { return Data; }

Here is the caller graph for this function:

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

Definition at line 131 of file C4Value.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendChar(), C4PropList::AppendDataString(), C4V_Data::Array, C4V_Array, C4V_Bool, C4V_Function, C4V_Int, C4V_Nil, C4V_PropList, C4V_String, C4V_Data::Fn, FormatString(), C4String::GetCStr(), GetDataString(), C4PropListStatic::GetDataString(), C4PropList::GetEffect(), C4AulFunc::GetFullName(), C4ValueArray::GetItem(), C4PropList::GetObject(), C4PropListStatic::GetParent(), C4AulScriptEngine::GetPropList(), C4ValueArray::GetSize(), GetType(), C4V_Data::Int, C4PropList::IsStatic(), C4PropListNumbered::Number, C4V_Data::PropList, ScriptEngine, and C4V_Data::Str.

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

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 }
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
const char * GetCStr() const
Definition: C4StringTable.h:49
C4AulFunc * Fn
Definition: C4Value.h:57
C4String * Str
Definition: C4Value.h:55
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
StdStrBuf GetDataString(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
Definition: C4Value.cpp:131
virtual C4Object * GetObject()
Definition: C4PropList.cpp:667
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
void AppendChar(char cChar)
Definition: StdBuf.h:588
C4V_Type GetType() const
Definition: C4Value.h:161
intptr_t Int
Definition: C4Value.h:52
void AppendDataString(StdStrBuf *out, const char *delim, int depth=3, bool ignore_reference_parent=false) const
Definition: C4PropList.cpp:518
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
virtual StdStrBuf GetFullName() const
Definition: C4AulFunc.cpp:38
int32_t GetSize() const
Definition: C4ValueArray.h:36
virtual C4Effect * GetEffect()
Definition: C4PropList.cpp:709
C4ValueArray * Array
Definition: C4Value.h:56
const C4PropListStatic * GetParent() const
Definition: C4PropList.h:270
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
C4PropList * PropList
Definition: C4Value.h:54
StdStrBuf GetDataString() const
Definition: C4PropList.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:

C4Def * C4Value::getDef ( ) const

Definition at line 78 of file C4Value.cpp.

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

79 {
80  return CheckConversion(C4V_Def) ? Data.PropList->GetDef() : nullptr;
81 }
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:685
C4PropList * PropList
Definition: C4Value.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

C4AulFunc* C4Value::getFunction ( ) const
inline

Definition at line 119 of file C4Value.h.

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

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

119 { return CheckConversion(C4V_Function) ? Data.Fn : nullptr; }
C4AulFunc * Fn
Definition: C4Value.h:57
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4Value::getInt ( ) const
inline
C4Object * C4Value::getObj ( ) const

Definition at line 68 of file C4Value.cpp.

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

69 {
70  return CheckConversion(C4V_Object) ? Data.PropList->GetObject() : nullptr;
71 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:667
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189
C4PropList * PropList
Definition: C4Value.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

C4PropList* C4Value::getPropList ( ) const
inline

Definition at line 116 of file C4Value.h.

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

Referenced by C4MapScriptAlgoModifier::C4MapScriptAlgoModifier(), C4Effect::ClearPointers(), C4Effect::CompileFunc(), CompileFunc(), C4ScriptGuiWindow::Denumerate(), C4Viewport::Execute(), FnGetEffectsFor(), C4PropList::FreezeAndMakeStaticRecursively(), C4Object::GetAction(), C4Def::GetActionByName(), C4PropList::GetPropertyPropList(), C4ScriptGuiWindowAction::Init(), C4Player::Init(), C4PropList::RemoveCyclicPrototypes(), C4ScriptGuiWindowProperty::Set(), C4Object::SetAction(), C4Object::SetActionByName(), C4PropList::SetPropertyByS(), C4PropList::ThawRecursively(), C4GraphicsOverlay::UpdateFacet(), and C4AulCompiler::ConstexprEvaluator::visit().

116 { return CheckConversion(C4V_PropList) ? Data.PropList : nullptr; }
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189
C4PropList * PropList
Definition: C4Value.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

C4String* C4Value::getStr ( ) const
inline

Definition at line 117 of file C4Value.h.

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

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

117 { return CheckConversion(C4V_String) ? Data.Str : nullptr; }
C4String * Str
Definition: C4Value.h:55
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189

Here is the call graph for this function:

Here is the caller graph for this function:

C4V_Type C4Value::GetType ( ) const
inline
C4V_Type C4Value::GetTypeEx ( ) const

Definition at line 623 of file C4Value.cpp.

References C4V_Def, C4V_Effect, C4V_Object, and C4V_PropList.

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 }
const char* C4Value::GetTypeName ( ) const
inline

Definition at line 164 of file C4Value.h.

References GetC4VName(), and GetType().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 149 of file C4Value.h.

References GetData(), and GetType().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 212 of file C4Value.h.

References C4V_Bool, and C4V_Int.

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

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

Here is the caller graph for this function:

C4Value::operator const void * ( ) const
inline

Definition at line 132 of file C4Value.h.

References GetData().

132 { return GetData() ? this : nullptr; } // To allow use of C4Value in conditions
C4V_Data GetData() const
Definition: C4Value.h:160

Here is the call graph for this function:

bool C4Value::operator! ( ) const
inline

Definition at line 131 of file C4Value.h.

References GetData().

131 { return !GetData(); }
C4V_Data GetData() const
Definition: C4Value.h:160

Here is the call graph for this function:

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

Definition at line 618 of file C4Value.cpp.

619 {
620  return !(*this == Value2);
621 }
C4Value& C4Value::operator++ ( )
inline

Definition at line 154 of file C4Value.h.

References C4V_Int, and C4V_Data::Int.

154 { Data.Int++; Type=C4V_Int; return *this; }
intptr_t Int
Definition: C4Value.h:52
C4Value C4Value::operator++ ( int  )
inline

Definition at line 155 of file C4Value.h.

155 { C4Value old = *this; ++(*this); return old; }
C4Value& C4Value::operator+= ( int32_t  by)
inline

Definition at line 153 of file C4Value.h.

References C4V_Int, and C4V_Data::Int.

153 { Data.Int += by; Type=C4V_Int; return *this; }
intptr_t Int
Definition: C4Value.h:52
C4Value& C4Value::operator-- ( )
inline

Definition at line 156 of file C4Value.h.

References C4V_Int, and C4V_Data::Int.

156 { Data.Int--; Type=C4V_Int; return *this; }
intptr_t Int
Definition: C4Value.h:52
C4Value C4Value::operator-- ( int  )
inline

Definition at line 157 of file C4Value.h.

157 { C4Value old = *this; --(*this); return old; }
C4Value& C4Value::operator= ( const C4Value nValue)
inline

Definition at line 107 of file C4Value.h.

References Set().

107 { Set(nValue); return *this; }
void Set(const C4Value &nValue)
Definition: C4Value.h:134

Here is the call graph for this function:

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

Definition at line 570 of file C4Value.cpp.

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

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 LogF(const char *strMessage,...)
Definition: C4Log.cpp:260
bool operator==(const C4Value &Value2) const
Definition: C4Value.cpp:570
#define s

Here is the call graph for this function:

void C4Value::Set ( const C4Value nValue)
inline

Definition at line 134 of file C4Value.h.

References Set().

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

134 { Set(nValue.Data, nValue.Type); }
void Set(const C4Value &nValue)
Definition: C4Value.h:134

Here is the call graph for this function:

Here is the caller graph for this function:

ALWAYS_INLINE void C4Value::Set0 ( )

Definition at line 336 of file C4Value.h.

References C4V_Nil.

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

337 {
338  C4V_Data oData = Data;
339  C4V_Type oType = Type;
340 
341  // change
342  Data = nullptr;
343  Type = C4V_Nil;
344 
345  // clean up (save even if Data was 0 before)
346  DelDataRef(oData, oType, NextRef);
347 }
C4V_Type
Definition: C4Value.h:23

Here is the caller graph for this function:

void C4Value::SetArray ( C4ValueArray Array)
inline

Definition at line 139 of file C4Value.h.

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

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

139 { C4V_Data d; d.Array = Array; Set(d, C4V_Array); }
void Set(const C4Value &nValue)
Definition: C4Value.h:134
C4ValueArray * Array
Definition: C4Value.h:56

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Value::SetBool ( bool  b)
inline

Definition at line 137 of file C4Value.h.

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

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

137 { C4V_Data d; d.Int = b; Set(d, C4V_Bool); }
#define b
void Set(const C4Value &nValue)
Definition: C4Value.h:134
intptr_t Int
Definition: C4Value.h:52

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Value::SetFunction ( C4AulFunc Fn)
inline

Definition at line 140 of file C4Value.h.

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

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

140 { C4V_Data d; d.Fn = Fn; Set(d, C4V_Function); }
C4AulFunc * Fn
Definition: C4Value.h:57
void Set(const C4Value &nValue)
Definition: C4Value.h:134

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Value::SetInt ( int32_t  i)
inline

Definition at line 136 of file C4Value.h.

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

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

136 { C4V_Data d; d.Int = i; Set(d, C4V_Int); }
void Set(const C4Value &nValue)
Definition: C4Value.h:134
intptr_t Int
Definition: C4Value.h:52

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Value::SetObjectEnum ( int  i)
inline

Definition at line 142 of file C4Value.h.

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

Referenced by C4Effect::CompileFunc().

142 { C4V_Data d; d.Int = i; Set(d, C4V_C4ObjectEnum); }
void Set(const C4Value &nValue)
Definition: C4Value.h:134
intptr_t Int
Definition: C4Value.h:52

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Value::SetPropList ( C4PropList PropList)
inline

Definition at line 141 of file C4Value.h.

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

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

141 { C4V_Data d; d.PropList = PropList; Set(d, C4V_PropList); }
void Set(const C4Value &nValue)
Definition: C4Value.h:134
C4PropList * PropList
Definition: C4Value.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Value::SetString ( C4String Str)
inline

Definition at line 138 of file C4Value.h.

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

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

138 { C4V_Data d; d.Str = Str; Set(d, C4V_String); }
C4String * Str
Definition: C4Value.h:55
void Set(const C4Value &nValue)
Definition: C4Value.h:134

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 189 of file C4Value.cpp.

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(), C4String::GetData(), StdStrBuf::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().

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 }
const char * getData() const
Definition: StdBuf.h:442
StdStrBuf ToJSON(int depth=10, bool ignore_reference_parent=false) const
Definition: C4PropList.cpp:546
StdStrBuf GetData() const
Definition: C4StringTable.h:50
int Replace(const char *szOld, const char *szNew, size_t iStartSearch=0)
Definition: StdBuf.cpp:284
const char * GetCStr() const
Definition: C4StringTable.h:49
C4String * Str
Definition: C4Value.h:55
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
void AppendChar(char cChar)
Definition: StdBuf.h:588
C4V_Type GetType() const
Definition: C4Value.h:161
intptr_t Int
Definition: C4Value.h:52
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
int32_t GetSize() const
Definition: C4ValueArray.h:36
C4ValueArray * Array
Definition: C4Value.h:56
StdStrBuf ToJSON(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
Definition: C4Value.cpp:189
void EscapeString()
Definition: StdBuf.h:669
const C4PropListStatic * GetParent() const
Definition: C4PropList.h:270
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
C4PropList * PropList
Definition: C4Value.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 111 of file C4Value.cpp.

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 C4AulCompiler::CodegenAstVisitor::visit().

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 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4PropList
friend

Definition at line 238 of file C4Value.h.


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