Welcome to mirror list, hosted at ThFree Co, Russian Federation.

centers_table.hpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 428d9c9dc6ae99131203da76d64498ef1a3e1f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once

#include "coding/geometry_coding.hpp"

#include "geometry/point2d.hpp"

#include "std/cstdint.hpp"
#include "std/unique_ptr.hpp"
#include "std/vector.hpp"

class FilesContainerR;
class Reader;
class Writer;

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                    endianness  2
//
// Version and endianness is always in stored little-endian format.  0
// value of endianness 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_endianness = 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.
  WARN_UNUSED_RESULT 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::GeometryCodingParams const & codingParams);

private:
  virtual bool Init() = 0;
};

class CentersTableBuilder
{
public:
  inline void SetGeometryCodingParams(serial::GeometryCodingParams const & codingParams)
  {
    m_codingParams = codingParams;
  }

  void Put(uint32_t featureId, m2::PointD const & center);
  void Freeze(Writer & writer) const;

private:
  serial::GeometryCodingParams m_codingParams;

  vector<m2::PointU> m_centers;
  vector<uint32_t> m_ids;
};
}  // namespace search