Code cleanup.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
parent
bfb066d87d
commit
c82ee7b047
6 changed files with 30 additions and 87 deletions
|
@ -1,8 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/serdes_binary_header.hpp"
|
||||
#include "coding/write_to_sink.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -34,6 +32,11 @@ enum class Version : uint8_t
|
|||
// It supports multiline geometry.
|
||||
};
|
||||
|
||||
inline std::string DebugPrint(Version v)
|
||||
{
|
||||
return ::DebugPrint(static_cast<int>(v));
|
||||
}
|
||||
|
||||
struct Header
|
||||
{
|
||||
template <typename Visitor>
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "indexer/classificator_loader.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "coding/file_reader.hpp"
|
||||
#include "coding/file_writer.hpp"
|
||||
#include "coding/hex.hpp"
|
||||
|
@ -19,7 +21,6 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
#include "kml/types.hpp"
|
||||
#include "kml/visitors.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "coding/read_write_utils.hpp"
|
||||
#include "coding/sha1.hpp"
|
||||
#include "coding/text_storage.hpp"
|
||||
|
||||
#include <string>
|
||||
|
@ -262,36 +258,23 @@ private:
|
|||
NonOwningReaderSource source(reader);
|
||||
m_header.Deserialize(source);
|
||||
|
||||
if (m_header.m_version == Version::V8)
|
||||
if (m_header.m_version == Version::V8 || m_header.m_version == Version::V9)
|
||||
{
|
||||
// Check if file has Opensource V8 or MapsMe V8 format.
|
||||
// Actual V8 format has 6 offsets (uint64_t) in header. While V8MM has 5 offsets.
|
||||
// Check if file has Opensource V8/V9 or MapsMe V8/V9 format.
|
||||
// Actual V8/V9 format has 6 offsets (uint64_t) in header. While V8MM/V9MM has 5 offsets.
|
||||
// It means that first section (usually categories) has offset 0x28 = 40 = 5 * 8.
|
||||
if (m_header.m_categoryOffset == 0x28 || m_header.m_bookmarksOffset == 0x28 ||
|
||||
m_header.m_tracksOffset == 0x28 || m_header.m_stringsOffset == 0x28 ||
|
||||
m_header.m_compilationsOffset == 0x28)
|
||||
{
|
||||
LOG(LINFO, ("KMB file has version V8MM"));
|
||||
m_header.m_version = Version::V8MM;
|
||||
m_header.m_eosOffset = m_header.m_stringsOffset;
|
||||
m_header.m_stringsOffset = m_header.m_compilationsOffset;
|
||||
}
|
||||
}
|
||||
if (m_header.m_version == Version::V9)
|
||||
{
|
||||
// Check if file has Opensource V9 or MapsMe V9 format.
|
||||
// Actual V9 format has 6 offsets (uint64_t) in header. While V9MM has 5 offsets.
|
||||
// It means that first section (usually categories) has offset 0x28 = 40 = 5 * 8.
|
||||
if (m_header.m_categoryOffset == 0x28 || m_header.m_bookmarksOffset == 0x28 ||
|
||||
m_header.m_tracksOffset == 0x28 || m_header.m_stringsOffset == 0x28 ||
|
||||
m_header.m_compilationsOffset == 0x28)
|
||||
{
|
||||
LOG(LINFO, ("KMB file has version V9MM"));
|
||||
m_header.m_version = Version::V9MM;
|
||||
m_header.m_version = (m_header.m_version == Version::V8 ? Version::V8MM : Version::V9MM);
|
||||
LOG(LINFO, ("KMB file has version", m_header.m_version));
|
||||
|
||||
m_header.m_eosOffset = m_header.m_stringsOffset;
|
||||
m_header.m_stringsOffset = m_header.m_compilationsOffset;
|
||||
}
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,16 +39,12 @@ void MultiGeometry::FromPoints(std::vector<m2::PointD> const & points)
|
|||
m_lines.push_back(std::move(line));
|
||||
}
|
||||
|
||||
MultiGeometry mergeGeometry(std::vector<MultiGeometry> aGeometries)
|
||||
MultiGeometry mergeGeometry(std::vector<MultiGeometry> && aGeometries)
|
||||
{
|
||||
MultiGeometry merged;
|
||||
for (auto const & geometry : aGeometries)
|
||||
{
|
||||
for (auto const & line : geometry.m_lines)
|
||||
{
|
||||
merged.m_lines.push_back(line);
|
||||
}
|
||||
}
|
||||
for (auto && geometry : aGeometries)
|
||||
for (auto && line : geometry.m_lines)
|
||||
merged.m_lines.push_back(std::move(line));
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
|
|
@ -264,20 +264,20 @@ struct CategoryDataV8MM
|
|||
};
|
||||
|
||||
// FileDataV8MM contains the same sections as FileDataV8 but with no compilations
|
||||
struct FileDataV8MM
|
||||
template <class TrackDataT> struct FileDataMMImpl
|
||||
{
|
||||
DECLARE_VISITOR_AND_DEBUG_PRINT(FileDataV8MM, visitor(m_serverId, "serverId"),
|
||||
DECLARE_VISITOR_AND_DEBUG_PRINT(FileDataMMImpl, visitor(m_serverId, "serverId"),
|
||||
visitor(m_categoryData, "category"),
|
||||
visitor(m_bookmarksData, "bookmarks"),
|
||||
visitor(m_tracksData, "tracks"))
|
||||
|
||||
bool operator==(FileDataV8MM const & data) const
|
||||
bool operator==(FileDataMMImpl const & data) const
|
||||
{
|
||||
return m_serverId == data.m_serverId && m_categoryData == data.m_categoryData &&
|
||||
m_bookmarksData == data.m_bookmarksData && m_tracksData == data.m_tracksData;
|
||||
}
|
||||
|
||||
bool operator!=(FileDataV8MM const & data) const { return !operator==(data); }
|
||||
bool operator!=(FileDataMMImpl const & data) const { return !operator==(data); }
|
||||
|
||||
FileData ConvertToLatestVersion()
|
||||
{
|
||||
|
@ -307,6 +307,9 @@ struct FileDataV8MM
|
|||
// Bookmarks collection.
|
||||
std::vector<BookmarkDataV8MM> m_bookmarksData;
|
||||
// Tracks collection.
|
||||
std::vector<TrackDataV8MM> m_tracksData;
|
||||
std::vector<TrackDataT> m_tracksData;
|
||||
};
|
||||
|
||||
using FileDataV8MM = FileDataMMImpl<TrackDataV8MM>;
|
||||
|
||||
} // namespace kml
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace kml
|
||||
{
|
||||
|
||||
MultiGeometry mergeGeometry(std::vector<MultiGeometry> aGeometries);
|
||||
MultiGeometry mergeGeometry(std::vector<MultiGeometry> && aGeometries);
|
||||
|
||||
struct TrackDataV9MM : TrackDataV8MM
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ struct TrackDataV9MM : TrackDataV8MM
|
|||
|
||||
DECLARE_COLLECTABLE(LocalizableStringIndex, m_name, m_description, m_nearestToponyms, m_properties)
|
||||
|
||||
TrackData ConvertToLatestVersion() const
|
||||
TrackData ConvertToLatestVersion()
|
||||
{
|
||||
TrackData data;
|
||||
data.m_id = m_id;
|
||||
|
@ -36,7 +36,7 @@ struct TrackDataV9MM : TrackDataV8MM
|
|||
data.m_description = m_description;
|
||||
data.m_layers = m_layers;
|
||||
data.m_timestamp = m_timestamp;
|
||||
data.m_geometry = mergeGeometry(m_multiGeometry);
|
||||
data.m_geometry = mergeGeometry(std::move(m_multiGeometry));
|
||||
data.m_visible = m_visible;
|
||||
data.m_nearestToponyms = m_nearestToponyms;
|
||||
data.m_properties = m_properties;
|
||||
|
@ -48,49 +48,6 @@ struct TrackDataV9MM : TrackDataV8MM
|
|||
|
||||
|
||||
// Contains the same sections as FileDataV8MM but with changed m_tracksData format
|
||||
struct FileDataV9MM
|
||||
{
|
||||
DECLARE_VISITOR_AND_DEBUG_PRINT(FileDataV9MM, visitor(m_serverId, "serverId"),
|
||||
visitor(m_categoryData, "category"),
|
||||
visitor(m_bookmarksData, "bookmarks"),
|
||||
visitor(m_tracksData, "tracks"))
|
||||
using FileDataV9MM = FileDataMMImpl<TrackDataV9MM>;
|
||||
|
||||
bool operator==(FileDataV9MM const & data) const
|
||||
{
|
||||
return m_serverId == data.m_serverId && m_categoryData == data.m_categoryData &&
|
||||
m_bookmarksData == data.m_bookmarksData && m_tracksData == data.m_tracksData;
|
||||
}
|
||||
|
||||
bool operator!=(FileDataV9MM const & data) const { return !operator==(data); }
|
||||
|
||||
FileData ConvertToLatestVersion()
|
||||
{
|
||||
FileData data;
|
||||
data.m_deviceId = m_deviceId;
|
||||
data.m_serverId = m_serverId;
|
||||
|
||||
data.m_categoryData = m_categoryData.ConvertToLatestVersion();
|
||||
|
||||
data.m_bookmarksData.reserve(m_bookmarksData.size());
|
||||
for (auto & d : m_bookmarksData)
|
||||
data.m_bookmarksData.emplace_back(d.ConvertToLatestVersion());
|
||||
|
||||
data.m_tracksData.reserve(m_tracksData.size());
|
||||
for (auto & t : m_tracksData)
|
||||
data.m_tracksData.emplace_back(t.ConvertToLatestVersion());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Device id (it will not be serialized in text files).
|
||||
std::string m_deviceId;
|
||||
// Server id.
|
||||
std::string m_serverId;
|
||||
// Category's data.
|
||||
CategoryDataV8MM m_categoryData;
|
||||
// Bookmarks collection.
|
||||
std::vector<BookmarkDataV8MM> m_bookmarksData;
|
||||
// Tracks collection.
|
||||
std::vector<TrackDataV9MM> m_tracksData;
|
||||
};
|
||||
} // namespace kml
|
||||
|
|
Reference in a new issue