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 : NextRef(nullptr), Type(C4V_Nil) { Data = 0; }
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 = 0; 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 65 of file C4Value.cpp.

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

Definition at line 66 of file C4Value.cpp.

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

Definition at line 67 of file C4Value.cpp.

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

Definition at line 68 of file C4Value.cpp.

68 : 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:449

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:58
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 85 of file C4Value.cpp.

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

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

86 {
87  return Data.PropList ? Data.PropList->GetDef() : nullptr;
88 }
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:662
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 75 of file C4Value.cpp.

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

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

76 {
77  return Data.PropList ? Data.PropList->GetObject() : nullptr;
78 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:644
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(), 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 302 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().

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

254 {
255  switch (Type)
256  {
257  case C4V_Enum:
258  Set(numbers->GetValue(Data.Int)); break;
259  case C4V_Array:
260  Data.Array->Denumerate(numbers); break;
261  case C4V_PropList:
262  // objects and effects are denumerated via the main object list
263  if (!Data.PropList->IsNumbered() && !Data.PropList->IsStatic())
264  Data.PropList->Denumerate(numbers);
265  break;
266  case C4V_C4ObjectEnum:
267  {
269  if (pObj)
270  // set
271  SetPropList(pObj);
272  else
273  {
274  // object: invalid value - set to zero
275  LogF("ERROR: Object number %d is missing.", int(Data.Int));
276  Set0();
277  }
278  }
279  default: break;
280  }
281 }
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:87
void Set(const C4Value &nValue)
Definition: C4Value.h:134
virtual void Denumerate(C4ValueNumbers *)
Definition: C4PropList.cpp:351
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:90
const C4Value & GetValue(uint32_t)
Definition: C4Value.cpp:245
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
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 : 0; }
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 133 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 CompileFunc(), C4Object::Draw(), C4AulScriptFunc::DumpByteCode(), GetDataString(), and C4AulScriptContext::ReturnDump().

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

81 {
82  return CheckConversion(C4V_Def) ? Data.PropList->GetDef() : nullptr;
83 }
ALWAYS_INLINE bool CheckConversion(C4V_Type vtToType) const
Definition: C4Value.h:189
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:662
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 70 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().

71 {
72  return CheckConversion(C4V_Object) ? Data.PropList->GetObject() : nullptr;
73 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:644
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(), 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

Definition at line 161 of file C4Value.h.

Referenced by C4ValueConv< Nillable< T > >::_FromC4V(), ComparisonImpl(), C4Game::CompileFunc(), C4ValueNumbers::CompileValue(), C4ScriptHost::CopyPropList(), C4Object::ExecAction(), GetDataString(), C4Object::GetInfoString(), GetTypeName(), IsIdenticalTo(), C4ValueArray::SetSlice(), ToJSON(), C4AulCompiler::CodegenAstVisitor::visit(), and C4AulCompiler::ConstexprEvaluator::visit().

161 { return Type; }

Here is the caller graph for this function:

C4V_Type C4Value::GetTypeEx ( ) const

Definition at line 625 of file C4Value.cpp.

References C4V_Def, C4V_Effect, C4V_Object, and C4V_PropList.

626 {
627  // Return type including types derived from prop list types (such as C4V_Def)
628  if (Type == C4V_PropList)
629  {
630  if (FnCnvEffect()) return C4V_Effect;
631  if (FnCnvObject()) return C4V_Object;
632  if (FnCnvDef()) return C4V_Def;
633  }
634  return Type;
635 }
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:34

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 : 0; } // 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 620 of file C4Value.cpp.

621 {
622  return !(*this == Value2);
623 }
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 572 of file C4Value.cpp.

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

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

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

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

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

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: