Skip to content

Commit

Permalink
[generator] Removed LogBuffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimandrianov authored and gmoryes committed Dec 16, 2019
1 parent 6dbf745 commit f544be9
Show file tree
Hide file tree
Showing 18 changed files with 8 additions and 203 deletions.
3 changes: 1 addition & 2 deletions generator/complex_generator/complex_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv) {

generator::RawGenerator rawGenerator(genInfo, threadsCount);
auto processor = CreateProcessor(generator::ProcessorType::Complex, rawGenerator.GetQueue(),
genInfo.m_intermediateDir, "" /* layerLogFilename */,
false /* haveBordersForWholeWorld */);
genInfo.m_intermediateDir, false /* haveBordersForWholeWorld */);
auto const cache = std::make_shared<generator::cache::IntermediateData>(genInfo);
auto translator = CreateTranslator(generator::TranslatorType::Complex, processor, cache, genInfo);
auto finalProcessor = std::make_shared<generator::ComplexFinalProcessor>(
Expand Down
44 changes: 0 additions & 44 deletions generator/feature_processing_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,12 @@ void FixLandType(FeatureBuilder & fb)
}
} // namespace

std::string LogBuffer::GetAsString() const
{
return m_buffer.str();
}

void LayerBase::Handle(FeatureBuilder & fb)
{
if (m_next)
m_next->Handle(fb);
}

void LayerBase::Merge(std::shared_ptr<LayerBase> const & other)
{
CHECK(other, ());

m_logBuffer.AppendLine(other->GetAsString());
}

void LayerBase::MergeChain(std::shared_ptr<LayerBase> const & other)
{
CHECK_EQUAL(GetChainSize(), other->GetChainSize(), ());

auto left = shared_from_this();
auto right = other;
while (left && right)
{
left->Merge(right);
left = left->m_next;
right = right->m_next;
}
}

size_t LayerBase::GetChainSize() const
{
size_t size = 0;
Expand Down Expand Up @@ -97,24 +71,6 @@ std::shared_ptr<LayerBase> LayerBase::Add(std::shared_ptr<LayerBase> next)
return next;
}

std::string LayerBase::GetAsString() const
{
return m_logBuffer.GetAsString();
}

std::string LayerBase::GetAsStringRecursive() const
{
std::ostringstream buffer;
auto temp = shared_from_this();
while (temp)
{
buffer << temp->GetAsString();
temp = temp->m_next;
}

return buffer.str();
}

void RepresentationLayer::Handle(FeatureBuilder & fb)
{
auto const sourceType = fb.GetMostGenericOsmId().GetType();
Expand Down
41 changes: 0 additions & 41 deletions generator/feature_processing_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,6 @@ struct GenerateInfo;
namespace generator
{
class PlaceProcessor;
// Responsibility of the class Log Buffer - encapsulation of the buffer for internal logs.
class LogBuffer
{
public:
template <class T, class... Ts>
void AppendLine(T const & value, Ts... rest)
{
AppendImpl(value, rest...);
// The last "\t" is overwritten here
m_buffer.seekp(-1, std::ios_base::end);
m_buffer << "\n";
}

std::string GetAsString() const;

private:
template <class T, class... Ts>
void AppendImpl(T const & value, Ts... rest)
{
m_buffer << value << "\t";
AppendImpl(rest...);
}

void AppendImpl() {}

std::ostringstream m_buffer;
};

// This is the base layer class. Inheriting from it allows you to create a chain of layers.
class LayerBase : public std::enable_shared_from_this<LayerBase>
{
Expand All @@ -63,25 +35,12 @@ class LayerBase : public std::enable_shared_from_this<LayerBase>
// The function works in linear time from the number of layers that exist after that.
virtual void Handle(feature::FeatureBuilder & fb);

void Merge(std::shared_ptr<LayerBase> const & other);
void MergeChain(std::shared_ptr<LayerBase> const & other);

size_t GetChainSize() const;

void SetNext(std::shared_ptr<LayerBase> next);
std::shared_ptr<LayerBase> Add(std::shared_ptr<LayerBase> next);

template <class T, class... Ts>
constexpr void AppendLine(T const & value, Ts... rest)
{
m_logBuffer.AppendLine(value, rest...);
}

std::string GetAsString() const;
std::string GetAsStringRecursive() const;

private:
LogBuffer m_logBuffer;
std::shared_ptr<LayerBase> m_next;
};

Expand Down
2 changes: 0 additions & 2 deletions generator/processor_booking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class ProcessorBooking : public FeatureProcessorInterface

void Finish() override {}

void Merge(FeatureProcessorInterface const &) override { CHECK(false, ()); }

private:
Dataset const & m_dataset;
std::map<base::GeoObjectId, feature::FeatureBuilder> & m_features;
Expand Down
7 changes: 0 additions & 7 deletions generator/processor_coastline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,4 @@ void ProcessorCoastline::Process(feature::FeatureBuilder & feature)
}

void ProcessorCoastline::Finish() { m_affiliationsLayer->AddBufferToQueue(); }

void ProcessorCoastline::Merge(FeatureProcessorInterface const & other) { other.MergeInto(*this); }

void ProcessorCoastline::MergeInto(ProcessorCoastline & other) const
{
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator
3 changes: 0 additions & 3 deletions generator/processor_coastline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class ProcessorCoastline : public FeatureProcessorInterface
void Process(feature::FeatureBuilder & feature) override;
void Finish() override;

void Merge(FeatureProcessorInterface const & other) override;
void MergeInto(ProcessorCoastline & other) const override;

private:
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
Expand Down
24 changes: 2 additions & 22 deletions generator/processor_complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
namespace generator
{
ProcessorComplex::ProcessorComplex(std::shared_ptr<FeatureProcessorQueue> const & queue,
std::string const & bordersPath,
std::string const & layerLogFilename,
bool haveBordersForWholeWorld)
std::string const & bordersPath, bool haveBordersForWholeWorld)
: m_bordersPath(bordersPath)
, m_layerLogFilename(layerLogFilename)
, m_queue(queue)
, m_haveBordersForWholeWorld(haveBordersForWholeWorld)
{
Expand All @@ -28,8 +25,7 @@ ProcessorComplex::ProcessorComplex(std::shared_ptr<FeatureProcessorQueue> const

std::shared_ptr<FeatureProcessorInterface> ProcessorComplex::Clone() const
{
return std::make_shared<ProcessorComplex>(m_queue, m_bordersPath, m_layerLogFilename,
m_haveBordersForWholeWorld);
return std::make_shared<ProcessorComplex>(m_queue, m_bordersPath, m_haveBordersForWholeWorld);
}

void ProcessorComplex::Process(feature::FeatureBuilder & feature)
Expand All @@ -38,20 +34,4 @@ void ProcessorComplex::Process(feature::FeatureBuilder & feature)
}

void ProcessorComplex::Finish() { m_affiliationsLayer->AddBufferToQueue(); }

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

void ProcessorComplex::Merge(FeatureProcessorInterface const & other) { other.MergeInto(*this); }

void ProcessorComplex::MergeInto(ProcessorComplex & other) const
{
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator
9 changes: 1 addition & 8 deletions generator/processor_complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,16 @@ class ProcessorComplex : public FeatureProcessorInterface
{
public:
explicit ProcessorComplex(std::shared_ptr<FeatureProcessorQueue> const & queue,
std::string const & bordersPath, std::string const & layerLogFilename,
bool haveBordersForWholeWorld);
std::string const & bordersPath, bool haveBordersForWholeWorld);

// FeatureProcessorInterface overrides:
std::shared_ptr<FeatureProcessorInterface> Clone() const override;

void Process(feature::FeatureBuilder & feature) override;
void Finish() override;

void Merge(FeatureProcessorInterface const & other) override;
void MergeInto(ProcessorComplex & other) const override;

private:
void WriteDump();

std::string m_bordersPath;
std::string m_layerLogFilename;
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<LayerBase> m_processingChain;
Expand Down
24 changes: 2 additions & 22 deletions generator/processor_country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
namespace generator
{
ProcessorCountry::ProcessorCountry(std::shared_ptr<FeatureProcessorQueue> const & queue,
std::string const & bordersPath,
std::string const & layerLogFilename,
bool haveBordersForWholeWorld)
std::string const & bordersPath, bool haveBordersForWholeWorld)
: m_bordersPath(bordersPath)
, m_layerLogFilename(layerLogFilename)
, m_queue(queue)
, m_haveBordersForWholeWorld(haveBordersForWholeWorld)
{
Expand All @@ -30,8 +27,7 @@ ProcessorCountry::ProcessorCountry(std::shared_ptr<FeatureProcessorQueue> const

std::shared_ptr<FeatureProcessorInterface> ProcessorCountry::Clone() const
{
return std::make_shared<ProcessorCountry>(m_queue, m_bordersPath, m_layerLogFilename,
m_haveBordersForWholeWorld);
return std::make_shared<ProcessorCountry>(m_queue, m_bordersPath, m_haveBordersForWholeWorld);
}

void ProcessorCountry::Process(feature::FeatureBuilder & feature)
Expand All @@ -40,20 +36,4 @@ void ProcessorCountry::Process(feature::FeatureBuilder & feature)
}

void ProcessorCountry::Finish() { m_affiliationsLayer->AddBufferToQueue(); }

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

void ProcessorCountry::Merge(FeatureProcessorInterface const & other) { other.MergeInto(*this); }

void ProcessorCountry::MergeInto(ProcessorCountry & other) const
{
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator
9 changes: 1 addition & 8 deletions generator/processor_country.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,16 @@ class ProcessorCountry : public FeatureProcessorInterface
{
public:
explicit ProcessorCountry(std::shared_ptr<FeatureProcessorQueue> const & queue,
std::string const & bordersPath, std::string const & layerLogFilename,
bool haveBordersForWholeWorld);
std::string const & bordersPath, bool haveBordersForWholeWorld);

// FeatureProcessorInterface overrides:
std::shared_ptr<FeatureProcessorInterface> Clone() const override;

void Process(feature::FeatureBuilder & feature) override;
void Finish() override;

void Merge(FeatureProcessorInterface const & other) override;
void MergeInto(ProcessorCountry & other) const override;

private:
void WriteDump();

std::string m_bordersPath;
std::string m_layerLogFilename;
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<LayerBase> m_processingChain;
Expand Down
19 changes: 0 additions & 19 deletions generator/processor_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ class FeatureParams;

namespace generator
{
class ProcessorCoastline;
class ProcessorCountry;
class ProcessorNoop;
class ProcessorSimple;
class ProcessorWorld;
class ProcessorComplex;

// Implementing this interface allows an object to process FeatureBuilder objects and broadcast
// them.
class FeatureProcessorInterface
Expand All @@ -32,17 +25,5 @@ class FeatureProcessorInterface
// This method is used by OsmTranslator to pass |fb| to Processor for further processing.
virtual void Process(feature::FeatureBuilder & fb) = 0;
virtual void Finish() = 0;

virtual void Merge(FeatureProcessorInterface const &) = 0;

virtual void MergeInto(ProcessorCoastline &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(ProcessorCountry &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(ProcessorNoop &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(ProcessorSimple &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(ProcessorWorld &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(ProcessorComplex &) const { FailIfMethodUnsupported(); }

private:
void FailIfMethodUnsupported() const { CHECK(false, ("This method is unsupported.")); }
};
} // namespace generator
3 changes: 0 additions & 3 deletions generator/processor_noop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ class ProcessorNoop : public FeatureProcessorInterface

void Process(feature::FeatureBuilder &) override {}
void Finish() override {}

void Merge(FeatureProcessorInterface const &) override {}
void MergeInto(ProcessorNoop &) const override {}
};
} // namespace generator
7 changes: 0 additions & 7 deletions generator/processor_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,4 @@ std::shared_ptr<FeatureProcessorInterface> ProcessorSimple::Clone() const
void ProcessorSimple::Process(feature::FeatureBuilder & fb) { m_processingChain->Handle(fb); }

void ProcessorSimple::Finish() { m_affiliationsLayer->AddBufferToQueue(); }

void ProcessorSimple::Merge(FeatureProcessorInterface const & other) { other.MergeInto(*this); }

void ProcessorSimple::MergeInto(ProcessorSimple & other) const
{
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator
3 changes: 0 additions & 3 deletions generator/processor_simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class ProcessorSimple : public FeatureProcessorInterface
void Process(feature::FeatureBuilder & fb) override;
void Finish() override;

void Merge(FeatureProcessorInterface const & other) override;
void MergeInto(ProcessorSimple & other) const override;

std::string GetFilename() const { return m_name; }

private:
Expand Down
7 changes: 0 additions & 7 deletions generator/processor_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,4 @@ void ProcessorWorld::Process(feature::FeatureBuilder & feature)
}

void ProcessorWorld::Finish() { m_affiliationsLayer->AddBufferToQueue(); }

void ProcessorWorld::Merge(FeatureProcessorInterface const & other) { other.MergeInto(*this); }

void ProcessorWorld::MergeInto(ProcessorWorld & other) const
{
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator
3 changes: 0 additions & 3 deletions generator/processor_world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class ProcessorWorld : public FeatureProcessorInterface
void Process(feature::FeatureBuilder & feature) override;
void Finish() override;

void Merge(FeatureProcessorInterface const & other) override;
void MergeInto(ProcessorWorld & other) const override;

private:
std::string m_popularityFilename;
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
Expand Down
2 changes: 1 addition & 1 deletion generator/raw_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::shared_ptr<FeatureProcessorQueue> RawGenerator::GetQueue() { return m_queue

void RawGenerator::GenerateCountries(bool addAds)
{
auto processor = CreateProcessor(ProcessorType::Country, m_queue, m_genInfo.m_targetDir, "",
auto processor = CreateProcessor(ProcessorType::Country, m_queue, m_genInfo.m_targetDir,
m_genInfo.m_haveBordersForWholeWorld);
m_translators->Append(
CreateTranslator(TranslatorType::Country, processor, m_cache, m_genInfo, addAds));
Expand Down
Loading

0 comments on commit f544be9

Please sign in to comment.