--------------------------------- ExtractValue Extracts a json basic type or object to an rttr variant, if it is neither it will return an invalid variant
| 601 | // Extracts a json basic type or object to an rttr variant, if it is neither it will return an invalid variant |
| 602 | // |
| 603 | rttr::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 |
no test coverage detected