constexpr
size_ts_reserved_buffers = 10;
56 staticconstexpr
size_ts_default_max_writers = 50;
57 staticconstexpr
size_ts_default_buffer_size = 64*1024;
59 usingTBuffersPool = TResourcePool<std::array<char, s_default_buffer_size>>;
60 staticTBuffersPool s_reused_buffers(s_reserved_buffers);
71 voidOpen(std::ostream& o_stream);
78 returnm_filename_delayed;
86std::shared_ptr<CMultiSourceOStreamBuf> NewStreamBuf();
92std::deque<std::shared_ptr<CMultiSourceOStreamBuf>>
m_writers;
93std::atomic<size_t> m_max_writers = s_default_max_writers;
94std::atomic<CMultiSourceOStreamBuf*>
m_head;
97std::condition_variable
m_cv;
99std::atomic<std::ostream*> m_ostream =
nullptr;
114 void Dump(std::ostream& ostr);
116int_type
overflow( int_type ch )
override;
126_other.m_buf =
nullptr;
127_MyBase::set_rdbuf(
m_buf.get());
128_other.set_rdbuf(
nullptr);
134 if(&_other ==
this)
return*
this;
138_MyBase::operator=(std::move(_other));
139 m_buf= std::move(_other.m_buf);
141_MyBase::set_rdbuf(
m_buf.get());
142_other.set_rdbuf(
nullptr);
155_MyBase::set_rdbuf(
nullptr);
185 auto_pptr = _MyBase::pptr();
186 auto_pbase = _MyBase::pbase();
187 size_t size= _pptr - _pbase;
189ostr.write(_pbase,
size);
208setp(
nullptr,
nullptr);
209 return_MyBase::overflow(ch);
223 autonew_stream = std::make_unique<std::ofstream>();
224new_stream->exceptions( ios::failbit | ios::badbit );
225new_stream->open(filename);
233 throwstd::runtime_error(
"already open");
244 throwstd::runtime_error(
"stream is not open");
253 throwstd::runtime_error(
"already open");
269std::unique_lock<std::mutex> lock(
m_mutex);
270 m_cv.wait(lock, [
this]
289std::unique_lock<std::mutex> lock(
m_mutex);
290 m_cv.wait(lock, [
this]
303std::shared_ptr<CMultiSourceOStreamBuf>
buf;
305std::unique_lock<std::mutex> lock(
m_mutex);
306 m_cv.wait(lock, [
this]
312 throwruntime_error(
"CMultiSourceWriter is not open");
314 buf= std::make_shared<CMultiSourceOStreamBuf>(*
this);
328 returns_reused_buffers.Allocate();
336std::unique_lock<std::mutex> lock(
m_mutex);
337 m_cv.wait(lock, [
this, strbuf]
339 boolis_head = strbuf ==
m_head.load();
356std::unique_lock<std::mutex> lock(
m_mutex);
357 m_cv.wait(lock, [
this, strbuf]
359 boolis_head = strbuf ==
m_head.load();
388 m_impl->OpenDelayed(filename);
405 return m_impl->GetFilename();
413 return{
m_impl->NewStreamBuf()};
415 throwstd::runtime_error(
"CMultiSourceWriter is not configured");
421 returnstd::make_unique<CMultiSourceOStream>(
m_impl->NewStreamBuf());
423 throwstd::runtime_error(
"CMultiSourceWriter is not configured");
434 m_impl->SetMaxWriters(num);
447 m_impl= make_unique<CMultiSourceWriterImpl>();
CMultiSourceWriterImpl & m_parent
TBuffersPool::value_type TBuffer
std::atomic< int > m_leftover
~CMultiSourceOStreamBuf()
TBuffersPool::TUniqPointer TBufferPtr
CMultiSourceOStreamBuf(CMultiSourceWriterImpl &parent)
void Dump(std::ostream &ostr)
int_type overflow(int_type ch) override
CMultiSourceOStream & operator=(CMultiSourceOStream &&)
CMultiSourceOStream()=default
std::shared_ptr< CMultiSourceOStreamBuf > m_buf
const std::string & GetFilename() const
void CloseStreamBuf(CMultiSourceOStreamBuf *strbuf, int leftover)
std::unique_ptr< std::ostream > m_own_stream
std::atomic< size_t > m_max_writers
~CMultiSourceWriterImpl()
std::shared_ptr< CMultiSourceOStreamBuf > NewStreamBuf()
void SetMaxWriters(size_t num)
std::atomic< CMultiSourceOStreamBuf * > m_head
TBufferPtr AllocateBuffer()
CMultiSourceWriterImpl(CMultiSourceWriterImpl &&)=delete
std::deque< std::shared_ptr< CMultiSourceOStreamBuf > > m_writers
std::condition_variable m_cv
void Open(const std::string &filename)
TBuffersPool::TUniqPointer TBufferPtr
void OpenDelayed(const std::string &filename)
void FlushStreamBuf(CMultiSourceOStreamBuf *strbuf)
std::string m_filename_delayed
std::atomic< std::ostream * > m_ostream
CMultiSourceWriterImpl(const CMultiSourceWriterImpl &)=delete
std::unique_ptr< CMultiSourceWriterImpl > m_impl
const std::string & GetFilename() const
void OpenDelayed(const std::string &filename)
void Open(std::ostream &o_stream)
void SetMaxWriters(size_t num)
CMultiSourceOStream NewStream()
std::unique_ptr< CMultiSourceOStream > NewStreamPtr()
The NCBI C++ standard methods for dealing with std::string.
static const char * expected[]
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define NCBI_XOBJWRITE_EXPORT
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4