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

type_utils.hpp « kml - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0887e0737dc50e4a7780a615745583a98b36ed7c (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once

#include "indexer/feature.hpp"

#include "geometry/point2d.hpp"

#include <cstdint>
#include <chrono>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>

namespace kml
{
using Timestamp = std::chrono::time_point<std::chrono::system_clock>;
using LocalizableString = std::unordered_map<int8_t, std::string>;
using LocalizableStringSubIndex = std::map<int8_t, uint32_t>;
using LocalizableStringIndex = std::vector<LocalizableStringSubIndex>;
using Properties = std::map<std::string, std::string>;

using MarkGroupId = uint64_t;
using MarkId = uint64_t;
using TrackId = uint64_t;
using LocalId = uint8_t;

using MarkIdCollection = std::vector<MarkId>;
using TrackIdCollection = std::vector<TrackId>;

using MarkIdSet = std::set<MarkId, std::greater<MarkId>>;
using TrackIdSet = std::set<TrackId>;

using GroupIdCollection = std::vector<MarkGroupId>;
using GroupIdSet = std::set<MarkGroupId>;

MarkGroupId constexpr kInvalidMarkGroupId = std::numeric_limits<MarkGroupId>::max();
MarkId constexpr kInvalidMarkId = std::numeric_limits<MarkId>::max();
TrackId constexpr kInvalidTrackId = std::numeric_limits<TrackId>::max();

inline uint64_t ToSecondsSinceEpoch(Timestamp const & time)
{
  auto const s = std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch());
  return static_cast<uint64_t>(s.count());
}

inline Timestamp FromSecondsSinceEpoch(uint64_t seconds)
{
  return Timestamp(std::chrono::seconds(seconds));
}

inline bool IsEqual(Timestamp const & ts1, Timestamp const & ts2)
{
  return ToSecondsSinceEpoch(ts1) == ToSecondsSinceEpoch(ts2);
}

uint32_t constexpr kEmptyStringId = 0;
double constexpr kMinLineWidth = 0.0;
double constexpr kMaxLineWidth = 100.0;
double constexpr kMinRating = 0.0;
double constexpr kMaxRating = 10.0;
uint8_t constexpr kDoubleBits = 30;

int8_t constexpr kDefaultLangCode = 0;

inline std::string GetDefaultStr(LocalizableString const & str)
{
  return (str.empty() || str.find(kDefaultLangCode) == str.end()) ? "" : str.at(kDefaultLangCode);
}

inline void SetDefaultStr(LocalizableString & localizableStr, std::string const & str)
{
  localizableStr[kDefaultLangCode] = str;
}

extern bool IsEqual(std::vector<m2::PointD> const & v1, std::vector<m2::PointD> const & v2);

struct BookmarkData;
std::string GetPreferredBookmarkName(BookmarkData const & bmData, std::string const & languageOrig);
std::string GetPreferredBookmarkStr(LocalizableString const & name, std::string const & languageNorm);
std::string GetPreferredBookmarkStr(LocalizableString const & name, feature::RegionData const & regionData,
                                    std::string const & languageNorm);
std::string GetLocalizedBookmarkType(std::vector<uint32_t> const & types);

#define DECLARE_COLLECTABLE(IndexType, ...)            \
  IndexType m_collectionIndex;                         \
  template <typename Collector>                        \
  void Collect(Collector & collector)                  \
  {                                                    \
    collector.Collect(m_collectionIndex, __VA_ARGS__); \
  }                                                    \
  void ClearCollectionIndex()                          \
  {                                                    \
    m_collectionIndex.clear();                         \
  }                                                    \

#define VISITOR_COLLECTABLE visitor(m_collectionIndex, "collectionIndex")

#define SKIP_VISITING(Type) void operator()(Type, char const * = nullptr) {}
}  // namespace kml