| 754 | } |
| 755 | |
| 756 | Expected<void> Object::deserializeRecursive_( const std::filesystem::path& path, const Json::Value& root, |
| 757 | int* objCounter, MapLinkToSharedObjectModel& mapLinkToSharedObjectModel, const ProgressCallback& progressCb ) |
| 758 | { |
| 759 | std::string key = root["Key"].isString() ? root["Key"].asString() : root["Name"].asString(); |
| 760 | |
| 761 | std::string link; |
| 762 | if ( !root["Link"].empty() && root["Link"].isString() ) |
| 763 | link = root["Link"].asString(); |
| 764 | |
| 765 | auto pathToDeserializeModel = path / pathFromUtf8( key ); |
| 766 | if ( !link.empty() ) |
| 767 | { |
| 768 | pathToDeserializeModel = mapLinkToSharedObjectModel.rootFolder / pathFromUtf8( link ); |
| 769 | |
| 770 | const auto [it, inserted] = mapLinkToSharedObjectModel.map.insert( { link, this } ); |
| 771 | if (!inserted ) |
| 772 | { |
| 773 | // model already deserialized |
| 774 | const auto res = setSharedModel_( *it->second ); |
| 775 | if ( !res.has_value() ) |
| 776 | return res; |
| 777 | pathToDeserializeModel.clear(); |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | if ( !pathToDeserializeModel.empty() ) |
| 782 | { |
| 783 | const auto res = deserializeModel_( pathToDeserializeModel, progressCb ); |
| 784 | if ( !res.has_value() ) |
| 785 | return res; |
| 786 | } |
| 787 | |
| 788 | deserializeFields_( root ); |
| 789 | if ( objCounter ) |
| 790 | ++( *objCounter ); |
| 791 | |
| 792 | if (!root["Children"].isNull()) |
| 793 | { |
| 794 | // split keys by type to sort numeric |
| 795 | std::vector<long> orderedLongChildKeys; // all that can be converted to Long type |
| 796 | std::vector<std::string> orderedStringChildKeys; // others |
| 797 | for ( const std::string& childKey : root["Children"].getMemberNames() ) |
| 798 | { |
| 799 | char* p_end; |
| 800 | long childKeyAsLong = std::strtol( childKey.c_str(), &p_end, 10 ); // check if key can be converted to Long |
| 801 | if ( *p_end ) // stoi failed |
| 802 | orderedStringChildKeys.push_back( childKey ); |
| 803 | else |
| 804 | orderedLongChildKeys.push_back( childKeyAsLong ); |
| 805 | } |
| 806 | std::sort( orderedLongChildKeys.begin(), orderedLongChildKeys.end() ); |
| 807 | |
| 808 | // join keys: after sorted numeric add all string keys |
| 809 | std::vector<std::string> orderedKeys; |
| 810 | orderedKeys.reserve( orderedLongChildKeys.size() + orderedStringChildKeys.size() ); |
| 811 | for ( const long& k : orderedLongChildKeys ) |
| 812 | orderedKeys.push_back( std::to_string( k ) ); |
| 813 | orderedKeys.insert( orderedKeys.end(), |
nothing calls this directly
no test coverage detected