| 1475 | */ |
| 1476 | |
| 1477 | void Storage::GetChildrenInGroups(CountryId const & parent, CountriesVec & downloadedChildren, |
| 1478 | CountriesVec & availChildren, bool keepAvailableChildren) const |
| 1479 | { |
| 1480 | CHECK_THREAD_CHECKER(m_threadChecker, ()); |
| 1481 | |
| 1482 | CountryTree::Node const * const parentNode = m_countries.FindFirst(parent); |
| 1483 | if (parentNode == nullptr) |
| 1484 | { |
| 1485 | ASSERT(false, ("CountryId =", parent, "not found in m_countries.")); |
| 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | downloadedChildren.clear(); |
| 1490 | availChildren.clear(); |
| 1491 | |
| 1492 | // Vector of disputed territories which are downloaded but the other maps |
| 1493 | // in their group are not downloaded. Only mwm in subtree with root == |parent| |
| 1494 | // are taken into account. |
| 1495 | CountriesVec disputedTerritoriesWithoutSiblings; |
| 1496 | // All disputed territories in subtree with root == |parent|. |
| 1497 | CountriesVec allDisputedTerritories; |
| 1498 | parentNode->ForEachChild([&](CountryTree::Node const & childNode) |
| 1499 | { |
| 1500 | CountryId const & childValue = childNode.Value().Name(); |
| 1501 | |
| 1502 | vector<pair<CountryId, NodeStatus>> disputedTerritoriesAndStatus; |
| 1503 | StatusAndError const childStatus = |
| 1504 | GetNodeStatusInfo(childNode, disputedTerritoriesAndStatus, true /* isDisputedTerritoriesCounted */); |
| 1505 | |
| 1506 | ASSERT_NOT_EQUAL(childStatus.status, NodeStatus::Undefined, ()); |
| 1507 | for (auto const & disputed : disputedTerritoriesAndStatus) |
| 1508 | allDisputedTerritories.push_back(disputed.first); |
| 1509 | |
| 1510 | if (childStatus.status == NodeStatus::NotDownloaded) |
| 1511 | { |
| 1512 | availChildren.push_back(childValue); |
| 1513 | for (auto const & disputed : disputedTerritoriesAndStatus) |
| 1514 | if (disputed.second != NodeStatus::NotDownloaded) |
| 1515 | disputedTerritoriesWithoutSiblings.push_back(disputed.first); |
| 1516 | } |
| 1517 | else |
| 1518 | { |
| 1519 | downloadedChildren.push_back(childValue); |
| 1520 | if (keepAvailableChildren) |
| 1521 | availChildren.push_back(childValue); |
| 1522 | } |
| 1523 | }); |
| 1524 | |
| 1525 | CountriesVec uniqueDisputed(disputedTerritoriesWithoutSiblings.begin(), disputedTerritoriesWithoutSiblings.end()); |
| 1526 | base::SortUnique(uniqueDisputed); |
| 1527 | |
| 1528 | for (auto const & countryId : uniqueDisputed) |
| 1529 | { |
| 1530 | // Checks that the number of disputed territories with |countryId| in subtree with root == |
| 1531 | // |parent| |
| 1532 | // is equal to the number of disputed territories with out downloaded sibling |
| 1533 | // with |countryId| in subtree with root == |parent|. |
| 1534 | if (count(disputedTerritoriesWithoutSiblings.begin(), disputedTerritoriesWithoutSiblings.end(), countryId) == |