BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_ostringstream.h
Go to the documentation of this file.
1/// @file bslstl_ostringstream.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_ostringstream.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_OSTRINGSTREAM
9#define INCLUDED_BSLSTL_OSTRINGSTREAM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_ostringstream bslstl_ostringstream
15/// @brief Provide a C++03-compatible `ostringstream` class.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_ostringstream
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_ostringstream-purpose"> Purpose</a>
25/// * <a href="#bslstl_ostringstream-classes"> Classes </a>
26/// * <a href="#bslstl_ostringstream-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_ostringstream-description"> Description </a>
28/// * <a href="#bslstl_ostringstream-memory-allocation"> Memory Allocation </a>
29/// * <a href="#bslstl_ostringstream-bslma-style-allocators"> bslma-Style Allocators </a>
30/// * <a href="#bslstl_ostringstream-usage"> Usage </a>
31/// * <a href="#bslstl_ostringstream-example-1-basic-output-operations"> Example 1: Basic Output Operations </a>
32///
33/// # Purpose {#bslstl_ostringstream-purpose}
34/// Provide a C++03-compatible `ostringstream` class.
35///
36/// # Classes {#bslstl_ostringstream-classes}
37///
38/// - bsl::ostringstream: C++03-compatible `ostringstream` class
39///
40/// # Canonical Header {#bslstl_ostringstream-canonical-header}
41/// bsl_sstream.h
42///
43/// @see
44///
45/// # Description {#bslstl_ostringstream-description}
46/// This component is for internal use only. Please include
47/// `<bsl_sstream.h>` instead.
48///
49/// This component defines a class template, `bsl::basic_ostringstream`,
50/// implementing a standard output stream that provides a method for obtaining a
51/// `bsl::basic_string`, which contains the characters that have been written to
52/// the stream (see 27.8.4 [ostringstream] of the C++11 standard). This
53/// component also defines two standard aliases, `bsl::ostringstream` and
54/// `bsl::wostringstream`, that refer to specializations of the
55/// `bsl::basic_ostringstream` template for `char` and `wchar_t` types,
56/// respectively. The `bsl::basic_ostringstream` template has three parameters,
57/// `CHAR_TYPE`, `CHAR_TRAITS`, and `ALLOCATOR`. The `CHAR_TYPE` and
58/// `CHAR_TRAITS` parameters respectively define the character type for the
59/// string-stream and a type providing a set of operations the string-stream
60/// will use to manipulate characters of that type, which must meet the
61/// character traits requirements defined by the C++11 standard, 21.2
62/// [char.traits]. The `ALLOCATOR` template parameter is described in the
63/// "Memory Allocation" section below.
64///
65/// ## Memory Allocation {#bslstl_ostringstream-memory-allocation}
66///
67///
68/// The type supplied as a string-stream's `ALLOCATOR` template parameter
69/// determines how that string-stream will allocate memory. The
70/// @ref basic_ostringstream template supports allocators meeting the requirements
71/// of the C++11 standard, 17.6.3.5 [allocator.requirements]; in addition, it
72/// supports scoped-allocators derived from the `bslma::Allocator` memory
73/// allocation protocol. Clients intending to use `bslma`-style allocators
74/// should use `bsl::allocator`, which provides a C++11 standard-compatible
75/// adapter for a `bslma::Allocator` object. Note that the standard aliases
76/// `bsl::ostringstream` and `bsl::wostringstream` both use `bsl::allocator`.
77///
78/// ### bslma-Style Allocators {#bslstl_ostringstream-bslma-style-allocators}
79///
80///
81/// If the type supplied for the `ALLOCATOR` template parameter of an
82/// `ostringstream` instantiation is `bsl::allocator`, then objects of that
83/// string-stream type will conform to the standard behavior of a
84/// `bslma`-allocator-enabled type. Such a string-stream accepts an optional
85/// `bslma::Allocator` argument at construction. If the address of a
86/// `bslma::Allocator` object is explicitly supplied at construction, it will be
87/// used to supply memory for the string-stream throughout its lifetime;
88/// otherwise, the string-stream will use the default allocator installed at the
89/// time of the string-stream's construction (see @ref bslma_default ).
90///
91/// ## Usage {#bslstl_ostringstream-usage}
92///
93///
94/// This section illustrates intended use of this component.
95///
96/// ### Example 1: Basic Output Operations {#bslstl_ostringstream-example-1-basic-output-operations}
97///
98///
99/// The following example demonstrates the use of `bsl::ostringstream` to write
100/// data of various types into a `bsl::string` object.
101///
102/// Suppose we want to implement a simplified converter from a generic type,
103/// `TYPE`, to `bsl::string`. We use `bsl::ostringstream` to implement the
104/// `toString` function. We write the data into the stream with `operator<<`
105/// and then use the `str` method to retrieve the resulting string from the
106/// stream:
107/// @code
108/// template <class TYPE>
109/// bsl::string toString(const TYPE& what)
110/// {
111/// bsl::ostringstream out;
112/// out << what;
113/// return out.str();
114/// }
115/// @endcode
116/// Finally, we verify that our `toString` function works on some simple test
117/// cases:
118/// @code
119/// assert(toString(1234) == "1234");
120///
121/// assert(toString<short>(-5) == "-5");
122///
123/// assert(toString("abc") == "abc");
124/// @endcode
125/// @}
126/** @} */
127/** @} */
128
129/** @addtogroup bsl
130 * @{
131 */
132/** @addtogroup bslstl
133 * @{
134 */
135/** @addtogroup bslstl_ostringstream
136 * @{
137 */
138
139#include <bslscm_version.h>
140
141#include <bslma_isstdallocator.h>
143
144#include <bslmf_enableif.h>
145#include <bslmf_issame.h>
146#include <bslmf_movableref.h>
147
149#include <bsls_keyword.h>
150#include <bsls_libraryfeatures.h>
151#include <bsls_platform.h>
152
153#include <bslstl_string.h>
154#include <bslstl_stringview.h>
155#include <bslstl_stringbuf.h>
157
158#include <ios>
159
160#include <ostream>
161
162#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
163# include <utility>
164#endif
165
166namespace bsl {
167
168 // =========================
169 // class basic_ostringstream
170 // =========================
171
172/// This class implements a standard output stream that provides an accessor
173/// for obtaining a `bsl::basic_string` containing the sequence of
174/// characters that have been written to the stream.
175template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
177 : private StringBufContainer<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>
178 , public std::basic_ostream<CHAR_TYPE, CHAR_TRAITS> {
179
180 private:
181 // PRIVATE TYPES
184 BaseType;
187 typedef std::basic_ostream<CHAR_TYPE, CHAR_TRAITS> BaseStream;
188 typedef std::ios_base ios_base;
189
190 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
191
192 private:
193 // NOT IMPLEMENTED
194 basic_ostringstream(const basic_ostringstream&); // = delete
195 basic_ostringstream& operator=(const basic_ostringstream&); // = delete
196
197 public:
198 // TYPES
199 typedef CHAR_TYPE char_type;
201 typedef ALLOCATOR allocator_type;
202 typedef typename traits_type::int_type int_type;
203 typedef typename traits_type::off_type off_type;
204 typedef typename traits_type::pos_type pos_type;
205
206 // CREATORS
207
208 /// Create a @ref basic_ostringstream object. Optionally specify a
209 /// `modeBitMask` indicating whether the underlying stream-buffer may
210 /// also be read from (`rdbuf` is created using
211 /// `modeBitMask | ios_base::out`). If `modeBitMask` is not supplied,
212 /// `rdbuf` will be created using `ios_base::out`. Optionally specify
213 /// an `initialString` indicating the value that will be returned by a
214 /// call to `str` prior to any streaming operations performed on this
215 /// object. If `initialString` is not supplied, `str` will initially
216 /// return an empty string. Optionally specify the `allocator` used to
217 /// supply memory. If `allocator` is not supplied, a
218 /// default-constructed object of the (template parameter) `ALLOCATOR`
219 /// type is used. If the `ALLOCATOR` argument is of type
220 /// `bsl::allocator` (the default), then `allocator`, if supplied,
221 /// shall be convertible to `bslma::Allocator *`. If the `ALLOCATOR`
222 /// argument is of type `bsl::allocator` and `allocator` is not
223 /// supplied, the currently installed default allocator will be used to
224 /// supply memory.
225 explicit
227 explicit
228 basic_ostringstream(ios_base::openmode modeBitMask,
230 explicit
231 basic_ostringstream(const StringType& initialString,
233 basic_ostringstream(const StringType& initialString,
234 ios_base::openmode modeBitMask,
236
237 /// Create a @ref basic_ostringstream object. Use the specified
238 /// `initialString` indicating the value that will be returned by a call
239 /// to `str` prior to any streaming operations performed on this object.
240 /// Optionally specify a `modeBitMask` indicating whether the underlying
241 /// stream-buffer may also be read from (`rdbuf` is created using
242 /// `modeBitMask | ios_base::out`). If `modeBitMask` is not supplied,
243 /// `rdbuf` will be created using `ios_base::out`. Optionally specify
244 /// the `allocator` used to supply memory. If `allocator` is not
245 /// supplied, the allocator in `initialString` is used. `initialString`
246 /// is left in a valid but unspecified state.
247 explicit
249 BloombergLP::bslmf::MovableRef<StringType> initialString);
251 BloombergLP::bslmf::MovableRef<StringType> initialString,
254 BloombergLP::bslmf::MovableRef<StringType> initialString,
255 ios_base::openmode modeBitMask);
257 BloombergLP::bslmf::MovableRef<StringType> initialString,
258 ios_base::openmode modeBitMask,
260
261 /// Create a @ref basic_ostringstream object. Use the specified
262 /// `initialString` as the value that will be returned by a call to
263 /// `str` prior to any streaming operations performed on this object.
264 /// `rdbuf` is created using `ios_base::out`. Optionally specify the
265 /// `allocator` used to supply memory. If `allocator` is not supplied,
266 /// a default-constructed object of the (template parameter) `ALLOCATOR`
267 /// type is used. If the `ALLOCATOR` argument is of type
268 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
269 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
270 /// is of type `bsl::allocator` and `allocator` is not supplied, the
271 /// currently installed default allocator will be used to supply memory.
272 template <class SALLOC>
275 initialString,
277 typename bsl::enable_if<
278 !bsl::is_same<ALLOCATOR, SALLOC>::value, void *>::type = 0)
279 : BaseType(initialString.begin(),
280 initialString.end(),
281 ios_base::out,
282 allocator)
283 , BaseStream(BaseType::rdbuf())
284 {
285 // Note: implemented inline due to Sun CC compilation error.
286 }
287
288 /// Create a @ref basic_ostringstream object. Use the specified
289 /// `initialString` as the value that will be returned by a call to
290 /// `str` prior to any streaming operations performed on this object.
291 /// Use the specified `modeBitMask` to indicate whether the underlying
292 /// stream-buffer may also be read from (`rdbuf` is created using
293 /// `modeBitMask | ios_base::out`). Optionally specify the `allocator`
294 /// used to supply memory. If `allocator` is not supplied, a
295 /// default-constructed object of the (template parameter) `ALLOCATOR`
296 /// type is used. If the `ALLOCATOR` argument is of type
297 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
298 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
299 /// is of type `bsl::allocator` and `allocator` is not supplied, the
300 /// currently installed default allocator will be used to supply memory.
301 template <class SALLOC>
304 initialString,
305 ios_base::openmode modeBitMask,
307 typename bsl::enable_if<
308 !bsl::is_same<ALLOCATOR, SALLOC>::value, void *>::type = 0)
309 : BaseType(initialString.begin(),
310 initialString.end(),
311 modeBitMask | ios_base::out,
312 allocator)
313 , BaseStream(BaseType::rdbuf())
314 {
315 // Note: implemented inline due to Sun CC compilation error.
316 }
317
318 /// Create a @ref basic_ostringstream object. Use the specified
319 /// `initialString` (of a type convertible to
320 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
321 /// `const CHAR_TYPE *`) indicating the initial sequence of characters
322 /// that have been written to this stream. `rdbuf` is created using
323 /// `ios_base::out`. Optionally specify the `allocator` used to supply
324 /// memory. If `allocator` is not supplied, a default-constructed
325 /// object of the (template parameter) `ALLOCATOR` type is used. If the
326 /// `ALLOCATOR` argument is of type `bsl::allocator` (the default), then
327 /// `allocator`, if supplied, shall be convertible to
328 /// `bslma::Allocator *`. If the `ALLOCATOR` argument is of type
329 /// `bsl::allocator` and `allocator` is not supplied, the currently
330 /// installed default allocator will be used to supply memory.
331 template <class STRING_VIEW_LIKE_TYPE>
332 explicit
334 const STRING_VIEW_LIKE_TYPE& initialString,
337 : BaseType(initialString, ios_base::out, allocator)
338 , BaseStream(BaseType::rdbuf())
339 {
340 // Note: implemented inline due to Sun CC compilation error.
341 }
342
343 /// Create a @ref basic_ostringstream object. Use the specified
344 /// `initialString` (of a type convertible to
345 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
346 /// `const CHAR_TYPE *`) indicating the initial sequence of characters
347 /// that have been written to this stream. Use the specified
348 /// `modeBitMask` to indicate whether this buffer may be read from,
349 /// written to, or both. `rdbuf` is created using
350 /// `modeBitMask | ios_base::out`. Optionally specify the `allocator`
351 /// used to supply memory. If `allocator` is not supplied, a
352 /// default-constructed object of the (template parameter) `ALLOCATOR`
353 /// type is used. If the `ALLOCATOR` argument is of type
354 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
355 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
356 /// is of type `bsl::allocator` and `allocator` is not supplied, the
357 /// currently installed default allocator will be used to supply memory.
358 template <class STRING_VIEW_LIKE_TYPE>
360 const STRING_VIEW_LIKE_TYPE& initialString,
361 ios_base::openmode modeBitMask,
364 : BaseType(initialString, modeBitMask | ios_base::out, allocator)
365 , BaseStream(BaseType::rdbuf())
366 {
367 // Note: implemented inline due to Sun CC compilation error.
368 }
369
370#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
371 /// Create a @ref basic_ostringstream object having the same value as the
372 /// specified `original` object by moving the contents of `original` to
373 /// the newly-created object. Optionally specify the `allocator` used
374 /// to supply memory. `original` is left in a valid but unspecified
375 /// state.
376// NOLINTNEXTLINE(performance-noexcept-move-constructor)
380#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
381
383 // Destroy this object.
384
385 // MANIPULATORS
386#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
387 /// Assign to this object the value of the specified `rhs`, and return a
388 /// reference providing modifiable access to this object. The contents
389 /// of `rhs` are move-assigned to this object. `rhs` is left in a valid
390 /// but unspecified state.
391// NOLINTNEXTLINE(performance-noexcept-move-constructor)
393#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
394
395 /// Reset the internally buffered sequence of characters maintained by
396 /// this stream object to the specified `value`. If `value` is passed
397 /// by `MovableRef`, it is left in a valid but unspecified state.
398 void str(const StringType& value);
399 void str(BloombergLP::bslmf::MovableRef<StringType> value);
400 template <class SALLOC>
401 typename
404 {
405 // Note: implemented inline due to Sun CC compilation error.
406 return this->rdbuf()->str(value);
407 }
408
409 /// Reset the internally buffered sequence of characters maintained by
410 /// this stream object to the specified `value` (of a type convertible
411 /// to `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
412 /// `const CHAR_TYPE *`).
413 template <class STRING_VIEW_LIKE_TYPE>
415 str(const STRING_VIEW_LIKE_TYPE& value)
416 {
417 // Note: implemented inline due to Sun CC compilation error.
418 this->rdbuf()->str(value);
419 }
420
421#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
422 /// Return the internally buffered sequence of characters maintained by
423 /// this stream, leaving the stream empty.
424 StringType str() &&;
425#endif // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
426
427#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
428 /// Efficiently exchange the value of this object with the value of the
429 /// specified `other` object. This method provides the no-throw
430 /// exception-safety guarantee if `*this` and `other` allocators compare equal.
431 ///
432 /// \pre The behavior is undefined unless either `*this` and `other`
433 /// allocators compare equal or @ref propagate_on_container_swap is `true`.
434 ///
435 /// \note Note that this function is only available for C++11 (and later)
436 /// language standards because it requires that `swap` be provided on
437 /// the (platform supplied) base class for this type.
438// NOLINTNEXTLINE(performance-noexcept-swap)
439 void swap(basic_ostringstream& other);
440#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
441
442 // ACCESSORS
443
444 /// Return the allocator used by the underlying buffer to supply memory.
446
447 /// Return an address providing modifiable access to the
448 /// @ref basic_stringbuf object that is internally used by this string
449 /// stream to buffer unformatted characters.
450 StreamBufType *rdbuf() const;
451
452#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
453 StringType str() const &;
454#else
455 StringType str() const;
456#endif
457 // Return the internally buffered sequence of characters maintained by
458 // this stream object.
459
460#ifndef BSLS_PLATFORM_CMP_SUN
461 // To be enabled once DRQS 168075157 is resolved
462
463 /// Return a copy of the internally buffered sequence of characters
464 /// maintained by this stream object in a @ref basic_string that uses the
465 /// specified `allocator`.
466 template <class SALLOC>
467 typename bsl::enable_if<
468 bsl::IsStdAllocator<SALLOC>::value,
470 str(const SALLOC& allocator) const
471 {
472 // Note: implemented inline due to Sun CC compilation error.
473 return this->rdbuf()->str(allocator);
474 }
475#endif // BSLS_PLATFORM_CMP_SUN
476
477 /// Return a view of the internally buffered sequence of characters
478 /// maintained by this stream object.
479 ViewType view() const BSLS_KEYWORD_NOEXCEPT;
480};
481
482// FREE FUNCTIONS
483#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) \
484 && defined(BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE)
485/// Efficiently exchange the values of the specified `a` and `b` objects.
486/// This method provides the no-throw exception-safety guarantee if `a` and `b` allocators compare equal.
487///
488/// \note Note that this function is only available
489/// for C++11 (and later) language standards.
490template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
491// NOLINTNEXTLINE(performance-noexcept-swap)
494#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY && CPP11_STREAM_MOVE
495
496// STANDARD TYPEDEFS
501
502} // close namespace bsl
503
504// TYPE TRAITS
505
506namespace bslma {
507
508template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
510 bsl::basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR> >
512{};
513
514} // close namespace bslma
515
516
517namespace bsl {
518
519// ============================================================================
520// TEMPLATE FUNCTION DEFINITIONS
521// ============================================================================
522
523 // -------------------------
524 // class basic_ostringstream
525 // -------------------------
526
527// CREATORS
528template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
529inline
532: BaseType(ios_base::out, allocator)
533, BaseStream(BaseType::rdbuf())
534{
535}
536
537template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
538inline
540basic_ostringstream(ios_base::openmode modeBitMask,
542: BaseType(modeBitMask | ios_base::out, allocator)
543, BaseStream(BaseType::rdbuf())
544{
545}
546
547template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
548inline
550basic_ostringstream(const StringType& initialString,
552: BaseType(initialString, ios_base::out, allocator)
553, BaseStream(BaseType::rdbuf())
554{
555}
556
557template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
558inline
560basic_ostringstream(const StringType& initialString,
561 ios_base::openmode modeBitMask,
563: BaseType(initialString, modeBitMask | ios_base::out, allocator)
564, BaseStream(BaseType::rdbuf())
565{
566}
567
568template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
569inline
571basic_ostringstream(BloombergLP::bslmf::MovableRef<StringType> initialString)
572: BaseType(MoveUtil::move(initialString), ios_base::out)
573, BaseStream(BaseType::rdbuf())
574{
575}
576
577template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
578inline
580basic_ostringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
582: BaseType(MoveUtil::move(initialString), ios_base::out, allocator)
583, BaseStream(BaseType::rdbuf())
584{
585}
586
587template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
588inline
590basic_ostringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
591 ios_base::openmode modeBitMask)
592: BaseType(MoveUtil::move(initialString), modeBitMask | ios_base::out)
593, BaseStream(BaseType::rdbuf())
594{
595}
596
597template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
598inline
600basic_ostringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
601 ios_base::openmode modeBitMask,
603: BaseType(MoveUtil::move(initialString),
604 modeBitMask | ios_base::out,
605 allocator)
606, BaseStream(BaseType::rdbuf())
607{
608}
609
610#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
611template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
612inline
614// NOLINTNEXTLINE(performance-noexcept-move-constructor)
616: BaseType(std::move(original))
617, BaseStream(std::move(original))
618{
619 BaseStream::set_rdbuf(BaseType::rdbuf());
620}
621
622template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
623inline
624basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::
625basic_ostringstream(basic_ostringstream&& original,
626 const allocator_type& allocator)
627: BaseType(std::move(original), allocator)
628, BaseStream(std::move(original))
629{
630 BaseStream::set_rdbuf(BaseType::rdbuf());
631}
632#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
633
634// MANIPULATORS
635#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
636template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
637inline
638basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>&
639basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::
640// NOLINTNEXTLINE(performance-noexcept-move-constructor)
641operator=(basic_ostringstream&& rhs)
642{
643 this->BaseType::operator=(std::move(rhs));
644 this->BaseStream::operator=(std::move(rhs));
645
646 return *this;
647}
648#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
649
650template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
651inline
653 const StringType& value)
654{
655 this->rdbuf()->str(value);
656}
657
658template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
659inline
661 BloombergLP::bslmf::MovableRef<StringType> value)
662{
663 this->rdbuf()->str(MoveUtil::move(value));
664}
665
666#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
667template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
668inline
671{
672 return std::move(*this->rdbuf()).str();
673}
674#endif // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
675
676#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
677template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
678inline
679// NOLINTNEXTLINE(performance-noexcept-swap)
680void basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::swap(
681 basic_ostringstream& other)
682{
683#ifdef BSLS_PLATFORM_CMP_GNU
684# pragma GCC diagnostic push
685# pragma GCC diagnostic ignored "-Wstringop-overflow"
686#endif
689 || get_allocator() == other.get_allocator());
690 this->BaseType::swap(other);
691 this->BaseStream::swap(other);
692#ifdef BSLS_PLATFORM_CMP_GNU
693# pragma GCC diagnostic pop
694#endif
695}
696#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
697
698// ACCESSORS
699template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
700inline
707
708template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
709inline
710typename
711 basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::StreamBufType *
713{
714 return this->BaseType::rdbuf();
715}
716
717#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
718template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
719inline
722{
723 return this->rdbuf()->str();
724}
725#else // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
726template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
727inline
728typename basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::StringType
730{
731 return this->rdbuf()->str();
732}
733#endif // else BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
734
735template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
736inline
737typename basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::ViewType
740{
741 return this->rdbuf()->view();
742}
743
744} // close namespace bsl
745
746// FREE FUNCTIONS
747#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) \
748 && defined(BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE)
749template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
750// NOLINTNEXTLINE(performance-noexcept-swap)
751void bsl::swap(basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& a,
752 basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& b)
753{
754 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
755
756 if (a.get_allocator() == b.get_allocator()
758 a.swap(b);
759 }
760 else {
761 basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR> aCopy(
762 MoveUtil::move(a),
763 b.get_allocator());
764 basic_ostringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR> bCopy(
765 MoveUtil::move(b),
766 a.get_allocator());
767 swap(a, bCopy);
768 swap(b, aCopy);
769 }
770}
771#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY && CPP11_STREAM_MOVE
772
773#endif // INCLUDED_BSLSTL_OSTRINGSTREAM
774
775// ----------------------------------------------------------------------------
776// Copyright 2013 Bloomberg Finance L.P.
777//
778// Licensed under the Apache License, Version 2.0 (the "License");
779// you may not use this file except in compliance with the License.
780// You may obtain a copy of the License at
781//
782// http://www.apache.org/licenses/LICENSE-2.0
783//
784// Unless required by applicable law or agreed to in writing, software
785// distributed under the License is distributed on an "AS IS" BASIS,
786// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
787// See the License for the specific language governing permissions and
788// limitations under the License.
789// ----------------------------- END-OF-FILE ----------------------------------
790
791/** @} */
792/** @} */
793/** @} */
Definition bslstl_stringbuf.h:835
Definition bslma_bslallocator.h:588
Definition bslstl_ostringstream.h:178
ALLOCATOR allocator_type
Definition bslstl_ostringstream.h:201
traits_type::pos_type pos_type
Definition bslstl_ostringstream.h:204
basic_ostringstream(const STRING_VIEW_LIKE_TYPE &initialString, ios_base::openmode modeBitMask, allocator=allocator_type())
Definition bslstl_ostringstream.h:359
CHAR_TYPE char_type
Definition bslstl_ostringstream.h:199
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by the underlying buffer to supply memory.
Definition bslstl_ostringstream.h:702
StringType str() const
Definition bslstl_ostringstream.h:729
bsl::enable_if< bsl::IsStdAllocator< SALLOC >::value, basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > >::type str(const SALLOC &allocator) const
Definition bslstl_ostringstream.h:470
ViewType view() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_ostringstream.h:738
basic_ostringstream(const bsl::basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &initialString, const allocator_type &allocator=allocator_type(), typename bsl::enable_if< !bsl::is_same< ALLOCATOR, SALLOC >::value, void * >::type=0)
Definition bslstl_ostringstream.h:273
traits_type::off_type off_type
Definition bslstl_ostringstream.h:203
basic_ostringstream(const STRING_VIEW_LIKE_TYPE &initialString, allocator=allocator_type())
Definition bslstl_ostringstream.h:333
bsl::enable_if<!bsl::is_same< ALLOCATOR, SALLOC >::value, void >::type str(const basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &value)
Definition bslstl_ostringstream.h:403
StreamBufType * rdbuf() const
Definition bslstl_ostringstream.h:712
traits_type::int_type int_type
Definition bslstl_ostringstream.h:202
basic_ostringstream(const bsl::basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &initialString, ios_base::openmode modeBitMask, const allocator_type &allocator=allocator_type(), typename bsl::enable_if< !bsl::is_same< ALLOCATOR, SALLOC >::value, void * >::type=0)
Definition bslstl_ostringstream.h:302
CHAR_TRAITS traits_type
Definition bslstl_ostringstream.h:200
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
Definition bslstl_stringbuf.h:248
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#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 BSLSTL_STRINGVIEWLIKEPARAM_ONLY_ENABLE_IF_T(...)
Definition bslstl_stringviewlikeparam.h:159
void swap(OptionValue &a, OptionValue &b)
Definition bdlat_valuetypefunctions.h:939
basic_ostringstream< wchar_t, char_traits< wchar_t >, allocator< wchar_t > > wostringstream
Definition bslstl_iosfwd.h:106
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
CHAR_TRAITS
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
basic_ostringstream< char, char_traits< char >, allocator< char > > ostringstream
Definition bslstl_iosfwd.h:97
Definition baljsn_encoder_testtypes.h:76
Definition bdldfp_decimal.h:5549
Definition bslma_allocatortraits.h:1089
Definition bslmf_enableif.h:530
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:344