|
40 | 40 | #include <fmt/format.h>
|
41 | 41 |
|
42 | 42 | #include <range/v3/algorithm/any_of.hpp>
|
| 43 | +#include <range/v3/view/drop_exactly.hpp> |
43 | 44 | #include <range/v3/view/enumerate.hpp>
|
44 | 45 |
|
45 | 46 | #include <fstream>
|
@@ -615,40 +616,24 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
|
615 | 616 | solThrow(AssemblyImportException, "The value of key '" + dataItemID + "' inside '.data' is neither a hex-string nor an object.");
|
616 | 617 | }
|
617 | 618 | }
|
| 619 | + |
618 | 620 | if (_level == 0)
|
619 |
| - result->updatePaths(); |
| 621 | + result->encodeAllPossibleSubPathsInAssemblyTree(); |
| 622 | + |
620 | 623 | return std::make_pair(result, _level == 0 ? parsedSourceList : std::vector<std::string>{});
|
621 | 624 | }
|
622 | 625 |
|
623 |
| -void Assembly::updatePaths(std::vector<Assembly*> const& _parents, std::vector<size_t> const& _absolutePathFromRoot) |
| 626 | +void Assembly::encodeAllPossibleSubPathsInAssemblyTree(std::vector<size_t> _pathFromRoot, std::vector<Assembly*> _assembliesOnPath) |
624 | 627 | {
|
625 |
| - size_t subId = 0; |
626 |
| - for (std::shared_ptr<Assembly> assembly: m_subs) |
| 628 | + _assembliesOnPath.push_back(this); |
| 629 | + for (_pathFromRoot.push_back(0); _pathFromRoot.back() < m_subs.size(); ++_pathFromRoot.back()) |
627 | 630 | {
|
628 |
| - std::vector<Assembly*> parents{_parents}; |
629 |
| - parents.push_back(this); |
630 |
| - |
631 |
| - std::vector<size_t> absolutePathFromRoot{_absolutePathFromRoot}; |
632 |
| - absolutePathFromRoot.emplace_back(subId); |
633 |
| - |
634 |
| - int pindex = 0; |
635 |
| - for (Assembly* parent: parents) |
636 |
| - { |
637 |
| - if (pindex == 0) |
638 |
| - parent->encodeSubPath(absolutePathFromRoot); |
639 |
| - else |
640 |
| - { |
641 |
| - std::vector<size_t> relativePath{absolutePathFromRoot}; |
642 |
| - for (int i = 0; i < pindex; ++i) |
643 |
| - relativePath.erase(relativePath.begin()); |
644 |
| - parent->encodeSubPath(relativePath); |
645 |
| - } |
646 |
| - ++pindex; |
647 |
| - } |
648 |
| - |
649 |
| - assembly->updatePaths(parents, absolutePathFromRoot); |
| 631 | + for (size_t distanceFromRoot = 0; distanceFromRoot < _assembliesOnPath.size(); ++distanceFromRoot) |
| 632 | + _assembliesOnPath[distanceFromRoot]->encodeSubPath( |
| 633 | + _pathFromRoot | ranges::views::drop_exactly(distanceFromRoot) | ranges::to<std::vector> |
| 634 | + ); |
650 | 635 |
|
651 |
| - ++subId; |
| 636 | + m_subs[_pathFromRoot.back()]->encodeAllPossibleSubPathsInAssemblyTree(_pathFromRoot, _assembliesOnPath); |
652 | 637 | }
|
653 | 638 | }
|
654 | 639 |
|
|
0 commit comments