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