BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_istringstream.h
Go to the documentation of this file.
1/// @file bslstl_istringstream.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_istringstream.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_ISTRINGSTREAM
9#define INCLUDED_BSLSTL_ISTRINGSTREAM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_istringstream bslstl_istringstream
15/// @brief Provide a C++03-compatible `istringstream` class.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_istringstream
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_istringstream-purpose"> Purpose</a>
25/// * <a href="#bslstl_istringstream-classes"> Classes </a>
26/// * <a href="#bslstl_istringstream-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_istringstream-description"> Description </a>
28/// * <a href="#bslstl_istringstream-memory-allocation"> Memory Allocation </a>
29/// * <a href="#bslstl_istringstream-bslma-style-allocators"> bslma-Style Allocators </a>
30/// * <a href="#bslstl_istringstream-usage"> Usage </a>
31/// * <a href="#bslstl_istringstream-example-1-basic-input-operations"> Example 1: Basic Input Operations </a>
32///
33/// # Purpose {#bslstl_istringstream-purpose}
34/// Provide a C++03-compatible `istringstream` class.
35///
36/// # Classes {#bslstl_istringstream-classes}
37///
38/// - bsl::istringstream: C++03-compatible `istringstream` class
39///
40/// # Canonical Header {#bslstl_istringstream-canonical-header}
41/// bsl_sstream.h
42///
43/// @see
44///
45/// # Description {#bslstl_istringstream-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_istringstream`,
50/// implementing a standard input stream that provides a constructor (as well as
51/// a manipulator) allowing clients to set the sequence of characters
52/// from which input is streamed to a supplied `bsl::basic_string` (see
53/// 27.8.3 [istringstream] of the C++11 standard). This component also defines
54/// two standard aliases, `bsl::istringstream` and `bsl::wistringstream`, that
55/// refer to specializations of the `bsl::basic_istringstream` template for
56/// `char` and `wchar_t` types, respectively. The `bsl::basic_istringstream`
57/// template has three parameters, `CHAR_TYPE`, `CHAR_TRAITS`, and `ALLOCATOR`.
58/// The `CHAR_TYPE` and `CHAR_TRAITS` parameters respectively define the
59/// character type for the string-stream and a type providing a set of
60/// operations the string-stream will use to manipulate characters of that type,
61/// which must meet the character traits requirements defined by the C++11
62/// standard, 21.2 [char.traits]. The `ALLOCATOR` template parameter is
63/// described in the "Memory Allocation" section below.
64///
65/// ## Memory Allocation {#bslstl_istringstream-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_istringstream 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::istringstream` and `bsl::wistringstream` both use `bsl::allocator`.
77///
78/// ### bslma-Style Allocators {#bslstl_istringstream-bslma-style-allocators}
79///
80///
81/// If the type supplied for the `ALLOCATOR` template parameter of an
82/// `istringstream` 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_istringstream-usage}
92///
93///
94/// This section illustrates intended use of this component.
95///
96/// ### Example 1: Basic Input Operations {#bslstl_istringstream-example-1-basic-input-operations}
97///
98///
99/// The following example demonstrates the use of `bsl::istringstream` to read
100/// data of various types from a `bsl::string` object.
101///
102/// Suppose we want to implement a simplified converter from `bsl::string` to a
103/// generic type, `TYPE`. We use `bsl::istringstream` to implement the
104/// `fromString` function. We initialize the input stream with the string
105/// passed as a parameter and then we read the data from the input stream with
106/// `operator>>`:
107/// @code
108/// template <class TYPE>
109/// TYPE fromString(const bsl::string& from)
110/// {
111/// bsl::istringstream in(from);
112/// TYPE val;
113/// in >> val;
114/// return val;
115/// }
116/// @endcode
117/// Finally, we verify that our `fromString` function works on some simple test
118/// cases:
119/// @code
120/// assert(fromString<int>("1234") == 1234);
121///
122/// assert(fromString<short>("-5") == -5);
123///
124/// assert(fromString<bsl::string>("abc") == "abc");
125/// @endcode
126/// @}
127/** @} */
128/** @} */
129
130/** @addtogroup bsl
131 * @{
132 */
133/** @addtogroup bslstl
134 * @{
135 */
136/** @addtogroup bslstl_istringstream
137 * @{
138 */
139
140#include <bslscm_version.h>
141
142#include <bslma_isstdallocator.h>
144
145#include <bslmf_enableif.h>
146#include <bslmf_issame.h>
147#include <bslmf_movableref.h>
148
150#include <bsls_keyword.h>
151#include <bsls_libraryfeatures.h>
152#include <bsls_platform.h>
153
154#include <bslstl_string.h>
155#include <bslstl_stringbuf.h>
156#include <bslstl_stringview.h>
158
159#include <ios>
160
161#include <istream>
162
163#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
164# include <utility>
165#endif
166
167namespace bsl {
168
169 // =========================
170 // class basic_istringstream
171 // =========================
172
173/// This class implements a standard input stream that provides a
174/// constructor and manipulator for setting the sequence of characters from
175/// which input is streamed to a supplied `bsl::basic_string`.
176template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
178 : private StringBufContainer<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>
179 , public std::basic_istream<CHAR_TYPE, CHAR_TRAITS> {
180
181 private:
182 // PRIVATE TYPES
185 BaseType;
188 typedef std::basic_istream<CHAR_TYPE, CHAR_TRAITS> BaseStream;
189 typedef std::ios_base ios_base;
190
191 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
192
193 private:
194 // NOT IMPLEMENTED
195 basic_istringstream(const basic_istringstream&); // = delete
196 basic_istringstream& operator=(const basic_istringstream&); // = delete
197
198 public:
199 // TYPES
200 typedef CHAR_TYPE char_type;
202 typedef ALLOCATOR allocator_type;
203 typedef typename traits_type::int_type int_type;
204 typedef typename traits_type::off_type off_type;
205 typedef typename traits_type::pos_type pos_type;
206
207 // CREATORS
208
209 /// Create a @ref basic_istringstream object. Optionally specify a
210 /// `modeBitMask` indicating whether the underlying stream-buffer may
211 /// also be written to (`rdbuf` is created using
212 /// `modeBitMask | ios_base::in`). If `modeBitMask` is not supplied,
213 /// `rdbuf` will be created using `ios_base::in`. Optionally specify an
214 /// `initialString` indicating the sequence of characters from which
215 /// input will be streamed. If `initialString` is not supplied, there
216 /// will not be data to stream (until a subsequent call to the `str`
217 /// manipulator). Optionally specify the `allocator` used to supply
218 /// memory. If `allocator` is not supplied, a default-constructed
219 /// object of the (template parameter) `ALLOCATOR` type is used. If the
220 /// `ALLOCATOR` argument is of type `bsl::allocator` (the default), then
221 /// `allocator`, if supplied, shall be convertible to
222 /// `bslma::Allocator *`. If the `ALLOCATOR` argument is of type
223 /// `bsl::allocator` and `allocator` is not supplied, the currently
224 /// installed default allocator will be used to supply memory. If
225 /// `initialString` is passed by `MovableRef`, it is left in a valid but
226 /// unspecified state.
227 explicit
229 explicit
230 basic_istringstream(ios_base::openmode modeBitMask,
232 explicit
233 basic_istringstream(const StringType& initialString,
235 basic_istringstream(const StringType& initialString,
236 ios_base::openmode modeBitMask,
238
239 /// Create a @ref basic_istringstream object. Use the specified
240 /// `initialString` indicating the initial sequence of characters from
241 /// which input will be streamed. Optionally specify a `modeBitMask`
242 /// indicating whether the underlying stream-buffer may also be written
243 /// to (`rdbuf` is created using `modeBitMask | ios_base::in`). If
244 /// `modeBitMask` is not supplied, `rdbuf` will be created using
245 /// `ios_base::in`. Optionally specify the `allocator` used to supply
246 /// memory. If `allocator` is not supplied, the allocator in
247 /// `initialString` is used. `initialString` is left in a valid but
248 /// unspecified state.
249 explicit
251 BloombergLP::bslmf::MovableRef<StringType> initialString);
253 BloombergLP::bslmf::MovableRef<StringType> initialString,
256 BloombergLP::bslmf::MovableRef<StringType> initialString,
257 ios_base::openmode modeBitMask);
259 BloombergLP::bslmf::MovableRef<StringType> initialString,
260 ios_base::openmode modeBitMask,
262
263 /// Create a @ref basic_istringstream object. Use the specified
264 /// `initialString` indicating the sequence of characters from which
265 /// input will be streamed. `rdbuf` is created using `ios_base::in`.
266 /// Optionally specify the `allocator` used to supply memory. If
267 /// `allocator` is not supplied, a default-constructed object of the
268 /// (template parameter) `ALLOCATOR` type is used. If the `ALLOCATOR`
269 /// argument is of type `bsl::allocator` (the default), then
270 /// `allocator`, if supplied, shall be convertible to
271 /// `bslma::Allocator *`. If the `ALLOCATOR` argument is of type
272 /// `bsl::allocator` and `allocator` is not supplied, the currently
273 /// installed default allocator will be used to supply memory.
274 template <class SALLOC>
277 initialString,
279 typename bsl::enable_if<
280 !bsl::is_same<ALLOCATOR, SALLOC>::value, void *>::type = 0)
281 : BaseType(initialString.begin(),
282 initialString.end(),
283 ios_base::in,
284 allocator)
285 , BaseStream(BaseType::rdbuf())
286 {
287 // Note: implemented inline due to Sun CC compilation error.
288 }
289
290 /// Create a @ref basic_istringstream object. Use the specified
291 /// `initialString` indicating the sequence of characters from which
292 /// input will be streamed. Use the specified `modeBitMask` to indicate
293 /// whether this buffer may be read from, written to, or both.
294 /// Optionally specify the `allocator` used to supply memory. If
295 /// `allocator` is not supplied, a default-constructed object of the
296 /// (template parameter) `ALLOCATOR` type is used. If the `ALLOCATOR`
297 /// argument is of type `bsl::allocator` (the default), then
298 /// `allocator`, if supplied, shall be convertible to
299 /// `bslma::Allocator *`. If the `ALLOCATOR` argument is of type
300 /// `bsl::allocator` and `allocator` is not supplied, the currently
301 /// installed default allocator will be used to supply memory.
302 template <class SALLOC>
305 initialString,
306 ios_base::openmode modeBitMask,
308 typename bsl::enable_if<
309 !bsl::is_same<ALLOCATOR, SALLOC>::value, void *>::type = 0)
310 : BaseType(initialString.begin(),
311 initialString.end(),
312 modeBitMask | ios_base::in,
313 allocator)
314 , BaseStream(BaseType::rdbuf())
315 {
316 // Note: implemented inline due to Sun CC compilation error.
317 }
318
319 /// Create a @ref basic_istringstream object. Use the specified
320 /// `initialString` (of a type convertible to
321 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
322 /// `const CHAR_TYPE *`) indicating the sequence of characters from
323 /// which input will be streamed. `rdbuf` is created using
324 /// `ios_base::in`. Optionally specify the `allocator` used to supply
325 /// memory. If `allocator` is not supplied, a default-constructed
326 /// object of the (template parameter) `ALLOCATOR` type is used. If the
327 /// `ALLOCATOR` argument is of type `bsl::allocator` (the default), then
328 /// `allocator`, if supplied, shall be convertible to
329 /// `bslma::Allocator *`. If the `ALLOCATOR` argument is of type
330 /// `bsl::allocator` and `allocator` is not supplied, the currently
331 /// installed default allocator will be used to supply memory.
332 template <class STRING_VIEW_LIKE_TYPE>
333 explicit
335 const STRING_VIEW_LIKE_TYPE& initialString,
338 : BaseType(initialString, ios_base::in, allocator)
339 , BaseStream(BaseType::rdbuf())
340 {
341 // Note: implemented inline due to Sun CC compilation error.
342 }
343
344 /// Create a @ref basic_istringstream object. Use the specified
345 /// `initialString` (of a type convertible to
346 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
347 /// `const CHAR_TYPE *`) indicating the sequence of characters from
348 /// which input will be streamed. Use the specified `modeBitMask` to
349 /// indicate whether this buffer may be read from, written to, or both.
350 /// `rdbuf` is created using `modeBitMask | ios_base::in`. Optionally
351 /// specify the `allocator` used to supply memory. If `allocator` is
352 /// not supplied, a default-constructed object of the (template
353 /// parameter) `ALLOCATOR` type is used. If the `ALLOCATOR` argument
354 /// is of type `bsl::allocator` (the default), then `allocator`, if
355 /// supplied, shall be convertible to `bslma::Allocator *`. If the
356 /// `ALLOCATOR` argument is of type `bsl::allocator` and `allocator` is
357 /// not supplied, the currently installed default allocator will be used
358 /// to supply memory.
359 template <class STRING_VIEW_LIKE_TYPE>
361 const STRING_VIEW_LIKE_TYPE& initialString,
362 ios_base::openmode modeBitMask,
365 : BaseType(initialString, modeBitMask | ios_base::in, allocator)
366 , BaseStream(BaseType::rdbuf())
367 {
368 // Note: implemented inline due to Sun CC compilation error.
369 }
370
371#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
372 /// Create a @ref basic_istringstream object having the same value as the
373 /// specified `original` object by moving the contents of `original` to
374 /// the newly-created object. `original` is left in a valid but
375 /// unspecified state.
376// NOLINTNEXTLINE(performance-noexcept-move-constructor)
378#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
379
381 // Destroy this object.
382
383 // MANIPULATORS
384#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
385 /// Assign to this object the value of the specified `rhs`, and return a
386 /// reference providing modifiable access to this object. The contents
387 /// of `rhs` are move-assigned to this object. `rhs` is left in a valid
388 /// but unspecified state.
389// NOLINTNEXTLINE(performance-noexcept-move-constructor)
391#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
392
393 /// Reset the internally buffered sequence of characters provided as
394 /// input by this stream to the specified `value`. If `value` is passed
395 /// by `MovableRef`, it is left in a valid but unspecified state.
396 void str(const StringType& value);
397 void str(BloombergLP::bslmf::MovableRef<StringType> value);
398 template <class SALLOC>
399 typename
402 {
403 // Note: implemented inline due to Sun CC compilation error.
404 this->rdbuf()->str(value);
405 }
406
407 /// Reset the internally buffered sequence of characters provided as
408 /// input by this stream to the specified `value` (of a type convertible
409 /// to `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
410 /// `const CHAR_TYPE *`).
411 template <class STRING_VIEW_LIKE_TYPE>
413 str(const STRING_VIEW_LIKE_TYPE& value)
414 {
415 // Note: implemented inline due to Sun CC compilation error.
416 this->rdbuf()->str(value);
417 }
418
419#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
420 /// Return the internally buffered sequence of characters maintained by
421 /// this stream, leaving the stream empty.
422 StringType str() &&;
423#endif // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
424
425#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
426 /// Efficiently exchange the value of this object with the value of the
427 /// specified `other` object. This method provides the no-throw
428 /// exception-safety guarantee if `*this` and `other` allocators compare equal.
429 ///
430 /// \pre The behavior is undefined unless either `*this` and `other`
431 /// allocators compare equal or @ref propagate_on_container_swap is `true`.
432 ///
433 /// \note Note that this function is only available for C++11 (and later)
434 /// language standards because it requires that `swap` be provided on
435 /// the (platform supplied) base class for this type.
436// NOLINTNEXTLINE(performance-noexcept-swap)
437 void swap(basic_istringstream& other);
438#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
439
440 // ACCESSORS
441
442 /// Return an address providing modifiable access to the
443 /// @ref basic_stringbuf object that is internally used by this string
444 /// stream to buffer unformatted characters.
445 StreamBufType *rdbuf() const;
446
447#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
448 StringType str() const &;
449#else
450 StringType str() const;
451#endif
452 // Return the internally buffered sequence of characters maintained by
453 // this stream object.
454
455#ifndef BSLS_PLATFORM_CMP_SUN
456 // To be enabled once DRQS 168075157 is resolved
457
458 /// Return a copy of the internally buffered sequence of characters
459 /// maintained by this stream object in a @ref basic_string that uses the
460 /// specified `allocator`.
461 template <class SALLOC>
462 typename bsl::enable_if<
463 bsl::IsStdAllocator<SALLOC>::value,
465 str(const SALLOC& allocator) const
466 {
467 // Note: implemented inline due to Sun CC compilation error.
468 return this->rdbuf()->str(allocator);
469 }
470#endif // BSLS_PLATFORM_CMP_SUN
471
472 /// Return a view of the internally buffered sequence of characters
473 /// maintained by this stream object.
474 ViewType view() const BSLS_KEYWORD_NOEXCEPT;
475};
476
477// FREE FUNCTIONS
478#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) \
479 && defined(BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE)
480/// Efficiently exchange the values of the specified `a` and `b` objects.
481/// This method provides the no-throw exception-safety guarantee if `a` and `b` allocators compare equal.
482///
483/// \note Note that this function is only available
484/// for C++11 (and later) language standards.
485template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
486// NOLINTNEXTLINE(performance-noexcept-swap)
489#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY && CPP11_STREAM_MOVE
490
491// STANDARD TYPEDEFS
496
497// ============================================================================
498// TEMPLATE FUNCTION DEFINITIONS
499// ============================================================================
500
501 // -------------------------
502 // class basic_istringstream
503 // -------------------------
504
505// CREATORS
506template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
507inline
510: BaseType(ios_base::in, allocator)
511, BaseStream(BaseType::rdbuf())
512{
513}
514
515template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
516inline
518basic_istringstream(ios_base::openmode modeBitMask,
520: BaseType(modeBitMask | ios_base::in, allocator)
521, BaseStream(BaseType::rdbuf())
522{
523}
524
525template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
526inline
528basic_istringstream(const StringType& initialString,
530: BaseType(initialString, ios_base::in, allocator)
531, BaseStream(BaseType::rdbuf())
532{
533}
534
535template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
536inline
538basic_istringstream(const StringType& initialString,
539 ios_base::openmode modeBitMask,
541: BaseType(initialString, modeBitMask | ios_base::in, allocator)
542, BaseStream(BaseType::rdbuf())
543{
544}
545
546template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
547inline
549basic_istringstream(BloombergLP::bslmf::MovableRef<StringType> initialString)
550: BaseType(MoveUtil::move(initialString), ios_base::in)
551, BaseStream(BaseType::rdbuf())
552{
553}
554
555template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
556inline
558basic_istringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
560: BaseType(MoveUtil::move(initialString), ios_base::in, allocator)
561, BaseStream(BaseType::rdbuf())
562{
563}
564
565template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
566inline
568basic_istringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
569 ios_base::openmode modeBitMask)
570: BaseType(MoveUtil::move(initialString), modeBitMask | ios_base::in)
571, BaseStream(BaseType::rdbuf())
572{
573}
574
575template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
576inline
578basic_istringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
579 ios_base::openmode modeBitMask,
581: BaseType(MoveUtil::move(initialString),
582 modeBitMask | ios_base::in,
583 allocator)
584, BaseStream(BaseType::rdbuf())
585{
586}
587
588#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
589template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
590inline
592// NOLINTNEXTLINE(performance-noexcept-move-constructor)
594: BaseType(std::move(original))
595, BaseStream(std::move(original))
596{
597 BaseStream::set_rdbuf(BaseType::rdbuf());
598}
599#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
600
601// MANIPULATORS
602#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
603template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
604inline
605basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>&
606basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::
607// NOLINTNEXTLINE(performance-noexcept-move-constructor)
608operator=(basic_istringstream&& rhs)
609{
610 this->BaseType::operator=(std::move(rhs));
611 this->BaseStream::operator=(std::move(rhs));
612
613 return *this;
614}
615#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
616
617#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
618template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
619inline
620// NOLINTNEXTLINE(performance-noexcept-swap)
621void basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::swap(
622 basic_istringstream& other)
623{
624#ifdef BSLS_PLATFORM_CMP_GNU
625# pragma GCC diagnostic push
626# pragma GCC diagnostic ignored "-Wstringop-overflow"
627#endif
630 || this->rdbuf()->get_allocator()
631 == other.rdbuf()->get_allocator());
632 this->BaseType::swap(other);
633 this->BaseStream::swap(other);
634#ifdef BSLS_PLATFORM_CMP_GNU
635# pragma GCC diagnostic pop
636#endif
637}
638#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
639
640template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
641inline
643 const StringType& value)
644{
645 this->rdbuf()->str(value);
646}
647
648template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
649inline
651 BloombergLP::bslmf::MovableRef<StringType> value)
652{
653 this->rdbuf()->str(MoveUtil::move(value));
654}
655
656#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
657template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
658inline
661{
662 return std::move(*this->rdbuf()).str();
663}
664#endif // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
665
666// ACCESSORS
667template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
668inline
669typename
670basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::StreamBufType *
672{
673 return this->BaseType::rdbuf();
674}
675
676#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
677template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
678inline
681{
682 return this->rdbuf()->str();
683}
684#else // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
685template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
686inline
687typename basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::StringType
689{
690 return this->rdbuf()->str();
691}
692#endif // else BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
693
694template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
695inline
696typename basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::ViewType
699{
700 return this->rdbuf()->view();
701}
702
703} // close namespace bsl
704
705// FREE FUNCTIONS
706#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) \
707 && defined(BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE)
708template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
709// NOLINTNEXTLINE(performance-noexcept-swap)
710void bsl::swap(basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& a,
711 basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& b)
712{
713 a.swap(b);
714}
715#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY && CPP11_STREAM_MOVE
716
717// ============================================================================
718// TYPE TRAITS
719// ============================================================================
720
721
722namespace bslma {
723
724template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
726 bsl::basic_istringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR> >
728{};
729
730} // close namespace bslma
731
732
733#endif // INCLUDED_BSLSTL_ISTRINGSTREAM
734
735// ----------------------------------------------------------------------------
736// Copyright 2013 Bloomberg Finance L.P.
737//
738// Licensed under the Apache License, Version 2.0 (the "License");
739// you may not use this file except in compliance with the License.
740// You may obtain a copy of the License at
741//
742// http://www.apache.org/licenses/LICENSE-2.0
743//
744// Unless required by applicable law or agreed to in writing, software
745// distributed under the License is distributed on an "AS IS" BASIS,
746// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
747// See the License for the specific language governing permissions and
748// limitations under the License.
749// ----------------------------- END-OF-FILE ----------------------------------
750
751/** @} */
752/** @} */
753/** @} */
Definition bslstl_stringbuf.h:835
Definition bslma_bslallocator.h:588
Definition bslstl_istringstream.h:179
bsl::enable_if< bsl::IsStdAllocator< SALLOC >::value, basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > >::type str(const SALLOC &allocator) const
Definition bslstl_istringstream.h:465
CHAR_TRAITS traits_type
Definition bslstl_istringstream.h:201
basic_istringstream(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_istringstream.h:303
basic_istringstream(const STRING_VIEW_LIKE_TYPE &initialString, ios_base::openmode modeBitMask, allocator=allocator_type())
Definition bslstl_istringstream.h:360
basic_istringstream(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_istringstream.h:275
ALLOCATOR allocator_type
Definition bslstl_istringstream.h:202
basic_istringstream(const STRING_VIEW_LIKE_TYPE &initialString, allocator=allocator_type())
Definition bslstl_istringstream.h:334
traits_type::int_type int_type
Definition bslstl_istringstream.h:203
traits_type::pos_type pos_type
Definition bslstl_istringstream.h:205
ViewType view() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_istringstream.h:697
bsl::enable_if<!bsl::is_same< ALLOCATOR, SALLOC >::value, void >::type str(const basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &value)
Definition bslstl_istringstream.h:401
StringType str() const
Definition bslstl_istringstream.h:688
CHAR_TYPE char_type
Definition bslstl_istringstream.h:200
traits_type::off_type off_type
Definition bslstl_istringstream.h:204
StreamBufType * rdbuf() const
Definition bslstl_istringstream.h:671
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
Definition bdlat_valuetypefunctions.h:939
basic_istringstream< wchar_t, char_traits< wchar_t >, allocator< wchar_t > > wistringstream
Definition bslstl_iosfwd.h:104
basic_istringstream< char, char_traits< char >, allocator< char > > istringstream
Definition bslstl_iosfwd.h:95
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
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