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:
-rw-r--r--defines.hpp1
-rw-r--r--generator/transit_generator.cpp37
-rw-r--r--generator/transit_generator.hpp49
-rw-r--r--routing_common/CMakeLists.txt1
-rw-r--r--routing_common/routing_common.pro1
-rw-r--r--routing_common/routing_common_tests/transit_test.cpp40
-rw-r--r--routing_common/transit_serdes.cpp13
-rw-r--r--routing_common/transit_serdes.hpp70
-rw-r--r--routing_common/transit_types.cpp16
-rw-r--r--xcode/routing_common/routing_common.xcodeproj/project.pbxproj5
10 files changed, 108 insertions, 125 deletions
diff --git a/defines.hpp b/defines.hpp
index 1c8111add7..99a4d69207 100644
--- a/defines.hpp
+++ b/defines.hpp
@@ -57,6 +57,7 @@
#define BOOKMARKS_FILE_EXTENSION ".kml"
#define ROUTING_FILE_EXTENSION ".routing"
#define NOROUTING_FILE_EXTENSION ".norouting"
+#define TRANSIT_FILE_EXTENSION ".transit.json"
#define GEOM_INDEX_TMP_EXT ".geomidx.tmp"
#define CELL2FEATURE_SORTED_EXT ".c2f.sorted"
diff --git a/generator/transit_generator.cpp b/generator/transit_generator.cpp
index d4934441db..7db44a62e1 100644
--- a/generator/transit_generator.cpp
+++ b/generator/transit_generator.cpp
@@ -15,20 +15,16 @@
#include "base/logging.hpp"
#include "base/macros.hpp"
-#include "3party/jansson/myjansson.hpp"
+#include "3party/jansson/src/jansson.h"
using namespace platform;
+using namespace routing;
+using namespace routing::transit;
using namespace std;
namespace
{
-using namespace routing;
-using namespace routing::transit;
-
-/// \returns file name without extension by a file path if a file name which have zero, one of several extensions.
-/// For example,
-/// GetFileName("Russia_Nizhny Novgorod Oblast.transit.json") returns "Russia_Nizhny Novgorod Oblast"
-/// GetFileName("Russia_Nizhny Novgorod Oblast.mwm") returns "Russia_Nizhny Novgorod Oblast"
+/// Drops all extensions from the filename.
string GetFileName(string const & filePath)
{
string name = filePath;
@@ -45,7 +41,7 @@ string GetFileName(string const & filePath)
return name;
}
-/// \brief Reads from |root| (json) and serialize an array to |serializer|.
+/// \brief Reads from |root| (json) and serializes an array to |serializer|.
template <class Item>
void SerializeObject(my::Json const & root, string const & key, Serializer<FileWriter> & serializer)
{
@@ -53,9 +49,7 @@ void SerializeObject(my::Json const & root, string const & key, Serializer<FileW
DeserializerFromJson deserializer(root.get());
deserializer(items, key.c_str());
-
- for (auto const & s : items)
- s.Visit(serializer);
+ serializer(items);
}
} // namespace
@@ -66,9 +60,7 @@ namespace transit
// DeserializerFromJson ---------------------------------------------------------------------------
void DeserializerFromJson::operator()(m2::PointD & p, char const * name)
{
- json_t * pointItem = my::GetJSONOptionalField(m_node, name);
- if (pointItem == nullptr)
- return;
+ json_t * pointItem = my::GetJSONObligatoryField(m_node, name);
CHECK(json_is_object(pointItem), ());
FromJSONObject(pointItem, "x", p.x);
FromJSONObject(pointItem, "y", p.y);
@@ -81,15 +73,13 @@ void BuildTransit(string const & mwmPath, string const & transitDir)
NOTIMPLEMENTED();
string const countryId = GetFileName(mwmPath);
- LOG(LINFO, ("countryId:", countryId));
-
- string const graphFullPath = my::JoinFoldersToPath(transitDir, countryId + ".transit.json");
+ string const graphFullPath = my::JoinFoldersToPath(transitDir, countryId + TRANSIT_FILE_EXTENSION);
Platform::EFileType fileType;
Platform::EError const errCode = Platform::GetFileType(graphFullPath, fileType);
if (errCode != Platform::EError::ERR_OK || fileType != Platform::EFileType::FILE_TYPE_REGULAR)
{
- LOG(LINFO, ("For mwm:", mwmPath, ".transit.json file not found"));
+ LOG(LINFO, ("For mwm:", mwmPath, TRANSIT_FILE_EXTENSION, "file not found"));
return;
}
@@ -109,9 +99,9 @@ void BuildTransit(string const & mwmPath, string const & transitDir)
LOG(LCRITICAL, ("Can't open", graphFullPath, ex.what()));
}
- // @TODO(bykoianko) If it's necessary to parse an integer jansson parser keeps it to time long long value.
- // It's not good because osm id and stop id are uint64_t. This should be solve before continue writing
- // transit jansson parsing. According to C++ signed long long is not smaller than long and at least 64 bits.
+ // @TODO(bykoianko) If it's necessary to parse an integer jansson parser keeps it in long long value.
+ // It's not good because osm id and stop id are uint64_t. This should be solved before continue writing
+ // transit jansson parsing. According to C++ signed long long is not smaller than long and is at least 64 bits.
// So as a variant before saving to json osm id and stop id should be converted to signed long long and
// then after reading at generator they should be converted back.
// @TODO(bykoianko) |osmId| should be converted to feature id while deserialing from json.
@@ -132,7 +122,6 @@ void BuildTransit(string const & mwmPath, string const & transitDir)
// @TODO(bykoianko) It's necessary to serialize other transit graph data here.
- w.WritePaddingByEnd(8);
header.m_endOffset = base::checked_cast<uint32_t>(w.Pos() - startOffset);
// Rewriting header info.
@@ -140,7 +129,7 @@ void BuildTransit(string const & mwmPath, string const & transitDir)
w.Seek(startOffset);
header.Visit(serializer);
w.Seek(endOffset);
- LOG(LINFO, (TRANSIT_FILE_TAG, "section is ready. The size is", header.m_endOffset));
+ LOG(LINFO, (TRANSIT_FILE_TAG, "section is ready. Size:", header.m_endOffset));
}
} // namespace transit
} // namespace routing
diff --git a/generator/transit_generator.hpp b/generator/transit_generator.hpp
index e14672fd40..b15fef9d60 100644
--- a/generator/transit_generator.hpp
+++ b/generator/transit_generator.hpp
@@ -2,10 +2,13 @@
#include "geometry/point2d.hpp"
+#include "base/macros.hpp"
+
#include "3party/jansson/myjansson.hpp"
#include <cstdint>
#include <string>
+#include <type_traits>
#include <vector>
namespace routing
@@ -17,20 +20,22 @@ class DeserializerFromJson
public:
DeserializerFromJson(json_struct_t * node) : m_node(node) {}
- void operator()(uint8_t & d, char const * name = nullptr) { GetField(d, name); }
- void operator()(uint16_t & d, char const * name = nullptr) { GetField(d, name); }
- void operator()(uint32_t & d, char const * name = nullptr) { GetField(d, name); }
- void operator()(uint64_t & d, char const * name = nullptr) { GetField(d, name); }
- void operator()(double & d, char const * name = nullptr) { GetField(d, name); }
- void operator()(std::string & s, char const * name = nullptr) { GetField(s, name); }
- void operator()(m2::PointD & p, char const * name = nullptr);
+ template<typename T>
+ typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value>::type
+ operator()(T & t, char const * name = nullptr)
+ {
+ GetField(t, name);
+ }
- template <typename R>
- void operator()(R & r, char const * name = nullptr)
+ template<typename T>
+ typename std::enable_if<std::is_floating_point<T>::value>::type operator()(T & t, char const * name = nullptr)
{
- r.Visit(*this);
+ NOTIMPLEMENTED();
}
+ void operator()(std::string & s, char const * name = nullptr) { GetField(s, name); }
+ void operator()(m2::PointD & p, char const * name = nullptr);
+
template <typename T>
void operator()(std::vector<T> & vs, char const * name = nullptr)
{
@@ -49,6 +54,12 @@ public:
}
}
+ template<typename T>
+ typename std::enable_if<std::is_class<T>::value>::type operator()(T & t, char const * name = nullptr)
+ {
+ t.Visit(*this);
+ }
+
private:
template <typename T>
void GetField(T & t, char const * name = nullptr)
@@ -57,21 +68,25 @@ private:
{
// |name| is not set in case of array items
FromJSON(m_node, t);
+ return;
}
- else
+
+ json_struct_t * field = my::GetJSONOptionalField(m_node, name);
+ if (field == nullptr)
{
- json_struct_t * field = my::GetJSONOptionalField(m_node, name);
- if (field == nullptr)
- return; // No field |name| at |m_node|.
- FromJSON(field, t);
+ // No optional field |name| at |m_node|. In that case the default value should be set to |t|.
+ // This default value is set at constructor of corresponding class which is filled with
+ // |DeserializerFromJson|. And the value (|t|) is not changed at this method.
+ return;
}
+ FromJSON(field, t);
}
json_struct_t * m_node;
};
-/// \brief Builds transit section at mwm.
-/// \param mwmPath relative or full path to built mwm. The name of mwm without extension is considered
+/// \brief Builds the transit section in the mwm.
+/// \param mwmPath relative or full path to an mwm. The name of mwm without extension is considered
/// as country id.
/// \param transitDir a path to directory with json files with transit graphs.
void BuildTransit(std::string const & mwmPath, std::string const & transitDir);
diff --git a/routing_common/CMakeLists.txt b/routing_common/CMakeLists.txt
index 9304a8c668..e6939ab95a 100644
--- a/routing_common/CMakeLists.txt
+++ b/routing_common/CMakeLists.txt
@@ -9,7 +9,6 @@ set(
pedestrian_model.cpp
pedestrian_model.hpp
transit_max_speed.hpp
- transit_serdes.cpp
transit_serdes.hpp
transit_types.cpp
transit_types.hpp
diff --git a/routing_common/routing_common.pro b/routing_common/routing_common.pro
index 56fd7525ce..66ab37ad94 100644
--- a/routing_common/routing_common.pro
+++ b/routing_common/routing_common.pro
@@ -25,5 +25,6 @@ HEADERS += \
car_model.hpp \
pedestrian_model.hpp \
transit_max_speed.hpp \
+ transit_serdes.hpp \
transit_types.hpp \
vehicle_model.hpp \
diff --git a/routing_common/routing_common_tests/transit_test.cpp b/routing_common/routing_common_tests/transit_test.cpp
index de0996d73f..732e2e3988 100644
--- a/routing_common/routing_common_tests/transit_test.cpp
+++ b/routing_common/routing_common_tests/transit_test.cpp
@@ -33,30 +33,30 @@ void TestSerialization(Obj const & obj)
TEST(obj.IsEqualForTesting(deserializedObj), ());
}
-UNIT_TEST(ZeroTransitHeaderSerialization)
+UNIT_TEST(Transit_HeaderSerialization)
{
- TransitHeader header;
- TestSerialization(header);
+ {
+ TransitHeader header;
+ TestSerialization(header);
+ }
+ {
+ TransitHeader header(1 /* version */, 1000 /* gatesOffset */, 2000 /* edgesOffset */,
+ 3000 /* transfersOffset */, 4000 /* linesOffset */, 5000 /* shapesOffset */,
+ 6000 /* networksOffset */, 7000 /* endOffset */);
+ TestSerialization(header);
+ }
}
-UNIT_TEST(TransitHeaderSerialization)
+UNIT_TEST(Transit_StopSerialization)
{
- TransitHeader header(1 /* version */, 1000 /* gatesOffset */, 2000 /* edgesOffset */,
- 3000 /* transfersOffset */, 4000 /* linesOffset */, 5000 /* shapesOffset */,
- 6000 /* networksOffset */, 7000 /* endOffset */);
- TestSerialization(header);
-}
-
-UNIT_TEST(ZeroTransitStopSerialization)
-{
- Stop stop;
- TestSerialization(stop);
-}
-
-UNIT_TEST(TransitStopSerialization)
-{
- Stop stop(1234 /* id */, 5678 /* feature id */, 7 /* transfer id */, {7, 8, 9, 10} /* line id */, {55.0, 37.0});
- TestSerialization(stop);
+ {
+ Stop stop;
+ TestSerialization(stop);
+ }
+ {
+ Stop stop(1234 /* id */, 5678 /* feature id */, 7 /* transfer id */, {7, 8, 9, 10} /* line id */, {55.0, 37.0});
+ TestSerialization(stop);
+ }
}
} // namespace
diff --git a/routing_common/transit_serdes.cpp b/routing_common/transit_serdes.cpp
deleted file mode 100644
index 631305e87c..0000000000
--- a/routing_common/transit_serdes.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "routing_common/transit_serdes.hpp"
-
-#include "coding/point_to_integer.hpp"
-
-namespace routing
-{
-namespace transit
-{
-// DeserializerToString ---------------------------------------------------------------------------
-
-
-} // namespace transit
-} // namespace routing
diff --git a/routing_common/transit_serdes.hpp b/routing_common/transit_serdes.hpp
index 0fc2ef650d..5b5a48ca4e 100644
--- a/routing_common/transit_serdes.hpp
+++ b/routing_common/transit_serdes.hpp
@@ -17,6 +17,7 @@
#include <limits>
#include <sstream>
#include <string>
+#include <type_traits>
#include <vector>
namespace routing
@@ -29,11 +30,15 @@ class Serializer
public:
Serializer(Sink & sink) : m_sink(sink) {}
- void operator()(uint8_t const d, char const * /* name */ = nullptr) { WriteToSink(m_sink, d); }
- void operator()(uint16_t const d, char const * /* name */ = nullptr) { WriteToSink(m_sink, d); }
- void operator()(uint32_t const d, char const * /* name */ = nullptr) { WriteToSink(m_sink, d); }
- void operator()(uint64_t const d, char const * /* name */ = nullptr) { WriteToSink(m_sink, d); }
- void operator()(double const d, char const * /* name */ = nullptr)
+ template<typename T>
+ typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value>::type
+ operator()(T const & t, char const * /* name */ = nullptr)
+ {
+ WriteToSink(m_sink, t);
+ }
+
+ template<typename T>
+ typename std::enable_if<std::is_floating_point<T>::value>::type operator()(T const & t, char const * /* name */ = nullptr)
{
NOTIMPLEMENTED();
}
@@ -50,21 +55,21 @@ public:
(*this)(pointU.y);
}
- template <typename R>
- void operator()(R const & r, char const * /* name */ = nullptr)
- {
- r.Visit(*this);
- }
-
template <typename T>
void operator()(std::vector<T> const & vs, char const * /* name */ = nullptr)
{
- CHECK_LESS(vs.size(), std::numeric_limits<uint32_t>::max(), ());
- WriteVarUint(m_sink, static_cast<uint32_t>(vs.size()));
+ CHECK_LESS(vs.size(), std::numeric_limits<uint64_t>::max(), ());
+ WriteVarUint(m_sink, static_cast<uint64_t>(vs.size()));
for (auto const & v : vs)
(*this)(v);
}
+ template<typename T>
+ typename std::enable_if<std::is_class<T>::value>::type operator()(T const & t, char const * /* name */ = nullptr)
+ {
+ t.Visit(*this);
+ }
+
private:
Sink & m_sink;
};
@@ -75,27 +80,15 @@ class Deserializer
public:
Deserializer(Source & source) : m_source(source) {}
- void operator()(uint8_t & d, char const * /* name */ = nullptr)
- {
- ReadPrimitiveFromSource(m_source, d);
- }
-
- void operator()(uint16_t & d, char const * /* name */ = nullptr)
+ template<typename T>
+ typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value>::type
+ operator()(T & t, char const * name = nullptr)
{
- ReadPrimitiveFromSource(m_source, d);
+ ReadPrimitiveFromSource(m_source, t);
}
- void operator()(uint32_t & d, char const * /* name */ = nullptr)
- {
- ReadPrimitiveFromSource(m_source, d);
- }
-
- void operator()(uint64_t & d, char const * /* name */ = nullptr)
- {
- ReadPrimitiveFromSource(m_source, d);
- }
-
- void operator()(double & d, char const * /* name */ = nullptr)
+ template<typename T>
+ typename std::enable_if<std::is_floating_point<T>::value>::type operator()(T & t, char const * name = nullptr)
{
NOTIMPLEMENTED();
}
@@ -113,22 +106,21 @@ public:
p = PointU2PointD(pointU, POINT_COORD_BITS);
}
-
- template <typename R>
- void operator()(R & r, char const * /* name */ = nullptr)
- {
- r.Visit(*this);
- }
-
template <typename T>
void operator()(vector<T> & vs, char const * /* name */ = nullptr)
{
- auto const size = ReadVarUint<uint32_t, Source>(m_source);
+ auto const size = ReadVarUint<uint64_t, Source>(m_source);
vs.resize(size);
for (auto & v : vs)
(*this)(v);
}
+ template<typename T>
+ typename std::enable_if<std::is_class<T>::value>::type operator()(T & t, char const * /* name */ = nullptr)
+ {
+ t.Visit(*this);
+ }
+
private:
Source & m_source;
};
diff --git a/routing_common/transit_types.cpp b/routing_common/transit_types.cpp
index 894e704952..9aebd3b4af 100644
--- a/routing_common/transit_types.cpp
+++ b/routing_common/transit_types.cpp
@@ -37,11 +37,15 @@ void TransitHeader::Reset()
bool TransitHeader::IsEqualForTesting(TransitHeader const & header) const
{
- return m_version == header.m_version && m_reserve == header.m_reserve &&
- m_gatesOffset == header.m_gatesOffset && m_edgesOffset == header.m_edgesOffset &&
- m_transfersOffset == header.m_transfersOffset && m_linesOffset == header.m_linesOffset &&
- m_shapesOffset == header.m_shapesOffset && m_networksOffset == header.m_networksOffset &&
- m_endOffset == header.m_endOffset;
+ return m_version == header.m_version
+ && m_reserve == header.m_reserve
+ && m_gatesOffset == header.m_gatesOffset
+ && m_edgesOffset == header.m_edgesOffset
+ && m_transfersOffset == header.m_transfersOffset
+ && m_linesOffset == header.m_linesOffset
+ && m_shapesOffset == header.m_shapesOffset
+ && m_networksOffset == header.m_networksOffset
+ && m_endOffset == header.m_endOffset;
}
// Stop -------------------------------------------------------------------------------------------
@@ -58,4 +62,4 @@ bool Stop::IsEqualForTesting(Stop const & stop) const
m_lineIds == stop.m_lineIds && my::AlmostEqualAbs(m_point, stop.m_point, kPointsEqualEpsilon);
}
} // namespace transit
-} // namespace routing \ No newline at end of file
+} // namespace routing
diff --git a/xcode/routing_common/routing_common.xcodeproj/project.pbxproj b/xcode/routing_common/routing_common.xcodeproj/project.pbxproj
index 7502158a12..135670eb62 100644
--- a/xcode/routing_common/routing_common.xcodeproj/project.pbxproj
+++ b/xcode/routing_common/routing_common.xcodeproj/project.pbxproj
@@ -12,7 +12,6 @@
5647A4511F72BEB600DE1125 /* libicu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5647A4521F72BEB600DE1125 /* libicu.a */; };
5667C1DD1F751F2700C6B31B /* transit_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5647A4531F72BF2B00DE1125 /* transit_test.cpp */; };
56E2EDA61F7E3F8A0092E9C2 /* transit_serdes.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56E2EDA31F7E3F890092E9C2 /* transit_serdes.hpp */; };
- 56E2EDA71F7E3F8A0092E9C2 /* transit_serdes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56E2EDA41F7E3F890092E9C2 /* transit_serdes.cpp */; };
56E2EDA81F7E3F8A0092E9C2 /* transit_types.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56E2EDA51F7E3F8A0092E9C2 /* transit_types.cpp */; };
56E41D881F72B42F00E28E2D /* transit_types.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56E41D861F72B42F00E28E2D /* transit_types.hpp */; };
671E78881E6A3C5D00B2859B /* bicycle_model.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 671E78801E6A3C5D00B2859B /* bicycle_model.cpp */; };
@@ -48,7 +47,6 @@
5647A4531F72BF2B00DE1125 /* transit_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transit_test.cpp; sourceTree = "<group>"; };
5667C1DE1F751F4200C6B31B /* routing_common.pro */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = routing_common.pro; sourceTree = "<group>"; };
56E2EDA31F7E3F890092E9C2 /* transit_serdes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = transit_serdes.hpp; sourceTree = "<group>"; };
- 56E2EDA41F7E3F890092E9C2 /* transit_serdes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transit_serdes.cpp; sourceTree = "<group>"; };
56E2EDA51F7E3F8A0092E9C2 /* transit_types.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transit_types.cpp; sourceTree = "<group>"; };
56E41D861F72B42F00E28E2D /* transit_types.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = transit_types.hpp; sourceTree = "<group>"; };
671E78721E6A3BE200B2859B /* librouting_common.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = librouting_common.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -138,7 +136,6 @@
671E78741E6A3BE200B2859B /* routing_common */ = {
isa = PBXGroup;
children = (
- 56E2EDA41F7E3F890092E9C2 /* transit_serdes.cpp */,
56E2EDA31F7E3F890092E9C2 /* transit_serdes.hpp */,
56E2EDA51F7E3F8A0092E9C2 /* transit_types.cpp */,
5667C1DE1F751F4200C6B31B /* routing_common.pro */,
@@ -203,7 +200,6 @@
56E2EDA61F7E3F8A0092E9C2 /* transit_serdes.hpp in Headers */,
671E78891E6A3C5D00B2859B /* bicycle_model.hpp in Headers */,
40576F7A1F7AA1B4000B593B /* transit_max_speed.hpp in Headers */,
- 56E41D841F72A64B00E28E2D /* transit_stop.hpp in Headers */,
671E788B1E6A3C5D00B2859B /* car_model.hpp in Headers */,
671E788F1E6A3C5D00B2859B /* vehicle_model.hpp in Headers */,
);
@@ -301,7 +297,6 @@
files = (
56E2EDA81F7E3F8A0092E9C2 /* transit_types.cpp in Sources */,
671E788A1E6A3C5D00B2859B /* car_model.cpp in Sources */,
- 56E2EDA71F7E3F8A0092E9C2 /* transit_serdes.cpp in Sources */,
671E78881E6A3C5D00B2859B /* bicycle_model.cpp in Sources */,
671E788E1E6A3C5D00B2859B /* vehicle_model.cpp in Sources */,
40FF45D01F388EF80046BD40 /* vehicle_model_for_country_test.cpp in Sources */,