25 void C4PropList::AddRef(
C4Value *pRef)
27 assert(Refs.count(pRef) == 0);
31 void C4PropList::DelRef(
C4Value * pRef)
33 auto erased = Refs.erase(pRef);
37 if (Refs.empty() &&
Delete())
delete this;
58 if (!pObj)
return false;
103 ShelvedPropList->AcquireNumber();
123 if (*p) (*p)->
Clear();
166 pComp->
excCorrupt(
"multiple PropLists with Number %d", n);
180 Log(
"removing numbered proplist without number");
225 pComp->
excCorrupt(
"C4PropListStatic::RefCompileFunc without ParentKeyName");
266 for (
auto prop_name : prop_names)
272 if (child_proplist && child_proplist->
IsFrozen())
288 this_static->Properties.Swap(&Properties);
290 RefSet pre_freeze_refs{Refs};
292 for (
C4Value * ref : pre_freeze_refs)
293 ref->SetPropList(this_static);
303 for (
auto prop_name : prop_names)
327 p = Properties.
Next(p);
338 Ref->Data =
nullptr; Ref->Type =
C4V_Nil;
342 assert(PropLists.Has(
this));
343 PropLists.Remove(
this);
351 if (
this == &
b)
return true;
353 if (Properties.
GetSize() !=
b.Properties.GetSize())
return false;
354 if (
GetDef() !=
b.GetDef())
return false;
359 if (!bp)
return false;
361 p = Properties.
Next(p);
368 bool oldFormat =
false;
376 pComp->
Value(constant);
414 pStruct = temp.release();
432 if (!fNaming && !
iSize--)
457 int32_t
iSize = GetSize();
461 const T * p = First();
490 if (depth <= 0 && Properties.
GetSize())
495 bool has_elements =
false;
499 DataString.
Append(
"Prototype = ");
505 for (std::list<const C4Property *>::const_iterator p = sorted_props.
begin(); p != sorted_props.
end(); ++p)
507 if (has_elements) DataString.
Append(delim);
508 DataString.
Append((*p)->Key->GetData());
510 DataString.
Append((*p)->Value.GetDataString(depth - 1, ignore_reference_parent ?
IsStatic() :
nullptr));
517 if (depth <= 0 && Properties.
GetSize())
523 bool has_elements =
false;
527 DataString.
Append(
"Prototype:");
533 for (std::list<const C4Property *>::const_iterator p = sorted_props.
begin(); p != sorted_props.
end(); ++p)
535 if (has_elements) DataString.
Append(
",");
538 DataString.
Append((*p)->Value.ToJSON(depth - 1, ignore_reference_parent ?
IsStatic() :
nullptr));
549 std::vector< C4String * > result;
550 result.reserve(sorted_props.size() + add_prototype);
552 for (
auto p : sorted_props) result.push_back(p->Key);
560 std::vector< C4String * > result;
563 if (!prefix || pp->Key->GetData().BeginsWith(prefix))
567 bool overridden =
false;
568 if (check && check !=
this)
570 if (check->
HasProperty(pp->Key)) { overridden =
true;
break; }
573 result.push_back(pp->Key);
576 std::sort(result.begin(), result.end(), [](
const C4String *
a,
const C4String *
b) ->
bool
578 return strcmp(a->GetCStr(), b->GetCStr()) < 0;
587 std::vector< C4String * > result;
593 if (!prefix || pp->Key->GetData().BeginsWith(prefix))
594 result.push_back(pp->Key);
596 if (p == ignore_parent)
break;
606 return strcmp(
a->GetCStr(),
b->GetCStr()) < 0;
613 std::set< C4String *, sort_cmp > result_set(result.begin(), result.end());
614 result.assign(result_set.begin(), result_set.end());
684 template<>
template<>
688 unsigned int hash = 4, tmp;
689 hash += ((uintptr_t)e) >> 16;
690 tmp = ((((uintptr_t)e) & 0xffff) << 11) ^ hash;
691 hash = (hash << 16) ^ tmp;
702 template<>
template<>
705 return Hash<const C4String *>(e);
708 template<>
template<>
714 template<>
template<>
720 template<>
template<>
728 if (Properties.
Has(k))
735 *pResult = prototype;
747 if (Properties.
Has(k))
761 if (Properties.
Has(k))
775 if (Properties.
Has(k))
789 if (
s[0] ==
'~') ++
s;
802 return pFn->
Exec(
this, Pars, fPassErrors);
821 return pFn->
Exec(
this, Pars, fPassErrors);
827 if (Properties.
Has(k))
844 if (Properties.
Has(k))
858 if (Properties.
Has(k))
872 if (Properties.
Has(k))
887 const bool hasInheritedProperties =
GetPrototype() !=
nullptr;
888 if (hasInheritedProperties)
892 a->SetSize(i + Properties.
GetSize());
903 assert(newPropertyName !=
nullptr &&
"Proplist key is nullpointer");
905 bool skipProperty =
false;
906 if (hasInheritedProperties)
908 for (
size_t j = 0; j < i; ++j)
910 if ((*
a)[j].getStr() != newPropertyName)
continue;
918 assert(((*
a)[i - 1].GetType() ==
C4V_String) &&
"Proplist key is non-string");
920 p = Properties.
Next(p);
923 if (hasInheritedProperties)
935 p = Properties.
Next(p);
948 throw C4AulExecError(
"Trying to create cyclic prototype structure");
951 else if (Properties.
Has(k))
969 void C4PropList::Iterator::Init()
971 iter = properties->begin();
974 void C4PropList::Iterator::Reserve(
size_t additionalAmount)
976 properties->reserve(properties->size() + additionalAmount);
979 void C4PropList::Iterator::AddProperty(
const C4Property * prop)
981 std::vector<const C4Property*>::size_type i = 0, len = properties->size();
984 const C4Property *oldProperty = (*properties)[i];
985 if (oldProperty->
Key == prop->
Key)
987 (*properties)[i] = prop;
992 properties->push_back(prop);
1005 iter.properties = std::make_shared<std::vector<const C4Property*> >();
1007 iter.Reserve(Properties.
GetSize());
1012 iter.AddProperty(p);
1013 p = Properties.
Next(p);
1021 template<>
template<>
1024 unsigned int hash = 4, tmp;
1026 tmp = ((e & 0xffff) << 11) ^ hash;
1027 hash = (hash << 16) ^ tmp;
1038 template<>
template<>
1044 template<>
template<>
1050 template<>
template<>
1053 return a->Number ==
b;
1056 template<>
template<>
1062 template<>
template<>
1068 template<>
template<>
1073 uintptr_t hash =
reinterpret_cast<uintptr_t
>(e);
1074 return (
unsigned int)(hash / 63);
C4AulScriptEngine ScriptEngine
bool Log(const char *szMessage)
void CompileNewFunc(C4PropList *&pStruct, StdCompiler *pComp, C4ValueNumbers *rPar)
C4Value C4VPropList(C4PropList *p)
C4Value C4VString(C4String *pStr)
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
StdStrBuf FormatString(const char *szFmt,...)
virtual void OnError(const char *msg)=0
const char * what() const noexcept override
C4Value Exec(C4PropList *p=nullptr, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
C4AulErrorHandler * GetErrorHandler() const
C4PropListStatic * GetPropList()
virtual void SetName(const char *NewName=nullptr)
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
int32_t GetPropertyBool(C4PropertyName n, bool default_val=false) const
virtual C4Object * GetObject()
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *)
C4AulFunc * GetFunc(C4PropertyName k) const
bool operator==(const C4PropList &b) const
virtual const char * GetName() const
virtual C4ValueArray * GetProperties() const
virtual class C4PropListStatic * IsStatic()
C4String * EnumerateOwnFuncs(C4String *prev=nullptr) const
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
C4ValueArray * GetPropertyArray(C4PropertyName n) const
virtual bool IsNumbered() const
virtual C4Effect * GetEffect()
bool HasProperty(C4String *k) const
C4PropertyName GetPropertyP(C4PropertyName k) const
void RemoveCyclicPrototypes()
C4PropListStatic * FreezeAndMakeStaticRecursively(std::vector< C4Value > *prop_lists, const C4PropListStatic *parent=nullptr, C4String *key=nullptr)
virtual void ResetProperty(C4String *k)
std::vector< C4String * > GetSortedLocalProperties(bool add_prototype=true) const
C4PropList * GetPrototype() const
StdStrBuf ToJSON(int depth=10, bool ignore_reference_parent=false) const
C4PropList * GetPropertyPropList(C4PropertyName k) const
void AppendDataString(StdStrBuf *out, const char *delim, int depth=3, bool ignore_reference_parent=false) const
C4PropList(C4PropList *prototype=nullptr)
C4String * GetPropertyStr(C4PropertyName k) const
virtual void Denumerate(C4ValueNumbers *)
virtual C4PropListNumbered * GetPropListNumbered()
virtual C4Def const * GetDef() const
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
virtual void SetPropertyByS(C4String *k, const C4Value &to)
static C4PropList * New(C4PropList *prototype=nullptr)
virtual class C4MapScriptLayer * GetMapScriptLayer()
std::vector< C4String * > GetSortedProperties(const char *prefix, C4PropList *ignore_parent=nullptr) const
virtual class C4MapScriptMap * GetMapScriptMap()
void SetProperty(C4PropertyName k, const C4Value &to)
static C4PropListStatic * NewStatic(C4PropList *prototype, const C4PropListStatic *parent, C4String *key)
std::vector< C4String * > GetUnsortedProperties(const char *prefix, C4PropList *ignore_parent=nullptr) const
C4PropListNumbered(C4PropList *prototype=nullptr)
C4PropListNumbered * GetPropListNumbered() override
~C4PropListNumbered() override
static void ClearShelve()
static std::vector< C4PropListNumbered * > ShelvedPropLists
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *numbers)
static bool CheckPropList(C4PropList *)
static C4Set< C4PropListNumbered * > PropLists
static void ShelveNumberedPropLists()
static void UnshelveNumberedPropLists()
static void ClearNumberedPropLists()
static void SetEnumerationIndex(int32_t iMaxObjectNumber)
static C4PropList * GetByNumber(int32_t iNumber)
static void ResetEnumerationIndex()
static int32_t EnumerationIndex
static C4Set< C4PropListScript * > PropLists
static void ClearScriptPropLists()
void RefCompileFunc(StdCompiler *pComp, C4ValueNumbers *numbers) const
C4RefCntPointer< C4String > ParentKeyName
C4String * GetParentKeyName()
StdStrBuf GetDataString() const
const C4PropListStatic * GetParent() const
const char * GetName() const override
const C4PropListStatic * Parent
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *)
void CompileFunc(class StdCompiler *pComp, class C4ValueNumbers *)
T const * Next(T const *p) const
std::list< const T * > GetSortedListOfElementPointers() const
unsigned int GetSize() const
static unsigned int Hash(const H &)
StdStrBuf GetData() const
C4String * FindString(const char *strString) const
C4String * RegString(StdStrBuf String)
C4ValueArray * getArray() const
void SetPropList(C4PropList *PropList)
StdStrBuf ToJSON(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
StdStrBuf GetDataString(int depth=10, const class C4PropListStatic *ignore_reference_parent=nullptr) const
C4String * getStr() const
C4AulFunc * getFunction() const
C4PropList * getPropList() const
void Denumerate(C4ValueNumbers *)
virtual bool Separator(Sep eSep=SEP_SEP)
void excCorrupt(const char *szMessage,...)
void Value(const T &rStruct)
virtual bool isDeserializer()
void AppendChar(char cChar)
void Append(const char *pnData, size_t iChars)