Preventing writing an empty transit section.

This commit is contained in:
Vladimir Byko-Ianko 2017-11-08 10:20:24 +03:00 committed by Tatiana Yan
parent f3cae53fca
commit 9269549766
3 changed files with 33 additions and 7 deletions

View file

@ -6,7 +6,7 @@
#include "routing_common/transit_types.hpp"
#include <std/unique_ptr.hpp>
#include "base/stl_add.hpp"
#include <memory>
#include <string>
@ -357,7 +357,7 @@ unique_ptr<GraphData> CreateGraph()
}
]})";
unique_ptr<GraphData> graph = make_unique<GraphData>();
unique_ptr<GraphData> graph = my::make_unique<GraphData>();
OsmIdToFeatureIdsMap mapping;
mapping[osm::Id(100)] = vector<FeatureId>({10});

View file

@ -86,6 +86,20 @@ private:
bool m_isValid = true;
};
struct IsEmptyVisitor
{
template <typename Cont>
void operator()(Cont const & c, char const * /* name */ )
{
m_isEmpty = m_isEmpty && c.empty();
}
bool IsEmpty() const { return m_isEmpty; }
private:
bool m_isEmpty = true;
};
struct IsUniqueVisitor
{
template <typename Cont>
@ -322,6 +336,13 @@ bool GraphData::IsValid() const
return v.IsValid();
}
bool GraphData::IsEmpty() const
{
IsEmptyVisitor v;
Visit(v);
return v.IsEmpty();
}
void GraphData::Sort()
{
SortVisitor const v{};
@ -443,7 +464,7 @@ void GraphData::ClipLines(vector<m2::RegionD> const & borders)
{
// Set with stop ids with stops which are inside |borders|.
set<StopId> stopIdInsideBorders;
for (auto const s : m_stops)
for (auto const & s : m_stops)
{
if (m2::RegionsContain(borders, s.GetPoint()))
stopIdInsideBorders.insert(s.GetId());
@ -563,7 +584,7 @@ void GraphData::ClipShapes()
// Set with shape ids contained in m_edges.
set<ShapeId> shapeIdInEdges;
for (auto const s : m_edges)
for (auto const & s : m_edges)
shapeIdInEdges.insert(s.GetShapeIds().cbegin(), s.GetShapeIds().cend());
vector<Shape> shapes;
@ -581,9 +602,9 @@ void DeserializeFromJson(OsmIdToFeatureIdsMap const & mapping,
{
Platform::EFileType fileType;
Platform::EError const errCode = Platform::GetFileType(transitJsonPath, fileType);
CHECK_EQUAL(errCode, Platform::EError::ERR_OK, ("Transit graph not found:", transitJsonPath));
CHECK_EQUAL(errCode, Platform::EError::ERR_OK, ("Transit graph is not found:", transitJsonPath));
CHECK_EQUAL(fileType, Platform::EFileType::FILE_TYPE_REGULAR,
("Transit graph not found:", transitJsonPath));
("Transit graph is not found:", transitJsonPath));
string jsonBuffer;
try
@ -638,8 +659,9 @@ void BuildTransit(string const & mwmDir, string const & countryId,
LoadBorders(mwmDir, countryId, mwmBorders);
GraphData jointData;
for (auto const & filePath : graphFiles)
for (auto const & fileName : graphFiles)
{
auto const filePath = my::JoinPath(transitDir, fileName);
LOG(LINFO, ("JSON:", filePath));
GraphData data;
DeserializeFromJson(mapping, filePath, data);
@ -648,6 +670,9 @@ void BuildTransit(string const & mwmDir, string const & countryId,
jointData.AppendTo(data);
}
if (jointData.IsEmpty())
return; // Empty transit section.
ProcessGraph(mwmPath, countryId, mapping, jointData);
CHECK(jointData.IsValid(), (mwmPath, countryId));
jointData.SerializeToMwm(mwmPath);

View file

@ -114,6 +114,7 @@ public:
void AppendTo(GraphData const & rhs);
void Clear();
bool IsValid() const;
bool IsEmpty() const;
/// \brief Sorts all class fields by their ids.
void Sort();