|
| 1 | +#include "lib/core/globals.h" |
| 2 | +#include "lib/data/decoded.h" |
| 3 | +#include "lib/data/image.h" |
| 4 | +#include "lib/data/layout.h" |
| 5 | +#include "lib/data/sector.h" |
| 6 | +#include "protocol.h" |
| 7 | + |
| 8 | +namespace |
| 9 | +{ |
| 10 | + struct pair_to_range_t |
| 11 | + { |
| 12 | + template <typename I> |
| 13 | + friend constexpr auto operator|( |
| 14 | + std::pair<I, I> const& pr, pair_to_range_t) |
| 15 | + { |
| 16 | + return std::ranges::subrange(pr.first, pr.second); |
| 17 | + } |
| 18 | + }; |
| 19 | + inline constexpr pair_to_range_t pair_to_range{}; |
| 20 | +} |
| 21 | + |
| 22 | +void DecodedDisk::populateTrackDataFromImage(const DiskLayout& diskLayout) |
| 23 | +{ |
| 24 | + tracksByPhysicalLocation.clear(); |
| 25 | + sectorsByPhysicalLocation.clear(); |
| 26 | + |
| 27 | + std::multimap<CylinderHead, std::shared_ptr<const Sector>> |
| 28 | + sectorsGroupedByTrack; |
| 29 | + for (const auto& sector : *image) |
| 30 | + sectorsGroupedByTrack.insert( |
| 31 | + std::make_pair(sector->physicalLocation.value(), sector)); |
| 32 | + |
| 33 | + for (const auto& physicalLocation : |
| 34 | + std::views::keys(sectorsGroupedByTrack) | std::ranges::to<std::set>()) |
| 35 | + { |
| 36 | + const auto& ptl = |
| 37 | + diskLayout.layoutByPhysicalLocation.at(physicalLocation); |
| 38 | + const auto& ltl = ptl->logicalTrackLayout; |
| 39 | + |
| 40 | + auto decodedTrack = std::make_shared<DecodedTrack>(); |
| 41 | + decodedTrack->ltl = ltl; |
| 42 | + decodedTrack->ptl = ptl; |
| 43 | + tracksByPhysicalLocation.insert( |
| 44 | + std::make_pair(physicalLocation, decodedTrack)); |
| 45 | + |
| 46 | + for (auto& [ch, sector] : |
| 47 | + sectorsGroupedByTrack.equal_range(physicalLocation) | pair_to_range) |
| 48 | + { |
| 49 | + decodedTrack->sectors.push_back(sector); |
| 50 | + sectorsByPhysicalLocation.insert( |
| 51 | + std::make_pair(physicalLocation, sector)); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments