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

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

#include "generator/city_boundary_processor.hpp"
#include "generator/feature_builder.hpp"
#include "generator/feature_processing_layers.hpp"
#include "generator/generate_info.hpp"

#include "base/logging.hpp"

#include <fstream>

#include "defines.hpp"

namespace generator
{
EmitterCountry::EmitterCountry(feature::GenerateInfo const & info)
  : m_cityBoundaryProcessor(std::make_shared<CityBoundaryProcessor>(info.m_boundariesTable))
  , m_countryMapper(std::make_shared<CountryMapper>(info))
  , m_skippedListFilename(info.GetIntermediateFileName("skipped_elements", ".lst"))
{
  m_processingChain = std::make_shared<RepresentationLayer>(m_cityBoundaryProcessor);
  m_processingChain->Add(std::make_shared<PrepareFeatureLayer>());
  m_processingChain->Add(std::make_shared<CityBoundaryLayer>(m_cityBoundaryProcessor));
  m_processingChain->Add(std::make_shared<BookingLayer>(info.m_bookingDatafileName, m_countryMapper));
  m_processingChain->Add(std::make_shared<OpentableLayer>(info.m_opentableDatafileName, m_countryMapper));
  m_processingChain->Add(std::make_shared<CountryMapperLayer>(m_countryMapper));

  if (info.m_emitCoasts)
  {
    auto const geomFilename = info.GetIntermediateFileName(WORLD_COASTS_FILE_NAME, ".geom");
    auto const worldCoastsFilename = info.GetTmpFileName(WORLD_COASTS_FILE_NAME);
    m_processingChain->Add(std::make_shared<EmitCoastsLayer>(worldCoastsFilename, geomFilename, m_countryMapper));
  }
}

void EmitterCountry::Process(FeatureBuilder1 & feature)
{
  m_processingChain->Handle(feature);
}

bool EmitterCountry::Finish()
{
  for (auto & feature : m_cityBoundaryProcessor->GetFeatures())
    m_countryMapper->RemoveInvalidTypesAndMap(feature);

  WriteDump();
  return true;
}

void EmitterCountry::GetNames(std::vector<std::string> & names) const
{
  names = m_countryMapper->GetNames();
}

void EmitterCountry::WriteDump()
{
  std::ofstream file;
  file.exceptions(std::ios::failbit | std::ios::badbit);
  file.open(m_skippedListFilename);
  file << m_processingChain->GetAsStringRecursive();
  LOG(LINFO, ("Skipped elements were saved to", m_skippedListFilename));
}
}  // namespace generator