From 44e48830ddb42e3d8224ff37de78bc6eb4b5a6cd Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 9 Nov 2016 10:27:07 +0300 Subject: [PATCH] Moving SyncOfstream to a separate file. --- generator/generator.pro | 2 ++ generator/osm_source.cpp | 25 +------------------------ generator/osm_source.hpp | 15 +-------------- generator/sync_ofsteam.cpp | 27 +++++++++++++++++++++++++++ generator/sync_ofsteam.hpp | 19 +++++++++++++++++++ 5 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 generator/sync_ofsteam.cpp create mode 100644 generator/sync_ofsteam.hpp diff --git a/generator/generator.pro b/generator/generator.pro index 4c416eeed5..9630f0b0c2 100644 --- a/generator/generator.pro +++ b/generator/generator.pro @@ -44,6 +44,7 @@ SOURCES += \ sponsored_scoring.cpp \ srtm_parser.cpp \ statistics.cpp \ + sync_ofsteam.cpp \ tesselator.cpp \ towns_dumper.cpp \ unpack_mwm.cpp \ @@ -86,6 +87,7 @@ HEADERS += \ sponsored_scoring.hpp \ srtm_parser.hpp \ statistics.hpp \ + sync_ofsteam.cpp \ tag_admixer.hpp \ tesselator.hpp \ towns_dumper.hpp \ diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 14a318ffe7..52163bbaef 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -2,6 +2,7 @@ #include "generator/feature_generator.hpp" #include "generator/intermediate_data.hpp" #include "generator/intermediate_elements.hpp" +#include "generator/sync_ofsteam.hpp" #include "generator/osm_element.hpp" #include "generator/osm_o5m_source.hpp" #include "generator/osm_source.hpp" @@ -533,30 +534,6 @@ private: }; } // anonymous namespace -void SyncOfstream::Open(string const & fullPath) -{ - lock_guard guard(m_mutex); - m_stream.open(fullPath, std::ofstream::out); -} - -bool SyncOfstream::IsOpened() -{ - lock_guard guard(m_mutex); - return m_stream.is_open() && !m_stream.fail(); -} - -void SyncOfstream::Write(uint32_t featureId, vector const & osmIds) -{ - if (!IsOpened()) - return; - - lock_guard guard(m_mutex); - m_stream << featureId; - for (osm::Id const & osmId : osmIds) - m_stream << "," << osmId.OsmId(); - m_stream << endl; -} - unique_ptr MakeMainFeatureEmitter(feature::GenerateInfo const & info) { LOG(LINFO, ("Processing booking data from", info.m_bookingDatafileName, "done.")); diff --git a/generator/osm_source.hpp b/generator/osm_source.hpp index e2added122..cdc23e2d88 100644 --- a/generator/osm_source.hpp +++ b/generator/osm_source.hpp @@ -2,13 +2,11 @@ #include "generator/generate_info.hpp" #include "generator/osm_element.hpp" -#include "generator/osm_id.hpp" -#include "std/fstream.hpp" #include "std/function.hpp" #include "std/iostream.hpp" -#include "std/mutex.hpp" #include "std/unique_ptr.hpp" +#include "std/vector.hpp" class SourceReader { @@ -51,17 +49,6 @@ public: virtual void GetNames(vector & names) const = 0; }; -class SyncOfstream -{ - ofstream m_stream; - mutex m_mutex; - -public: - void Open(string const & fullPath); - bool IsOpened(); - void Write(uint32_t featureId, vector const & osmIds); -}; - unique_ptr MakeMainFeatureEmitter(feature::GenerateInfo const & info); using EmitterFactory = function(feature::GenerateInfo const &)>; diff --git a/generator/sync_ofsteam.cpp b/generator/sync_ofsteam.cpp new file mode 100644 index 0000000000..92b29aae5a --- /dev/null +++ b/generator/sync_ofsteam.cpp @@ -0,0 +1,27 @@ +#include "sync_ofsteam.hpp" + +#include "std/iostream.hpp" + +void SyncOfstream::Open(string const & fullPath) +{ + lock_guard guard(m_mutex); + m_stream.open(fullPath, std::ofstream::out); +} + +bool SyncOfstream::IsOpened() +{ + lock_guard guard(m_mutex); + return m_stream.is_open() && !m_stream.fail(); +} + +void SyncOfstream::Write(uint32_t featureId, vector const & osmIds) +{ + if (!IsOpened()) + return; + + lock_guard guard(m_mutex); + m_stream << featureId; + for (osm::Id const & osmId : osmIds) + m_stream << "," << osmId.OsmId(); + m_stream << endl; +} diff --git a/generator/sync_ofsteam.hpp b/generator/sync_ofsteam.hpp new file mode 100644 index 0000000000..9890eff341 --- /dev/null +++ b/generator/sync_ofsteam.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "generator/osm_id.hpp" + +#include "std/fstream.hpp" +#include "std/mutex.hpp" +#include "std/string.hpp" +#include "std/vector.hpp" + +class SyncOfstream +{ + ofstream m_stream; + mutex m_mutex; + +public: + void Open(string const & fullPath); + bool IsOpened(); + void Write(uint32_t featureId, vector const & osmIds); +};