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:
authorDaria Volvenkova <d.volvenkova@corp.mail.ru>2017-08-15 17:27:15 +0300
committerRoman Kuznetsov <r.kuznetsow@gmail.com>2017-08-15 18:13:10 +0300
commit7d1c6e0e9a43f1489e8a0cd9f3f0c4430ee009b5 (patch)
treec9fac7043e1cc1a70670233109369445bdcc722c
parent711b1d44176d245d624e95f3b06e76c23d62ca1f (diff)
Refactoring of route point's intermediate index type.
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp4
-rw-r--r--map/routing_manager.cpp27
-rw-r--r--map/routing_manager.hpp16
-rw-r--r--map/routing_mark.cpp30
-rw-r--r--map/routing_mark.hpp18
5 files changed, 47 insertions, 48 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index 0b9d298505..ea7b814584 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -1213,7 +1213,7 @@ Java_com_mapswithme_maps_Framework_nativeAddRoutePoint(JNIEnv * env, jclass, jst
data.m_title = jni::ToNativeString(env, title);
data.m_subTitle = jni::ToNativeString(env, subtitle);
data.m_pointType = static_cast<RouteMarkType>(markType);
- data.m_intermediateIndex = static_cast<int8_t>(intermediateIndex);
+ data.m_intermediateIndex = static_cast<size_t>(intermediateIndex);
data.m_isMyPosition = static_cast<bool>(isMyPosition);
data.m_position = m2::PointD(MercatorBounds::FromLatLon(lat, lon));
@@ -1225,7 +1225,7 @@ Java_com_mapswithme_maps_Framework_nativeRemoveRoutePoint(JNIEnv * env, jclass,
jint markType, jint intermediateIndex)
{
frm()->GetRoutingManager().RemoveRoutePoint(static_cast<RouteMarkType>(markType),
- static_cast<int8_t>(intermediateIndex));
+ static_cast<size_t>(intermediateIndex));
}
JNIEXPORT void JNICALL
diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp
index 46d4914bd7..3dad8e26d0 100644
--- a/map/routing_manager.cpp
+++ b/map/routing_manager.cpp
@@ -265,7 +265,7 @@ RoutingManager::RoutingManager(Callbacks && callbacks, Delegate & delegate)
else if (passedCheckpointIdx + 1 == pointsCount)
OnRoutePointPassed(RouteMarkType::Finish, 0);
else
- OnRoutePointPassed(RouteMarkType::Intermediate, static_cast<int8_t>(passedCheckpointIdx - 1));
+ OnRoutePointPassed(RouteMarkType::Intermediate, passedCheckpointIdx - 1);
});
});
}
@@ -322,7 +322,7 @@ void RoutingManager::OnRebuildRouteReady(Route const & route, IRouter::ResultCod
CallRouteBuilded(code, storage::TCountriesVec());
}
-void RoutingManager::OnRoutePointPassed(RouteMarkType type, int8_t intermediateIndex)
+void RoutingManager::OnRoutePointPassed(RouteMarkType type, size_t intermediateIndex)
{
// Remove route point.
ASSERT(m_bmManager != nullptr, ());
@@ -533,7 +533,7 @@ void RoutingManager::SetLastUsedRouter(RouterType type)
settings::Set(kRouterTypeKey, ToString(type));
}
-void RoutingManager::HideRoutePoint(RouteMarkType type, int8_t intermediateIndex)
+void RoutingManager::HideRoutePoint(RouteMarkType type, size_t intermediateIndex)
{
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
RouteMarkPoint * mark = routePoints.GetRoutePoint(type, intermediateIndex);
@@ -544,7 +544,7 @@ void RoutingManager::HideRoutePoint(RouteMarkType type, int8_t intermediateIndex
}
}
-bool RoutingManager::IsMyPosition(RouteMarkType type, int8_t intermediateIndex)
+bool RoutingManager::IsMyPosition(RouteMarkType type, size_t intermediateIndex)
{
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
RouteMarkPoint * mark = routePoints.GetRoutePoint(type, intermediateIndex);
@@ -572,8 +572,7 @@ bool RoutingManager::CouldAddIntermediatePoint() const
return false;
auto const & controller = m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK);
- return controller.GetUserMarkCount() <
- static_cast<size_t>(RoutePointsLayout::kMaxIntermediatePointsCount + 2);
+ return controller.GetUserMarkCount() < RoutePointsLayout::kMaxIntermediatePointsCount + 2;
}
void RoutingManager::AddRoutePoint(RouteMarkData && markData)
@@ -591,7 +590,7 @@ void RoutingManager::AddRoutePoint(RouteMarkData && markData)
routePoints.NotifyChanges();
}
-void RoutingManager::RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex)
+void RoutingManager::RemoveRoutePoint(RouteMarkType type, size_t intermediateIndex)
{
ASSERT(m_bmManager != nullptr, ());
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
@@ -615,8 +614,8 @@ void RoutingManager::RemoveIntermediateRoutePoints()
routePoints.NotifyChanges();
}
-void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
- RouteMarkType targetType, int8_t targetIntermediateIndex)
+void RoutingManager::MoveRoutePoint(RouteMarkType currentType, size_t currentIntermediateIndex,
+ RouteMarkType targetType, size_t targetIntermediateIndex)
{
ASSERT(m_bmManager != nullptr, ());
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
@@ -625,13 +624,13 @@ void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentInt
routePoints.NotifyChanges();
}
-void RoutingManager::MoveRoutePoint(int8_t currentIndex, int8_t targetIndex)
+void RoutingManager::MoveRoutePoint(size_t currentIndex, size_t targetIndex)
{
ASSERT(m_bmManager != nullptr, ());
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
size_t const sz = routePoints.GetRoutePointsCount();
- auto const convertIndex = [sz](RouteMarkType & type, int8_t & index) {
+ auto const convertIndex = [sz](RouteMarkType & type, size_t & index) {
if (index == 0)
{
type = RouteMarkType::Start;
@@ -701,10 +700,10 @@ void RoutingManager::ReorderIntermediatePoints()
CheckpointPredictor predictor(m_routingSession.GetStartPoint(), m_routingSession.GetEndPoint());
- auto const insertIndex = predictor.PredictPosition(prevPositions, addedPosition);
- addedPoint->SetIntermediateIndex(static_cast<int8_t>(insertIndex));
+ size_t const insertIndex = predictor.PredictPosition(prevPositions, addedPosition);
+ addedPoint->SetIntermediateIndex(insertIndex);
for (size_t i = 0; i < prevPoints.size(); ++i)
- prevPoints[i]->SetIntermediateIndex(static_cast<int8_t>(i < insertIndex ? i : i + 1));
+ prevPoints[i]->SetIntermediateIndex(i < insertIndex ? i : i + 1);
routePoints.NotifyChanges();
}
diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp
index 525d93c768..ce29756235 100644
--- a/map/routing_manager.hpp
+++ b/map/routing_manager.hpp
@@ -46,7 +46,7 @@ struct RoutePointInfo
{
std::string m_name;
RouteMarkType m_markType = RouteMarkType::Start;
- int8_t m_intermediateIndex = 0;
+ size_t m_intermediateIndex = 0;
bool m_isPassed = false;
bool m_isMyPosition = false;
m2::PointD m_position;
@@ -184,15 +184,15 @@ public:
void AddRoutePoint(RouteMarkData && markData);
std::vector<RouteMarkData> GetRoutePoints() const;
size_t GetRoutePointsCount() const;
- void RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
+ void RemoveRoutePoint(RouteMarkType type, size_t intermediateIndex = 0);
void RemoveRoutePoints();
void RemoveIntermediateRoutePoints();
- void MoveRoutePoint(int8_t currentIndex, int8_t targetIndex);
- void MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
- RouteMarkType targetType, int8_t targetIntermediateIndex);
- void HideRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
+ void MoveRoutePoint(size_t currentIndex, size_t targetIndex);
+ void MoveRoutePoint(RouteMarkType currentType, size_t currentIntermediateIndex,
+ RouteMarkType targetType, size_t targetIntermediateIndex);
+ void HideRoutePoint(RouteMarkType type, size_t intermediateIndex = 0);
bool CouldAddIntermediatePoint() const;
- bool IsMyPosition(RouteMarkType type, int8_t intermediateIndex = 0);
+ bool IsMyPosition(RouteMarkType type, size_t intermediateIndex = 0);
void SetRouterImpl(routing::RouterType type);
void RemoveRoute(bool deactivateFollowing);
@@ -202,7 +202,7 @@ public:
storage::TCountriesVec const & absentCountries);
void OnBuildRouteReady(routing::Route const & route, routing::IRouter::ResultCode code);
void OnRebuildRouteReady(routing::Route const & route, routing::IRouter::ResultCode code);
- void OnRoutePointPassed(RouteMarkType type, int8_t intermediateIndex);
+ void OnRoutePointPassed(RouteMarkType type, size_t intermediateIndex);
void OnLocationUpdate(location::GpsInfo & info);
void SetAllowSendingPoints(bool isAllowed)
{
diff --git a/map/routing_mark.cpp b/map/routing_mark.cpp
index 2175e1f7dc..fcf9503d79 100644
--- a/map/routing_mark.cpp
+++ b/map/routing_mark.cpp
@@ -49,7 +49,7 @@ void RouteMarkPoint::SetRoutePointType(RouteMarkType type)
m_markData.m_pointType = type;
}
-void RouteMarkPoint::SetIntermediateIndex(int8_t index)
+void RouteMarkPoint::SetIntermediateIndex(size_t index)
{
SetDirty();
m_markData.m_intermediateIndex = index;
@@ -123,7 +123,7 @@ UserMark * RouteUserMarkContainer::AllocateUserMark(m2::PointD const & ptOrg)
return new RouteMarkPoint(ptOrg, this);
}
-int8_t const RoutePointsLayout::kMaxIntermediatePointsCount = 3;
+size_t const RoutePointsLayout::kMaxIntermediatePointsCount = 3;
RoutePointsLayout::RoutePointsLayout(UserMarksController & routeMarks)
: m_routeMarks(routeMarks)
@@ -139,18 +139,18 @@ RouteMarkPoint * RoutePointsLayout::AddRoutePoint(RouteMarkData && data)
{
if (data.m_pointType == RouteMarkType::Finish)
{
- int const intermediatePointsCount = std::max(static_cast<int>(m_routeMarks.GetUserMarkCount()) - 2, 0);
+ size_t const intermediatePointsCount = std::max(m_routeMarks.GetUserMarkCount() - 2, size_t(0));
sameTypePoint->SetRoutePointType(RouteMarkType::Intermediate);
- sameTypePoint->SetIntermediateIndex(static_cast<int8_t>(intermediatePointsCount));
+ sameTypePoint->SetIntermediateIndex(intermediatePointsCount);
}
else
{
- int const offsetIndex = data.m_pointType == RouteMarkType::Start ? 0 : data.m_intermediateIndex;
+ size_t const offsetIndex = data.m_pointType == RouteMarkType::Start ? 0 : data.m_intermediateIndex;
ForEachIntermediatePoint([offsetIndex](RouteMarkPoint * mark)
{
if (mark->GetIntermediateIndex() >= offsetIndex)
- mark->SetIntermediateIndex(static_cast<int8_t>(mark->GetIntermediateIndex() + 1));
+ mark->SetIntermediateIndex(mark->GetIntermediateIndex() + 1);
});
if (data.m_pointType == RouteMarkType::Start)
@@ -168,7 +168,7 @@ RouteMarkPoint * RoutePointsLayout::AddRoutePoint(RouteMarkData && data)
return newPoint;
}
-bool RoutePointsLayout::RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex)
+bool RoutePointsLayout::RemoveRoutePoint(RouteMarkType type, size_t intermediateIndex)
{
RouteMarkPoint * point = nullptr;
size_t index = 0;
@@ -193,10 +193,10 @@ bool RoutePointsLayout::RemoveRoutePoint(RouteMarkType type, int8_t intermediate
if (type == RouteMarkType::Finish)
{
RouteMarkPoint * lastIntermediate = nullptr;
- int8_t maxIntermediateIndex = -1;
+ size_t maxIntermediateIndex = 0;
ForEachIntermediatePoint([&lastIntermediate, &maxIntermediateIndex](RouteMarkPoint * mark)
{
- if (mark->GetIntermediateIndex() > maxIntermediateIndex)
+ if (lastIntermediate == nullptr || mark->GetIntermediateIndex() > maxIntermediateIndex)
{
lastIntermediate = mark;
maxIntermediateIndex = mark->GetIntermediateIndex();
@@ -213,7 +213,7 @@ bool RoutePointsLayout::RemoveRoutePoint(RouteMarkType type, int8_t intermediate
if (mark->GetIntermediateIndex() == 0)
mark->SetRoutePointType(RouteMarkType::Start);
else
- mark->SetIntermediateIndex(static_cast<int8_t>(mark->GetIntermediateIndex() - 1));
+ mark->SetIntermediateIndex(mark->GetIntermediateIndex() - 1);
});
}
else
@@ -221,7 +221,7 @@ bool RoutePointsLayout::RemoveRoutePoint(RouteMarkType type, int8_t intermediate
ForEachIntermediatePoint([point](RouteMarkPoint * mark)
{
if (mark->GetIntermediateIndex() > point->GetIntermediateIndex())
- mark->SetIntermediateIndex(static_cast<int8_t>(mark->GetIntermediateIndex() - 1));
+ mark->SetIntermediateIndex(mark->GetIntermediateIndex() - 1);
});
}
@@ -244,8 +244,8 @@ void RoutePointsLayout::RemoveIntermediateRoutePoints()
}
}
-bool RoutePointsLayout::MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
- RouteMarkType destType, int8_t destIntermediateIndex)
+bool RoutePointsLayout::MoveRoutePoint(RouteMarkType currentType, size_t currentIntermediateIndex,
+ RouteMarkType destType, size_t destIntermediateIndex)
{
RouteMarkPoint * point = GetRoutePoint(currentType, currentIntermediateIndex);
if (point == nullptr)
@@ -261,7 +261,7 @@ bool RoutePointsLayout::MoveRoutePoint(RouteMarkType currentType, int8_t current
return true;
}
-void RoutePointsLayout::PassRoutePoint(RouteMarkType type, int8_t intermediateIndex)
+void RoutePointsLayout::PassRoutePoint(RouteMarkType type, size_t intermediateIndex)
{
RouteMarkPoint * point = GetRoutePoint(type, intermediateIndex);
if (point == nullptr)
@@ -281,7 +281,7 @@ void RoutePointsLayout::SetFollowingMode(bool enabled)
}
}
-RouteMarkPoint * RoutePointsLayout::GetRoutePoint(RouteMarkType type, int8_t intermediateIndex)
+RouteMarkPoint * RoutePointsLayout::GetRoutePoint(RouteMarkType type, size_t intermediateIndex)
{
for (size_t i = 0, sz = m_routeMarks.GetUserMarkCount(); i < sz; ++i)
{
diff --git a/map/routing_mark.hpp b/map/routing_mark.hpp
index 2cdb501298..d9e5e31a5b 100644
--- a/map/routing_mark.hpp
+++ b/map/routing_mark.hpp
@@ -17,7 +17,7 @@ struct RouteMarkData
std::string m_title;
std::string m_subTitle;
RouteMarkType m_pointType = RouteMarkType::Start;
- int8_t m_intermediateIndex = 0;
+ size_t m_intermediateIndex = 0;
bool m_isVisible = true;
bool m_isMyPosition = false;
bool m_isPassed = false;
@@ -42,8 +42,8 @@ public:
RouteMarkType GetRoutePointType() const { return m_markData.m_pointType; }
void SetRoutePointType(RouteMarkType type);
- void SetIntermediateIndex(int8_t index);
- int8_t GetIntermediateIndex() const { return m_markData.m_intermediateIndex; }
+ void SetIntermediateIndex(size_t index);
+ size_t GetIntermediateIndex() const { return m_markData.m_intermediateIndex; }
void SetIsMyPosition(bool isMyPosition);
bool IsMyPosition() const { return m_markData.m_isMyPosition; }
@@ -78,20 +78,20 @@ protected:
class RoutePointsLayout
{
public:
- static int8_t const kMaxIntermediatePointsCount;
+ static size_t const kMaxIntermediatePointsCount;
RoutePointsLayout(UserMarksController & routeMarks);
RouteMarkPoint * AddRoutePoint(RouteMarkData && data);
- RouteMarkPoint * GetRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
+ RouteMarkPoint * GetRoutePoint(RouteMarkType type, size_t intermediateIndex = 0);
std::vector<RouteMarkPoint *> GetRoutePoints();
size_t GetRoutePointsCount() const;
- bool RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
+ bool RemoveRoutePoint(RouteMarkType type, size_t intermediateIndex = 0);
void RemoveRoutePoints();
void RemoveIntermediateRoutePoints();
- bool MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
- RouteMarkType destType, int8_t destIntermediateIndex);
- void PassRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
+ bool MoveRoutePoint(RouteMarkType currentType, size_t currentIntermediateIndex,
+ RouteMarkType destType, size_t destIntermediateIndex);
+ void PassRoutePoint(RouteMarkType type, size_t intermediateIndex = 0);
void SetFollowingMode(bool enabled);
void NotifyChanges();