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

utils.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00b7d11bc81ad0a543113862f3676404e01e6899 (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
#pragma once

#include "generator/gen_mwm_info.hpp"

#include "indexer/data_source.hpp"
#include "indexer/mwm_set.hpp"

#include "platform/local_country_file.hpp"

#include <string>

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

#include "base/logging.hpp"

#include <string>

namespace generator
{
/// \brief This class is wrapper around |DataSource| if only one mwm is registered in DataSource.
class SingleMwmDataSource
{
public:
  /// \param mwmPath is a path to mwm which should be registerd in DataSource.
  explicit SingleMwmDataSource(std::string const & mwmPath);

  DataSource & GetDataSource() { return m_dataSource; }
  std::string GetPath(MapOptions file) const { return m_countryFile.GetPath(file); }
  MwmSet::MwmId const & GetMwmId() const { return m_mwmId; }

private:
  DataSource m_dataSource;
  platform::LocalCountryFile m_countryFile;
  MwmSet::MwmId m_mwmId;
};

void LoadDataSource(DataSource & dataSource);

template <typename ToDo>
bool ForEachOsmId2FeatureId(std::string const & path, ToDo && toDo)
{
  gen::OsmID2FeatureID mapping;
  try
  {
    FileReader reader(path);
    NonOwningReaderSource source(reader);
    mapping.Read(source);
  }
  catch (FileReader::Exception const & e)
  {
    LOG(LERROR, ("Exception while reading file:", path, ", message:", e.Msg()));
    return false;
  }

  mapping.ForEach([&](gen::OsmID2FeatureID::ValueT const & p) {
    toDo(p.first /* osm id */, p.second /* feature id */);
  });

  return true;
}
}  // namespace generator