diff options
author | Olga Khlopkova <o.khlopkova@corp.mail.ru> | 2020-06-18 16:51:16 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2020-06-19 17:06:31 +0300 |
commit | c982258aeb1df1c53b94e961b4027ed7af38c3e3 (patch) | |
tree | 9f095573a06ca0dd8c1e9faf67056ef7d669c66c /transit/transit_serdes.hpp | |
parent | fe0caf070da48b62cc70c47762a36e7ea642965b (diff) |
[generator][transit] Ser/des for new transit section.
Diffstat (limited to 'transit/transit_serdes.hpp')
-rw-r--r-- | transit/transit_serdes.hpp | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/transit/transit_serdes.hpp b/transit/transit_serdes.hpp index 00fc5acedc..37b25eece3 100644 --- a/transit/transit_serdes.hpp +++ b/transit/transit_serdes.hpp @@ -1,9 +1,8 @@ #pragma once +#include "transit/experimental/transit_types_experimental.hpp" #include "transit/transit_types.hpp" -#include "geometry/point2d.hpp" - #include "coding/geometry_coding.hpp" #include "coding/point_coding.hpp" #include "coding/read_write_utils.hpp" @@ -11,6 +10,8 @@ #include "coding/varint.hpp" #include "coding/write_to_sink.hpp" +#include "geometry/point2d.hpp" + #include "base/assert.hpp" #include "base/exception.hpp" #include "base/macros.hpp" @@ -22,8 +23,11 @@ #include <sstream> #include <string> #include <type_traits> +#include <unordered_map> #include <vector> +#include "3party/opening_hours/opening_hours.hpp" + namespace routing { namespace transit @@ -117,6 +121,19 @@ public: id.Visit(*this); } + void operator()(::transit::experimental::IdBundle const & id, char const * name = nullptr) + { + if (id.SerializeFeatureIdOnly()) + (*this)(id.GetFeatureId(), name); + else + id.Visit(*this); + } + + void operator()(osmoh::OpeningHours const & oh, char const * /* name */ = nullptr) + { + (*this)(ToString(oh)); + } + void operator()(Edge const & e, char const * /* name */ = nullptr) { (*this)(e.m_stop1Id); @@ -153,6 +170,18 @@ public: (*this)(v); } + template <class K, class V> + void operator()(std::unordered_map<K, V> const & container, char const * /* name */ = nullptr) + { + CHECK_LESS_OR_EQUAL(container.size(), std::numeric_limits<uint64_t>::max(), ()); + WriteVarUint(m_sink, static_cast<uint64_t>(container.size())); + for (auto const & [key, val] : container) + { + (*this)(key); + (*this)(val); + } + } + template <typename T> std::enable_if_t<std::is_class<T>::value> operator()(T const & t, char const * /* name */ = nullptr) @@ -240,6 +269,20 @@ public: id.Visit(*this); } + void operator()(::transit::experimental::IdBundle & idBundle, char const * name = nullptr) + { + if (idBundle.SerializeFeatureIdOnly()) + { + FeatureId featureId; + operator()(featureId, name); + idBundle.SetFeatureId(featureId); + idBundle.SetOsmId(kInvalidOsmId); + return; + } + + idBundle.Visit(*this); + } + void operator()(Edge & e, char const * name = nullptr) { (*this)(e.m_stop1Id); @@ -304,6 +347,29 @@ public: (*this)(v); } + template <class K, class V> + void operator()(std::unordered_map<K, V> & container, char const * /* name */ = nullptr) + { + auto const size = static_cast<size_t>(ReadVarUint<uint64_t, Source>(m_source)); + for (size_t i = 0; i < size; ++i) + { + K key; + V val; + + (*this)(key); + (*this)(val); + + container.emplace(key, val); + } + } + + void operator()(osmoh::OpeningHours & oh, char const * /* name */ = nullptr) + { + std::string ohStr; + (*this)(ohStr); + oh = osmoh::OpeningHours(ohStr); + } + template <typename T> std::enable_if_t<std::is_class<T>::value> operator()(T & t, char const * /* name */ = nullptr) { @@ -331,6 +397,11 @@ public: void operator()(TransitHeader const & header) { header.Visit(*this); } + void operator()(::transit::experimental::TransitHeader const & headerExperimental) + { + headerExperimental.Visit(*this); + } + private: Sink & m_sink; }; @@ -350,6 +421,11 @@ public: void operator()(TransitHeader & header) { header.Visit(*this); } + void operator()(::transit::experimental::TransitHeader & headerExperimental) + { + headerExperimental.Visit(*this); + } + private: Source & m_source; }; |