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
127 lines
5.0 KiB
C++
127 lines
5.0 KiB
C++
#pragma once
|
|
|
|
#include "indexer/feature_covering.hpp"
|
|
#include "indexer/feature_source.hpp"
|
|
#include "indexer/mwm_set.hpp"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
class DataSource : public MwmSet
|
|
{
|
|
public:
|
|
using FeatureCallback = std::function<void(FeatureType &)>;
|
|
using FeatureIdCallback = std::function<void(FeatureID const &)>;
|
|
using StopSearchCallback = std::function<bool(void)>;
|
|
|
|
/// Registers a new map.
|
|
std::pair<MwmId, RegResult> RegisterMap(platform::LocalCountryFile const & localFile);
|
|
|
|
/**
|
|
* @brief Deregisters a map from internal records.
|
|
* @param countryFile A `CountryFile` denoting a map to be deregistered.
|
|
* @return True if the map was successfully deregistered, false if the map is locked now.
|
|
*/
|
|
bool DeregisterMap(platform::CountryFile const & countryFile);
|
|
|
|
void ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, int scale,
|
|
covering::CoveringMode mode = covering::ViewportWithLowLevels) const;
|
|
void ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const;
|
|
|
|
/**
|
|
* @brief Iterates over features within a given distance of a center point.
|
|
*
|
|
* Calls `f` for features closest to `center` until `stopCallback` returns true or distance
|
|
* `sizeM` from has been reached. Then for EditableDataSource calls `f` for each edited feature
|
|
* inside square with center `center` and side `2 * sizeM`. Edited features are not in the same
|
|
* hierarchy and there is no fast way to merge frozen and edited features.
|
|
*
|
|
* @brief f Callback function that is called on each feature.
|
|
* @brief stopCallback Callback function which decides whether to continue searching or stop.
|
|
* @brief center The center of the search area.
|
|
* @brief sizeM The size of the search area, as a distance from the center point.
|
|
* @brief scale
|
|
*/
|
|
void ForClosestToPoint(FeatureCallback const & f, StopSearchCallback const & stopCallback, m2::PointD const & center,
|
|
double sizeM, int scale) const;
|
|
void ForEachInScale(FeatureCallback const & f, int scale) const;
|
|
void ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const & rect, int scale, MwmId const & id) const;
|
|
// "features" must be sorted using FeatureID::operator< as predicate.
|
|
void ReadFeatures(FeatureCallback const & fn, std::vector<FeatureID> const & features) const;
|
|
|
|
void ReadFeature(FeatureCallback const & fn, FeatureID const & feature) const { return ReadFeatures(fn, {feature}); }
|
|
|
|
std::unique_ptr<FeatureSource> CreateFeatureSource(DataSource::MwmHandle const & handle) const
|
|
{
|
|
return (*m_factory)(handle);
|
|
}
|
|
|
|
protected:
|
|
using ReaderCallback =
|
|
std::function<void(MwmSet::MwmHandle const & handle, covering::CoveringGetter & cov, int scale)>;
|
|
|
|
explicit DataSource(std::unique_ptr<FeatureSourceFactory> factory) : m_factory(std::move(factory)) {}
|
|
|
|
void ForEachInIntervals(ReaderCallback const & fn, covering::CoveringMode mode, m2::RectD const & rect,
|
|
int scale) const;
|
|
|
|
/// @name MwmSet overrides
|
|
/// @{
|
|
std::unique_ptr<MwmInfo> CreateInfo(platform::LocalCountryFile const & localFile) const override;
|
|
std::unique_ptr<MwmValue> CreateValue(MwmInfo & info) const override;
|
|
/// @}
|
|
|
|
private:
|
|
std::unique_ptr<FeatureSourceFactory> m_factory;
|
|
};
|
|
|
|
/**
|
|
* @brief A `DataSource` which operates with features from an MWM file and does not support
|
|
* creation, deletion or modification of features.
|
|
*/
|
|
class FrozenDataSource : public DataSource
|
|
{
|
|
public:
|
|
FrozenDataSource() : DataSource(std::make_unique<FeatureSourceFactory>()) {}
|
|
};
|
|
|
|
/**
|
|
* @brief Guard for loading features from particular MWM by demand.
|
|
*
|
|
* @note If you need to work with `FeatureType` from different threads, you need to use
|
|
* a unique `FeaturesLoaderGuard` instance for every thread.
|
|
* For an example of concurrent extracting feature details please see `ConcurrentFeatureParsingTest`
|
|
* in `routing/routing_integration_tests`.
|
|
*/
|
|
class FeaturesLoaderGuard
|
|
{
|
|
public:
|
|
FeaturesLoaderGuard(DataSource const & dataSource, DataSource::MwmId const & id)
|
|
: m_handle(dataSource.GetMwmHandleById(id))
|
|
, m_source(dataSource.CreateFeatureSource(m_handle))
|
|
{
|
|
// FeaturesLoaderGuard is always created in-place, so MWM should always be alive.
|
|
ASSERT(id.IsAlive(), ());
|
|
}
|
|
|
|
MwmSet::MwmId const & GetId() const { return m_handle.GetId(); }
|
|
MwmSet::MwmHandle const & GetHandle() const { return m_handle; }
|
|
|
|
std::string GetCountryFileName() const;
|
|
int64_t GetVersion() const;
|
|
|
|
bool IsWorld() const;
|
|
/// Editor core only method, to get 'untouched', original version of feature.
|
|
std::unique_ptr<FeatureType> GetOriginalFeatureByIndex(uint32_t index) const;
|
|
std::unique_ptr<FeatureType> GetOriginalOrEditedFeatureByIndex(uint32_t index) const;
|
|
/// Everyone, except Editor core, should use this method.
|
|
std::unique_ptr<FeatureType> GetFeatureByIndex(uint32_t index) const;
|
|
size_t GetNumFeatures() const { return m_source->GetNumFeatures(); }
|
|
|
|
private:
|
|
MwmSet::MwmHandle m_handle;
|
|
std::unique_ptr<FeatureSource> m_source;
|
|
};
|