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

storage.hpp « ugc - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bda776f2fc325f51d949be949de935f5d8ad42db (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 "ugc/types.hpp"

#include "geometry/point2d.hpp"

#include "base/thread_checker.hpp"

#include <memory>
#include <string>

class DataSource;
class FeatureType;
struct FeatureID;

namespace feature
{
class TypesHolder;
}

namespace ugc
{
class Storage
{
public:
  explicit Storage(DataSource const & dataSource) : m_dataSource(dataSource) {}

  UGCUpdate GetUGCUpdate(FeatureID const & id) const;

  enum class SettingResult
  {
    Success,
    InvalidUGC,
    WritingError
  };

  SettingResult SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc);
  bool SaveIndex(std::string const & pathToTargetFile = "") const;
  std::string GetUGCToSend() const;
  void MarkAllAsSynchronized();
  void Defragmentation();
  void Load();
  size_t GetNumberOfUnsynchronized() const;
  bool HasUGCForPlace(uint32_t bestType, m2::PointD const & point) const;

  /// Testing
  UpdateIndexes & GetIndexesForTesting() { return m_indexes; }
  size_t GetNumberOfDeletedForTesting() const { return m_numberOfDeleted; }
  SettingResult SetUGCUpdateForTesting(FeatureID const & id, v0::UGCUpdate const & ugc);
  void LoadForTesting(std::string const & testIndexFilePath);

private:
  void DefragmentationImpl(bool force);
  uint64_t UGCSizeAtIndex(size_t const indexPosition) const;
  std::unique_ptr<FeatureType> GetFeature(FeatureID const & id) const;
  void Migrate(std::string const & indexFilePath);
  UpdateIndexes::const_iterator FindIndex(FeatureID const & id) const;
  UpdateIndexes::const_iterator FindIndex(uint32_t bestType, m2::PointD const & point) const;

  DataSource const & m_dataSource;
  UpdateIndexes m_indexes;
  size_t m_numberOfDeleted = 0;
};

inline std::string DebugPrint(Storage::SettingResult const & result)
{
  switch (result)
  {
  case Storage::SettingResult::Success: return "Success";
  case Storage::SettingResult::InvalidUGC: return "Invalid UGC";
  case Storage::SettingResult::WritingError: return "Writing Error";
  }
  CHECK_SWITCH();
}
}  // namespace ugc

namespace lightweight
{
size_t GetNumberOfUnsentUGC();
}  //namespace lightweight