Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'routing_common/vehicle_model.hpp')
-rw-r--r--routing_common/vehicle_model.hpp53
1 files changed, 44 insertions, 9 deletions
diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp
index 4f54aa34b7..4fbb6daf06 100644
--- a/routing_common/vehicle_model.hpp
+++ b/routing_common/vehicle_model.hpp
@@ -2,6 +2,7 @@
#include <initializer_list>
#include <memory>
+#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
@@ -14,7 +15,7 @@ namespace feature { class TypesHolder; }
namespace routing
{
-class IVehicleModel
+class VehicleModelInterface
{
public:
enum class RoadAvailability
@@ -24,7 +25,7 @@ public:
Unknown,
};
- virtual ~IVehicleModel() {}
+ virtual ~VehicleModelInterface() {}
/// @return Allowed speed in KMpH.
/// 0 means that it's forbidden to move on this feature or it's not a road at all.
@@ -42,20 +43,20 @@ public:
virtual bool IsTransitAllowed(FeatureType const & f) const = 0;
};
-class VehicleModelFactory
+class VehicleModelFactoryInterface
{
public:
- virtual ~VehicleModelFactory() {}
+ virtual ~VehicleModelFactoryInterface() {}
/// @return Default vehicle model which corresponds for all countrines,
/// but it may be non optimal for some countries
- virtual std::shared_ptr<IVehicleModel> GetVehicleModel() const = 0;
+ virtual std::shared_ptr<VehicleModelInterface> GetVehicleModel() const = 0;
/// @return The most optimal vehicle model for specified country
- virtual std::shared_ptr<IVehicleModel> GetVehicleModelForCountry(
+ virtual std::shared_ptr<VehicleModelInterface> GetVehicleModelForCountry(
std::string const & country) const = 0;
};
-class VehicleModel : public IVehicleModel
+class VehicleModel : public VehicleModelInterface
{
public:
struct FeatureTypeLimits final
@@ -82,7 +83,7 @@ public:
VehicleModel(Classificator const & c, InitListT const & featureTypeLimits);
- /// IVehicleModel overrides:
+ /// VehicleModelInterface overrides:
double GetSpeed(FeatureType const & f) const override;
double GetMaxSpeed() const override { return m_maxSpeedKMpH; }
bool IsOneWay(FeatureType const & f) const override;
@@ -104,6 +105,13 @@ public:
return false;
}
+ bool EqualsForTests(VehicleModel const & rhs) const
+ {
+ return (m_types == rhs.m_types) &&
+ (m_addRoadTypes == rhs.m_addRoadTypes) &&
+ (m_onewayType == rhs.m_onewayType);
+ }
+
protected:
/// @returns a special restriction which is set to the feature.
virtual RoadAvailability GetRoadAvailability(feature::TypesHolder const & types) const;
@@ -143,6 +151,10 @@ private:
double GetSpeedKMpH() const { return m_speedKMpH; };
bool IsTransitAllowed() const { return m_isTransitAllowed; };
+ bool operator==(RoadLimits const & rhs) const
+ {
+ return (m_speedKMpH == rhs.m_speedKMpH) && (m_isTransitAllowed == rhs.m_isTransitAllowed);
+ }
private:
double const m_speedKMpH;
@@ -157,5 +169,28 @@ private:
uint32_t m_onewayType;
};
-std::string DebugPrint(IVehicleModel::RoadAvailability const l);
+class VehicleModelFactory : public VehicleModelFactoryInterface
+{
+public:
+ // Callback which takes territory name (mwm graph node name) and returns its parent
+ // territory name. Used to properly find local restrictions in GetVehicleModelForCountry.
+ // For territories which do not have parent (countries) or have multiple parents
+ // (disputed territories) it should return empty name.
+ // For example "Munich" -> "Bavaria"; "Bavaria" -> "Germany"; "Germany" -> ""
+ using CountryParentNameGetterFn = std::function<std::string(std::string const &)>;
+
+ std::shared_ptr<VehicleModelInterface> GetVehicleModel() const override;
+
+ std::shared_ptr<VehicleModelInterface> GetVehicleModelForCountry(
+ std::string const & country) const override;
+
+protected:
+ VehicleModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn);
+ std::string GetParent(std::string const & country) const;
+
+ std::unordered_map<std::string, std::shared_ptr<VehicleModelInterface>> m_models;
+ CountryParentNameGetterFn m_countryParentNameGetterFn;
+};
+
+std::string DebugPrint(VehicleModelInterface::RoadAvailability const l);
} // namespace routing