8#ifndef INCLUDED_BSLSTL_SYNCBUF
9#define INCLUDED_BSLSTL_SYNCBUF
115#include <bslscm_version.h>
135#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
152template <
class CHAR_TYPE,
class CHAR_TRAITS,
class ALLOCATOR>
154 public BloombergLP::bslstl::SyncBufBase {
157 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
215 const ALLOCATOR&
allocator = ALLOCATOR());
220#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
246#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
318template <
class CHAR,
class TRAITS,
class ALLOCATOR>
322, d_emit_on_sync(false)
328template <
class CHAR,
class TRAITS,
class ALLOCATOR>
332: d_wrapped_p(wrapped)
334, d_emit_on_sync(false)
340template <
class CHAR,
class TRAITS,
class ALLOCATOR>
351#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
352template <
class CHAR,
class TRAITS,
class ALLOCATOR>
354: d_wrapped_p(original.d_wrapped_p)
355, d_mutex_p(original.d_mutex_p)
356, d_emit_on_sync(original.d_emit_on_sync)
357, d_needs_sync(original.d_needs_sync)
358, d_buff(
std::move(original.d_buff))
360 original.d_wrapped_p = 0;
361 original.d_mutex_p = 0;
364template <
class CHAR,
class TRAITS,
class ALLOCATOR>
366 const ALLOCATOR& allocator)
367: d_wrapped_p(original.d_wrapped_p)
368, d_mutex_p(original.d_mutex_p)
369, d_emit_on_sync(original.d_emit_on_sync)
370, d_needs_sync(original.d_needs_sync)
371, d_buff(
std::move(original.d_buff), allocator)
373 original.d_wrapped_p = 0;
374 original.d_mutex_p = 0;
379template <
class CHAR,
class TRAITS,
class ALLOCATOR>
382 if (!this->d_wrapped_p) {
389 BloombergLP::bsls::BslLockGuard lock(this->d_mutex_p);
391#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
392 std::move(d_buff).str();
395 d_buff.
str(String());
397 if (SizeType size = s.length()) {
398 SizeType n = this->d_wrapped_p->sputn(s.data(), size);
401 d_buff.
str(MoveUtil::move(s));
405 if (this->d_needs_sync) {
406 this->d_needs_sync =
false;
407 if (this->d_wrapped_p->pubsync() != 0) {
414template <
class CHAR,
class TRAITS,
class ALLOCATOR>
420template <
class CHAR,
class TRAITS,
class ALLOCATOR>
425 d_emit_on_sync = value;
428template <
class CHAR,
class TRAITS,
class ALLOCATOR>
432 set_emit_on_sync(value);
435#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
436template <
class CHAR,
class TRAITS,
class ALLOCATOR>
437basic_syncbuf<CHAR,TRAITS,ALLOCATOR>&
438basic_syncbuf<CHAR,TRAITS,ALLOCATOR>::operator=(basic_syncbuf&& original)
441 if (&original !=
this) {
442 d_buff = std::move(original.d_buff);
443 this->d_wrapped_p = original.d_wrapped_p;
444 this->d_mutex_p = original.d_mutex_p;
445 this->d_emit_on_sync = original.d_emit_on_sync;
446 this->d_needs_sync = original.d_needs_sync;
448 original.d_wrapped_p = 0;
449 original.d_mutex_p = 0;
454template <
class CHAR,
class TRAITS,
class ALLOCATOR>
455void basic_syncbuf<CHAR,TRAITS,ALLOCATOR>::swap(basic_syncbuf& other)
457 BSLS_ASSERT(allocator_traits<ALLOCATOR>::propagate_on_container_swap::value
458 || get_allocator() == other.get_allocator());
459 typedef BloombergLP::bslalg::SwapUtil SwapUtil;
460 streambuf_type::swap(other);
461 SwapUtil::swap(&d_wrapped_p, &other.d_wrapped_p);
462 SwapUtil::swap(&d_mutex_p, &other.d_mutex_p);
463 SwapUtil::swap(&d_emit_on_sync, &other.d_emit_on_sync);
464 SwapUtil::swap(&d_needs_sync, &other.d_needs_sync);
465 d_buff.swap(other.d_buff);
470template <
class CHAR,
class TRAITS,
class ALLOCATOR>
478template <
class CHAR,
class TRAITS,
class ALLOCATOR>
487template <
class CHAR,
class TRAITS,
class ALLOCATOR>
491 if (!traits_type::eq_int_type(character, traits_type::eof())) {
492 return d_buff.sputc(traits_type::to_char_type(character));
494 return traits_type::eof();
497template <
class CHAR,
class TRAITS,
class ALLOCATOR>
500 this->d_needs_sync =
true;
501 if (this->d_emit_on_sync && !emit()) {
507template <
class CHAR,
class TRAITS,
class ALLOCATOR>
510 std::streamsize count)
512 return d_buff.sputn(inputString, count);
516#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
519template <
class CHAR,
class TRAITS,
class ALLOCATOR>
538template <
class CHAR_TYPE,
class CHAR_TRAITS,
class ALLOCATOR>
Definition bslma_bslallocator.h:588
Definition bslstl_string.h:1252
AllocatorTraits::size_type size_type
Definition bslstl_string.h:1274
Definition bslstl_stringbuf.h:248
void str(const StringType &value)
Definition bslstl_stringbuf.h:1649
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by the underlying string to supply memory.
Definition bslstl_stringbuf.h:1740
Definition bslstl_syncbuf.h:154
CHAR_TYPE char_type
Definition bslstl_syncbuf.h:177
std::streamsize xsputn(const char_type *inputString, std::streamsize count) BSLS_KEYWORD_OVERRIDE
Definition bslstl_syncbuf.h:508
void set_emit_on_sync(bool value) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_syncbuf.h:422
ALLOCATOR allocator_type
Definition bslstl_syncbuf.h:182
~basic_syncbuf() BSLS_KEYWORD_OVERRIDE
Call emit. Any exceptions thrown by emit are ignored.
Definition bslstl_syncbuf.h:341
CHAR_TRAITS traits_type
Definition bslstl_syncbuf.h:181
int_type overflow(int_type character=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
Definition bslstl_syncbuf.h:489
int sync() BSLS_KEYWORD_OVERRIDE
Definition bslstl_syncbuf.h:498
CHAR_TRAITS::int_type int_type
Definition bslstl_syncbuf.h:178
std::basic_streambuf< CHAR_TYPE, CHAR_TRAITS > streambuf_type
Definition bslstl_syncbuf.h:184
bool emit()
Definition bslstl_syncbuf.h:380
basic_syncbuf(const ALLOCATOR &allocator=ALLOCATOR())
Definition bslstl_syncbuf.h:319
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used to supply memory.
Definition bslstl_syncbuf.h:472
CHAR_TRAITS::pos_type pos_type
Definition bslstl_syncbuf.h:179
streambuf_type * get_wrapped() const BSLS_KEYWORD_NOEXCEPT
Return the wrapped buffer supplied at construction.
Definition bslstl_syncbuf.h:481
CHAR_TRAITS::off_type off_type
Definition bslstl_syncbuf.h:180
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_CATCH(X)
Definition bsls_exceptionutil.h:372
#define BSLS_TRY
Definition bsls_exceptionutil.h:370
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition bdlat_valuetypefunctions.h:939
basic_syncbuf< wchar_t > wsyncbuf
Definition bslstl_iosfwd.h:115
BSLS_KEYWORD_CONSTEXPR_CPP14 TYPE & get(array< TYPE, SIZE > &a) BSLS_KEYWORD_NOEXCEPT
basic_syncbuf< char > syncbuf
Definition bslstl_iosfwd.h:114
CHAR_TRAITS
Definition bslstl_string.h:3917
BloombergLP::bsls::BslLock SyncBuf_Mutex
Definition bslstl_syncbuf.h:142
Definition baljsn_encoder_testtypes.h:76
Definition bdldfp_decimal.h:5549
Definition bslstl_syncbuf.h:302
static SyncBuf_Mutex * get(void *streambuf) BSLS_KEYWORD_NOEXCEPT
Definition bslma_usesbslmaallocator.h:344