Moving SyncOfstream to a separate file.

This commit is contained in:
Vladimir Byko-Ianko 2016-11-09 10:27:07 +03:00
parent ca0432c4a0
commit 44e48830dd
5 changed files with 50 additions and 38 deletions

View file

@ -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 \

View file

@ -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<mutex> guard(m_mutex);
m_stream.open(fullPath, std::ofstream::out);
}
bool SyncOfstream::IsOpened()
{
lock_guard<mutex> guard(m_mutex);
return m_stream.is_open() && !m_stream.fail();
}
void SyncOfstream::Write(uint32_t featureId, vector<osm::Id> const & osmIds)
{
if (!IsOpened())
return;
lock_guard<mutex> guard(m_mutex);
m_stream << featureId;
for (osm::Id const & osmId : osmIds)
m_stream << "," << osmId.OsmId();
m_stream << endl;
}
unique_ptr<EmitterBase> MakeMainFeatureEmitter(feature::GenerateInfo const & info)
{
LOG(LINFO, ("Processing booking data from", info.m_bookingDatafileName, "done."));

View file

@ -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<string> & 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<osm::Id> const & osmIds);
};
unique_ptr<EmitterBase> MakeMainFeatureEmitter(feature::GenerateInfo const & info);
using EmitterFactory = function<unique_ptr<EmitterBase>(feature::GenerateInfo const &)>;

View file

@ -0,0 +1,27 @@
#include "sync_ofsteam.hpp"
#include "std/iostream.hpp"
void SyncOfstream::Open(string const & fullPath)
{
lock_guard<mutex> guard(m_mutex);
m_stream.open(fullPath, std::ofstream::out);
}
bool SyncOfstream::IsOpened()
{
lock_guard<mutex> guard(m_mutex);
return m_stream.is_open() && !m_stream.fail();
}
void SyncOfstream::Write(uint32_t featureId, vector<osm::Id> const & osmIds)
{
if (!IsOpened())
return;
lock_guard<mutex> guard(m_mutex);
m_stream << featureId;
for (osm::Id const & osmId : osmIds)
m_stream << "," << osmId.OsmId();
m_stream << endl;
}

View file

@ -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<osm::Id> const & osmIds);
};