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:
authorYuri Gorshenin <y@maps.me>2016-07-18 16:39:49 +0300
committerYuri Gorshenin <y@maps.me>2016-07-22 14:08:44 +0300
commit32af6db6fd63955565a2b26533eb9015ec2f1b56 (patch)
treeb5434fc9024c6039e3bc888e7c31ac253ec5b14e /indexer/centers_table.hpp
parent9c128b3a9f250acefae6c213e6410b9a0cd2368c (diff)
[indexer] Implemented CentersTable.
Diffstat (limited to 'indexer/centers_table.hpp')
-rw-r--r--indexer/centers_table.hpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/indexer/centers_table.hpp b/indexer/centers_table.hpp
new file mode 100644
index 0000000000..7c67eed682
--- /dev/null
+++ b/indexer/centers_table.hpp
@@ -0,0 +1,79 @@
+#pragma once
+
+#include "geometry/point2d.hpp"
+
+#include "std/cstdint.hpp"
+#include "std/unique_ptr.hpp"
+#include "std/vector.hpp"
+
+class Reader;
+class Writer;
+
+namespace serial
+{
+class CodingParams;
+}
+
+namespace search
+{
+// A wrapper class around serialized centers-table.
+//
+// *NOTE* This wrapper is abstract enough so feel free to change it,
+// but note that there should always be backward-compatibility. Thus,
+// when adding new versions, never change data format of old versions.
+//
+// All centers tables are serialized in the following format:
+//
+// File offset (bytes) Field name Field size (bytes)
+// 0 version 2
+// 2 endiannes 2
+//
+// Version and endiannes is always in stored little-endian format. 0
+// value of endiannes means little endian, whereas 1 means big endian.
+class CentersTable
+{
+public:
+ struct Header
+ {
+ void Read(Reader & reader);
+ void Write(Writer & writer);
+ bool IsValid() const;
+
+ uint16_t m_version = 0;
+ uint16_t m_endiannes = 0;
+ };
+
+ static_assert(sizeof(Header) == 4, "Wrong header size");
+
+ virtual ~CentersTable() = default;
+
+ // Tries to get |center| of the feature identified by |id|. Returns
+ // false if table does not have entry for the feature.
+ virtual bool Get(uint32_t id, m2::PointD & center) = 0;
+
+ // Loads CentersTable instance. Note that |reader| must be alive
+ // until the destruction of loaded table. Returns nullptr if
+ // CentersTable can't be loaded.
+ static unique_ptr<CentersTable> Load(Reader & reader, serial::CodingParams const & codingParams);
+
+private:
+ virtual bool Init() = 0;
+};
+
+class CentersTableBuilder
+{
+public:
+ CentersTableBuilder(Writer & writer, serial::CodingParams const & codingParams);
+
+ ~CentersTableBuilder();
+
+ void Put(uint32_t featureId, m2::PointD const & center);
+
+private:
+ Writer & m_writer;
+ serial::CodingParams const & m_codingParams;
+
+ vector<m2::PointU> m_centers;
+ vector<uint32_t> m_ids;
+};
+} // namespace search