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