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

osm_id.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99f61411e172fb0bf0162fe714a767ee0aaeaee3 (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
#include "osm_id.hpp"

#include "../base/assert.hpp"

#include "../std/sstream.hpp"


namespace osm
{

// Use 3 higher bits to encode type
static const uint64_t NODE = 0x4000000000000000ULL;
static const uint64_t WAY = 0x8000000000000000ULL;
static const uint64_t RELATION = 0xC000000000000000ULL;
static const uint64_t RESET = ~(NODE | WAY | RELATION);

Id::Id(uint64_t encodedId) : m_encodedId(encodedId)
{
}

Id Id::Node(uint64_t id)
{
  return Id( id | NODE );
}

Id Id::Way(uint64_t id)
{
  return Id( id | WAY );
}

Id Id::Relation(uint64_t id)
{
  return Id( id | RELATION );
}

uint64_t Id::OsmId() const
{
  return m_encodedId & RESET;
}

bool Id::IsWay() const
{
  return ((m_encodedId & WAY) == WAY);
}

string Id::Type() const
{
  if ((m_encodedId & RELATION) == RELATION)
    return "relation";
  else if ((m_encodedId & NODE) == NODE)
    return "node";
  else if ((m_encodedId & WAY) == WAY)
    return "way";
  else
    return "ERROR: Not initialized Osm ID";
}

string DebugPrint(osm::Id const & id)
{
  ostringstream stream;
  stream << id.Type() << " " << id.OsmId();
  return stream.str();
}

}  // namespace osm