MCPcopy Create free account
hub / github.com/Illation/ETEngine / ExtractValue

Function ExtractValue

Engine/source/EtCore/Reflection/serialization.cpp:603–639  ·  view source on GitHub ↗

--------------------------------- ExtractValue Extracts a json basic type or object to an rttr variant, if it is neither it will return an invalid variant

Source from the content-addressed store, hash-verified

601// Extracts a json basic type or object to an rttr variant, if it is neither it will return an invalid variant
602//
603rttr::variant ExtractValue(JSON::Value const* const jVal, const rttr::type& valueType)
604{
605 // try converting from a basic type
606 rttr::variant extractedVal = ExtractBasicTypes(jVal);
607
608 // if that doesn't work, try an object
609 if (!extractedVal.convert(valueType))
610 {
611 if (jVal->GetType() == JSON::JSON_Object)
612 {
613 // find the right constructor for our type
614 rttr::constructor ctor = valueType.get_constructor();
615 for (auto& item : valueType.get_constructors())
616 {
617 if (item.get_instantiated_type() == valueType)
618 {
619 ctor = item;
620 }
621 }
622
623 //use it
624 extractedVal = ctor.invoke();
625
626 JSON::Value const* localJVal = jVal;
627 rttr::type localType = valueType;
628 if (!ExtractPointerValueType(localType, localJVal))
629 {
630 return rttr::variant();
631 }
632
633 // fill the rest of our object
634 ObjectFromJsonRecursive(localJVal, extractedVal, localType);
635 }
636 }
637
638 return extractedVal;
639}
640
641//---------------------------------
642// AssociativeViewFromJsonRecursive

Callers 1

Calls 4

ExtractBasicTypesFunction · 0.85
ExtractPointerValueTypeFunction · 0.85
ObjectFromJsonRecursiveFunction · 0.85
GetTypeMethod · 0.45

Tested by

no test coverage detected