8#ifndef INCLUDED_BSLSTL_SYNCBUF
9#define INCLUDED_BSLSTL_SYNCBUF
113#include <bslscm_version.h>
133#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
150template <
class CHAR_TYPE,
class CHAR_TRAITS,
class ALLOCATOR>
152 public BloombergLP::bslstl::SyncBufBase {
155 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
211 const ALLOCATOR&
allocator = ALLOCATOR());
216#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
242#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
310template <
class CHAR,
class TRAITS,
class ALLOCATOR>
314, d_emit_on_sync(false)
320template <
class CHAR,
class TRAITS,
class ALLOCATOR>
324: d_wrapped_p(wrapped)
326, d_emit_on_sync(false)
332template <
class CHAR,
class TRAITS,
class ALLOCATOR>
343#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
344template <
class CHAR,
class TRAITS,
class ALLOCATOR>
346: d_wrapped_p(original.d_wrapped_p)
347, d_mutex_p(original.d_mutex_p)
348, d_emit_on_sync(original.d_emit_on_sync)
349, d_needs_sync(original.d_needs_sync)
350, d_buff(
std::move(original.d_buff))
352 original.d_wrapped_p = 0;
353 original.d_mutex_p = 0;
356template <
class CHAR,
class TRAITS,
class ALLOCATOR>
358 const ALLOCATOR& allocator)
359: d_wrapped_p(original.d_wrapped_p)
360, d_mutex_p(original.d_mutex_p)
361, d_emit_on_sync(original.d_emit_on_sync)
362, d_needs_sync(original.d_needs_sync)
363, d_buff(
std::move(original.d_buff), allocator)
365 original.d_wrapped_p = 0;
366 original.d_mutex_p = 0;
371template <
class CHAR,
class TRAITS,
class ALLOCATOR>
374 if (!this->d_wrapped_p) {
381 BloombergLP::bsls::BslLockGuard lock(this->d_mutex_p);
383#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
384 std::move(d_buff).str();
387 d_buff.
str(String());
389 if (SizeType
size = s.length()) {
390 SizeType n = this->d_wrapped_p->sputn(s.data(),
size);
393 d_buff.
str(MoveUtil::move(s));
397 if (this->d_needs_sync) {
398 this->d_needs_sync =
false;
399 if (this->d_wrapped_p->pubsync() != 0) {
406template <
class CHAR,
class TRAITS,
class ALLOCATOR>
412template <
class CHAR,
class TRAITS,
class ALLOCATOR>
417 d_emit_on_sync = value;
420template <
class CHAR,
class TRAITS,
class ALLOCATOR>
424 set_emit_on_sync(value);
427#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
428template <
class CHAR,
class TRAITS,
class ALLOCATOR>
429basic_syncbuf<CHAR,TRAITS,ALLOCATOR>&
430basic_syncbuf<CHAR,TRAITS,ALLOCATOR>::operator=(basic_syncbuf&& original)
433 if (&original !=
this) {
434 d_buff = std::move(original.d_buff);
435 this->d_wrapped_p = original.d_wrapped_p;
436 this->d_mutex_p = original.d_mutex_p;
437 this->d_emit_on_sync = original.d_emit_on_sync;
438 this->d_needs_sync = original.d_needs_sync;
440 original.d_wrapped_p = 0;
441 original.d_mutex_p = 0;
446template <
class CHAR,
class TRAITS,
class ALLOCATOR>
447void basic_syncbuf<CHAR,TRAITS,ALLOCATOR>::swap(basic_syncbuf& other)
449 BSLS_ASSERT(allocator_traits<ALLOCATOR>::propagate_on_container_swap::value
450 || get_allocator() == other.get_allocator());
451 typedef BloombergLP::bslalg::SwapUtil SwapUtil;
452 streambuf_type::swap(other);
453 SwapUtil::swap(&d_wrapped_p, &other.d_wrapped_p);
454 SwapUtil::swap(&d_mutex_p, &other.d_mutex_p);
455 SwapUtil::swap(&d_emit_on_sync, &other.d_emit_on_sync);
456 SwapUtil::swap(&d_needs_sync, &other.d_needs_sync);
457 d_buff.
swap(other.d_buff);
462template <
class CHAR,
class TRAITS,
class ALLOCATOR>
470template <
class CHAR,
class TRAITS,
class ALLOCATOR>
479template <
class CHAR,
class TRAITS,
class ALLOCATOR>
483 if (!traits_type::eq_int_type(character, traits_type::eof())) {
484 return d_buff.sputc(traits_type::to_char_type(character));
486 return traits_type::eof();
489template <
class CHAR,
class TRAITS,
class ALLOCATOR>
492 this->d_needs_sync =
true;
493 if (this->d_emit_on_sync && !emit()) {
499template <
class CHAR,
class TRAITS,
class ALLOCATOR>
502 std::streamsize count)
504 return d_buff.sputn(inputString, count);
508#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
511template <
class CHAR,
class TRAITS,
class ALLOCATOR>
530template <
class CHAR_TYPE,
class CHAR_TRAITS,
class ALLOCATOR>
Definition bslma_bslallocator.h:580
Definition bslstl_string.h:1281
AllocatorTraits::size_type size_type
Definition bslstl_string.h:1303
Definition bslstl_stringbuf.h:245
void swap(basic_stringbuf &other)
Definition bslstl_stringbuf.h:1586
void str(const StringType &value)
Definition bslstl_stringbuf.h:1538
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by the underlying string to supply memory.
Definition bslstl_stringbuf.h:1629
Definition bslstl_syncbuf.h:152
CHAR_TYPE char_type
Definition bslstl_syncbuf.h:173
std::streamsize xsputn(const char_type *inputString, std::streamsize count) BSLS_KEYWORD_OVERRIDE
Definition bslstl_syncbuf.h:500
void set_emit_on_sync(bool value) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_syncbuf.h:414
ALLOCATOR allocator_type
Definition bslstl_syncbuf.h:178
~basic_syncbuf() BSLS_KEYWORD_OVERRIDE
Call emit. Any exceptions thrown by emit are ignored.
Definition bslstl_syncbuf.h:333
CHAR_TRAITS traits_type
Definition bslstl_syncbuf.h:177
int_type overflow(int_type character=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
Definition bslstl_syncbuf.h:481
int sync() BSLS_KEYWORD_OVERRIDE
Definition bslstl_syncbuf.h:490
CHAR_TRAITS::int_type int_type
Definition bslstl_syncbuf.h:174
std::basic_streambuf< CHAR_TYPE, CHAR_TRAITS > streambuf_type
Definition bslstl_syncbuf.h:180
bool emit()
Definition bslstl_syncbuf.h:372
basic_syncbuf(const ALLOCATOR &allocator=ALLOCATOR())
Definition bslstl_syncbuf.h:311
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used to supply memory.
Definition bslstl_syncbuf.h:464
CHAR_TRAITS::pos_type pos_type
Definition bslstl_syncbuf.h:175
streambuf_type * get_wrapped() const BSLS_KEYWORD_NOEXCEPT
Return the wrapped buffer supplied at construction.
Definition bslstl_syncbuf.h:473
CHAR_TRAITS::off_type off_type
Definition bslstl_syncbuf.h:176
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_CATCH(X)
Definition bsls_exceptionutil.h:372
#define BSLS_TRY
Definition bsls_exceptionutil.h:370
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bdlb_printmethods.h:283
BSLS_KEYWORD_CONSTEXPR_CPP14 TYPE & get(array< TYPE, SIZE > &a) BSLS_KEYWORD_NOEXCEPT
BSLS_KEYWORD_CONSTEXPR size_t size(const TYPE(&)[DIMENSION]) BSLS_KEYWORD_NOEXCEPT
Return the dimension of the specified array argument.
Definition bslstl_iterator.h:1331
BloombergLP::bsls::BslLock SyncBuf_Mutex
Definition bslstl_syncbuf.h:140
Definition balxml_encoderoptions.h:68
Definition bdldfp_decimal.h:5188
Internal mutex-related utils.
Definition bslstl_syncbuf.h:295
static SyncBuf_Mutex * get(void *streambuf) BSLS_KEYWORD_NOEXCEPT
Definition bslma_usesbslmaallocator.h:343