diff options
author | vng <viktor.govako@gmail.com> | 2015-08-07 14:43:14 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:59:54 +0300 |
commit | ca342cc8422424e998047cdd00d943db524edced (patch) | |
tree | fc953088dd64fbc17c86909044f28137c8b72cc3 /platform | |
parent | bf973b8c30031be4b8dc29b811a0a7f8d9ae1b51 (diff) |
Moved mm_version.* into “platform” library.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/mwm_version.cpp | 80 | ||||
-rw-r--r-- | platform/mwm_version.hpp | 44 | ||||
-rw-r--r-- | platform/platform.pro | 2 |
3 files changed, 126 insertions, 0 deletions
diff --git a/platform/mwm_version.cpp b/platform/mwm_version.cpp new file mode 100644 index 0000000000..2796860b21 --- /dev/null +++ b/platform/mwm_version.cpp @@ -0,0 +1,80 @@ +#include "mwm_version.hpp" + +#include "coding/file_container.hpp" +#include "coding/reader_wrapper.hpp" +#include "coding/varint.hpp" +#include "coding/writer.hpp" + +#include "base/timer.hpp" + +#include "defines.hpp" + +#include "std/ctime.hpp" + +namespace version +{ +namespace +{ + +char const MWM_PROLOG[] = "MWM"; + +template <class TSource> +void ReadVersionT(TSource & src, MwmVersion & version) +{ + size_t const prologSize = ARRAY_SIZE(MWM_PROLOG); + char prolog[prologSize]; + src.Read(prolog, prologSize); + + if (strcmp(prolog, MWM_PROLOG) != 0) + { + version.format = v2; + version.timestamp = + my::GenerateTimestamp(2011 - 1900 /* number of years since 1900 */, + 10 /* number of month since January */, 1 /* month day */); + return; + } + + // Read format value "as-is". It's correctness will be checked later + // with the correspondent return value. + version.format = static_cast<Format>(ReadVarUint<uint32_t>(src)); + version.timestamp = ReadVarUint<uint32_t>(src); +} +} // namespace + +MwmVersion::MwmVersion() : format(unknownFormat), timestamp(0) {} + +void WriteVersion(Writer & w) +{ + w.Write(MWM_PROLOG, ARRAY_SIZE(MWM_PROLOG)); + + // write inner data version + WriteVarUint(w, static_cast<uint32_t>(lastFormat)); + + // static is used for equal time stamp for all "mwm" files in one generation process + static uint32_t generatorStartTime = my::TodayAsYYMMDD(); + WriteVarUint(w, generatorStartTime); +} + +void ReadVersion(ReaderSrc & src, MwmVersion & version) { ReadVersionT(src, version); } + +bool ReadVersion(FilesContainerR const & container, MwmVersion & version) +{ + if (!container.IsExist(VERSION_FILE_TAG)) + return false; + + ModelReaderPtr versionReader = container.GetReader(VERSION_FILE_TAG); + ReaderSource<ModelReaderPtr> src(versionReader); + ReadVersionT(src, version); + return true; +} + +uint32_t ReadVersionTimestamp(ModelReaderPtr const & reader) +{ + MwmVersion version; + if (!ReadVersion(FilesContainerR(reader), version)) + return 0; + + return version.timestamp; +} + +} // namespace version diff --git a/platform/mwm_version.hpp b/platform/mwm_version.hpp new file mode 100644 index 0000000000..5dd106fed3 --- /dev/null +++ b/platform/mwm_version.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include "std/cstdint.hpp" + +class FilesContainerR; +class ReaderSrc; +class Writer; +class ModelReaderPtr; + +namespace version +{ +enum Format +{ + unknownFormat = -1, + v1 = 0, // April 2011 + v2, // November 2011 (store type index, instead of raw type in mwm) + v3, // March 2013 (store type index, instead of raw type in search data) + v4, // April 2015 (distinguish и and й in search index) + v5, // July 2015 (feature id is the index in vector now). + lastFormat = v5 +}; + +struct MwmVersion +{ + MwmVersion(); + + Format format; + uint32_t timestamp; +}; + +/// Writes latest format and current timestamp to the writer. +void WriteVersion(Writer & w); + +/// Reads mwm version from src. +void ReadVersion(ReaderSrc & src, MwmVersion & version); + +/// \return True when version was successfully parsed from container, +/// otherwise returns false. In the latter case version is +/// unchanged. +bool ReadVersion(FilesContainerR const & container, MwmVersion & version); + +/// Helper function that is usend in FindAllLocalMaps. +uint32_t ReadVersionTimestamp(ModelReaderPtr const & reader); +} // namespace version diff --git a/platform/platform.pro b/platform/platform.pro index d5d88f6489..71be1f2ba2 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -74,6 +74,7 @@ HEADERS += \ local_country_file_utils.hpp \ location.hpp \ measurement_utils.hpp \ + mwm_version.hpp \ platform.hpp \ preferred_languages.hpp \ servers_list.hpp \ @@ -90,6 +91,7 @@ SOURCES += \ local_country_file.cpp \ local_country_file_utils.cpp \ measurement_utils.cpp \ + mwm_version.cpp \ platform.cpp \ preferred_languages.cpp \ servers_list.cpp \ |