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

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

#include "indexer/index.hpp"

#include "platform/mwm_traits.hpp"

#include "coding/fixed_bits_ddvector.hpp"
#include "coding/reader.hpp"

#include "base/assert.hpp"

#include "defines.hpp"

namespace search
{
namespace v2
{
namespace
{
class Fixed3BitsTable : public HouseToStreetTable
{
public:
  using TVector = FixedBitsDDVector<3, ModelReaderPtr>;

  Fixed3BitsTable(MwmValue & value)
    : m_vector(TVector::Create(value.m_cont.GetReader(SEARCH_ADDRESS_FILE_TAG)))
  {
    ASSERT(m_vector.get(), ("Can't instantiate FixedBitsDDVector."));
  }

  // HouseToStreetTable overrides:
  bool Get(uint32_t houseId, uint32_t & streetIndex) const override
  {
    return m_vector->Get(houseId, streetIndex);
  }

private:
  unique_ptr<TVector> m_vector;
};

class DummyTable : public HouseToStreetTable
{
public:
  // HouseToStreetTable overrides:
  bool Get(uint32_t /* houseId */, uint32_t & /* streetIndex */) const override { return false; }
};
}  // namespace

unique_ptr<HouseToStreetTable> HouseToStreetTable::Load(MwmValue & value)
{
  version::MwmTraits traits(value.GetMwmVersion().GetFormat());
  auto const format = traits.GetHouseToStreetTableFormat();

  unique_ptr<HouseToStreetTable> result;

  try
  {
    if (format == version::MwmTraits::HouseToStreetTableFormat::Fixed3BitsDDVector)
      result.reset(new Fixed3BitsTable(value));
  }
  catch (Reader::OpenException const & ex)
  {
    LOG(LWARNING, (ex.Msg()));
  }

  if (!result)
    result.reset(new DummyTable());
  return result;
}
}  // namespace v2
}  // namespace search