mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
# Conflicts: # CMakeLists.txt # android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java # android/sdk/src/main/cpp/app/organicmaps/sdk/Framework.hpp # android/sdk/src/main/cpp/app/organicmaps/sdk/OrganicMaps.cpp # android/sdk/src/main/cpp/app/organicmaps/sdk/util/Config.cpp # libs/indexer/data_source.hpp # libs/indexer/feature.hpp # libs/indexer/ftypes_matcher.hpp # libs/map/framework.cpp # libs/map/traffic_manager.cpp # libs/routing/absent_regions_finder.cpp # libs/routing/edge_estimator.hpp # libs/routing/index_router.cpp # libs/routing/index_router.hpp # libs/routing/routing_session.hpp # libs/routing_common/num_mwm_id.hpp # libs/traffic/traffic_info.cpp # qt/mainwindow.hpp # qt/preferences_dialog.cpp # tools/openlr/helpers.hpp # tools/openlr/openlr_decoder.cpp # tools/openlr/openlr_decoder.hpp # tools/openlr/openlr_stat/openlr_stat.cpp # tools/openlr/router.hpp # tools/openlr/score_candidate_paths_getter.cpp # tools/openlr/score_candidate_paths_getter.hpp # xcode/CoMaps.xcworkspace/contents.xcworkspacedata
96 lines
2.2 KiB
C++
96 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "platform/country_file.hpp"
|
|
|
|
#include "base/assert.hpp"
|
|
#include "base/checked_cast.hpp"
|
|
#include "base/logging.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <limits>
|
|
#include <map>
|
|
#include <vector>
|
|
|
|
namespace routing
|
|
{
|
|
using NumMwmId = std::uint16_t;
|
|
NumMwmId constexpr kFakeNumMwmId = std::numeric_limits<NumMwmId>::max();
|
|
NumMwmId constexpr kGeneratorMwmId = 0;
|
|
|
|
/**
|
|
* @brief A numbered list of country files.
|
|
*/
|
|
class NumMwmIds final
|
|
{
|
|
public:
|
|
bool IsEmpty() const { return m_idToFile.empty(); }
|
|
|
|
/**
|
|
* @brief Registers a file, i.e. adds it to the instance.
|
|
*
|
|
* If the instance already contains the file, this is a no-op.
|
|
*
|
|
* @param file
|
|
*/
|
|
void RegisterFile(platform::CountryFile const & file)
|
|
{
|
|
if (ContainsFile(file))
|
|
return;
|
|
|
|
NumMwmId const id = base::asserted_cast<NumMwmId>(m_idToFile.size());
|
|
m_idToFile.push_back(file);
|
|
m_fileToId[file] = id;
|
|
|
|
// LOG(LDEBUG, ("MWM:", file.GetName(), "=", id));
|
|
}
|
|
|
|
/**
|
|
* @brief Whether this instance contains a given file.
|
|
* @param file
|
|
* @return
|
|
*/
|
|
bool ContainsFile(platform::CountryFile const & file) const { return m_fileToId.find(file) != m_fileToId.cend(); }
|
|
|
|
/**
|
|
* @brief Whether this instance contains a file at a given index.
|
|
* @param mwmId The index.
|
|
* @return
|
|
*/
|
|
bool ContainsFileForMwm(NumMwmId mwmId) const { return mwmId < m_idToFile.size(); }
|
|
|
|
/**
|
|
* @brief Returns a file by index.
|
|
* @param mwmId The index.
|
|
* @return
|
|
*/
|
|
platform::CountryFile const & GetFile(NumMwmId mwmId) const
|
|
{
|
|
ASSERT_LESS(mwmId, m_idToFile.size(), ());
|
|
return m_idToFile[mwmId];
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the index for a given file.
|
|
* @param file
|
|
* @return
|
|
*/
|
|
NumMwmId GetId(platform::CountryFile const & file) const
|
|
{
|
|
auto const it = m_fileToId.find(file);
|
|
ASSERT(it != m_fileToId.cend(), ("Can't find mwm id for", file));
|
|
return it->second;
|
|
}
|
|
|
|
template <typename F>
|
|
void ForEachId(F && f) const
|
|
{
|
|
for (NumMwmId id = 0; id < base::asserted_cast<NumMwmId>(m_idToFile.size()); ++id)
|
|
f(id);
|
|
}
|
|
|
|
private:
|
|
std::vector<platform::CountryFile> m_idToFile;
|
|
std::map<platform::CountryFile, NumMwmId> m_fileToId;
|
|
};
|
|
} // namespace routing
|