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: 204484e04d3627a9d07ce783017a3c6cfa0bdee2 (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
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once

#include "generator/gen_mwm_info.hpp"
#include "generator/osm_element.hpp"

#include "search/cbv.hpp"

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

#include "platform/local_country_file.hpp"

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

#include "geometry/point2d.hpp"

#include "base/logging.hpp"

#include <csignal>
#include <cstdint>
#include <fstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MAIN_WITH_ERROR_HANDLING(func)             \
  int main(int argc, char ** argv)                 \
  {                                                \
    std::signal(SIGABRT, generator::ErrorHandler); \
    std::signal(SIGSEGV, generator::ErrorHandler); \
    return func(argc, argv);                       \
  }

namespace generator
{
void ErrorHandler(int signum);

/// \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; }
  platform::LocalCountryFile const & GetLocalCountryFile() const { return m_countryFile; }
  MwmSet::MwmId const & GetMwmId() const { return m_mwmId; }

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

void LoadDataSource(DataSource & dataSource);

class FeatureGetter
{
public:
  FeatureGetter(std::string const & countryFullPath);

  std::unique_ptr<FeatureType> GetFeatureByIndex(uint32_t index) const;

private:
  SingleMwmDataSource m_mwm;
  std::unique_ptr<FeaturesLoaderGuard> m_guard;
};

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

  mapping.ForEach([&](auto const & p) {
    toDo(p.first /* osm id */, p.second /* feature id */);
  });
  return true;
}

bool ParseFeatureIdToOsmIdMapping(std::string const & path,
                                  std::unordered_map<uint32_t, base::GeoObjectId> & mapping);
bool ParseFeatureIdToTestIdMapping(std::string const & path,
                                   std::unordered_map<uint32_t, uint64_t> & mapping);

search::CBV GetLocalities(std::string const & dataPath);

struct MapcssRule
{
  bool Matches(std::vector<OsmElement::Tag> const & tags) const;

  std::vector<OsmElement::Tag> m_tags;
  std::vector<std::string> m_mandatoryKeys;
  std::vector<std::string> m_forbiddenKeys;
};

using TypeStrings = std::vector<std::string>;
using MapcssRules = std::vector<std::pair<TypeStrings, MapcssRule>>;

MapcssRules ParseMapCSS(std::unique_ptr<Reader> reader);

std::ofstream OfstreamWithExceptions(std::string const & name);
}  // namespace generator