Quick Links:

bal | bbl | bdl | bsl

Classes | Typedefs | Functions

Component bslstl_istringstream
[Package bslstl]

Provide a C++03-compatible istringstream class. More...

Classes

class  bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >

Typedefs

typedef CHAR_TYPE bsl::basic_istringstream::char_type
typedef CHAR_TRAITS bsl::basic_istringstream::traits_type
typedef ALLOCATOR bsl::basic_istringstream::allocator_type
typedef traits_type::int_type bsl::basic_istringstream::int_type
typedef traits_type::off_type bsl::basic_istringstream::off_type
typedef traits_type::pos_type bsl::basic_istringstream::pos_type

Functions

 bsl::basic_istringstream::basic_istringstream (const allocator_type &allocator=allocator_type())
 bsl::basic_istringstream::basic_istringstream (ios_base::openmode modeBitMask, const allocator_type &allocator=allocator_type())
 bsl::basic_istringstream::basic_istringstream (const StringType &initialString, const allocator_type &allocator=allocator_type())
 bsl::basic_istringstream::basic_istringstream (const StringType &initialString, ios_base::openmode modeBitMask, const allocator_type &allocator=allocator_type())
 bsl::basic_istringstream::basic_istringstream (BloombergLP::bslmf::MovableRef< StringType > initialString)
 bsl::basic_istringstream::basic_istringstream (BloombergLP::bslmf::MovableRef< StringType > initialString, const allocator_type &allocator)
 bsl::basic_istringstream::basic_istringstream (BloombergLP::bslmf::MovableRef< StringType > initialString, ios_base::openmode modeBitMask)
 bsl::basic_istringstream::basic_istringstream (BloombergLP::bslmf::MovableRef< StringType > initialString, ios_base::openmode modeBitMask, const allocator_type &allocator)
template<class SALLOC >
 bsl::basic_istringstream::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)
template<class SALLOC >
 bsl::basic_istringstream::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)
 bsl::basic_istringstream::~basic_istringstream ()
void bsl::basic_istringstream::str (const StringType &value)
void bsl::basic_istringstream::str (BloombergLP::bslmf::MovableRef< StringType > value)
template<class SALLOC >
bsl::enable_if<!bsl::is_same
< ALLOCATOR, SALLOC >::value,
void >::type 
bsl::basic_istringstream::str (const basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &value)
StreamBufType * bsl::basic_istringstream::rdbuf () const
StringType bsl::basic_istringstream::str () const
template<class SALLOC >
bsl::enable_if
< bsl::IsStdAllocator< SALLOC >
::value, basic_string
< CHAR_TYPE, CHAR_TRAITS,
SALLOC > >::type 
bsl::basic_istringstream::str (const SALLOC &allocator) const
ViewType bsl::basic_istringstream::view () const BSLS_KEYWORD_NOEXCEPT

Detailed Description

Outline
Purpose:
Provide a C++03-compatible istringstream class.
Classes:
bsl::istringstream C++03-compatible istringstream class
Canonical Header:
bsl_sstream.h
See also:
Description:
This component is for internal use only. Please include <bsl_sstream.h> instead.
This component defines a class template, bsl::basic_istringstream, implementing a standard input stream that provides a constructor (as well as a manipulator) allowing clients to set the sequence of characters from which input is streamed to a supplied bsl::basic_string (see 27.8.3 [istringstream] of the C++11 standard). This component also defines two standard aliases, bsl::istringstream and bsl::wistringstream, that refer to specializations of the bsl::basic_istringstream template for char and wchar_t types, respectively. The bsl::basic_istringstream template has three parameters, CHAR_TYPE, CHAR_TRAITS, and ALLOCATOR. The CHAR_TYPE and CHAR_TRAITS parameters respectively define the character type for the string-stream and a type providing a set of operations the string-stream will use to manipulate characters of that type, which must meet the character traits requirements defined by the C++11 standard, 21.2 [char.traits]. The ALLOCATOR template parameter is described in the "Memory Allocation" section below.
Memory Allocation:
The type supplied as a string-stream's ALLOCATOR template parameter determines how that string-stream will allocate memory. The basic_istringstream template supports allocators meeting the requirements of the C++11 standard, 17.6.3.5 [allocator.requirements]; in addition, it supports scoped-allocators derived from the bslma::Allocator memory allocation protocol. Clients intending to use bslma-style allocators should use bsl::allocator, which provides a C++11 standard-compatible adapter for a bslma::Allocator object. Note that the standard aliases bsl::istringstream and bsl::wistringstream both use bsl::allocator.
bslma-Style Allocators:
If the type supplied for the ALLOCATOR template parameter of an istringstream instantiation is bsl::allocator, then objects of that string-stream type will conform to the standard behavior of a bslma-allocator-enabled type. Such a string-stream accepts an optional bslma::Allocator argument at construction. If the address of a bslma::Allocator object is explicitly supplied at construction, it will be used to supply memory for the string-stream throughout its lifetime; otherwise, the string-stream will use the default allocator installed at the time of the string-stream's construction (see bslma_default).
Usage:
This section illustrates intended use of this component.
Example 1: Basic Input Operations:
The following example demonstrates the use of bsl::istringstream to read data of various types from a bsl::string object.
Suppose we want to implement a simplified converter from bsl::string to a generic type, TYPE. We use bsl::istringstream to implement the fromString function. We initialize the input stream with the string passed as a parameter and then we read the data from the input stream with operator>>:
  template <class TYPE>
  TYPE fromString(const bsl::string& from)
  {
      bsl::istringstream in(from);
      TYPE val;
      in >> val;
      return val;
  }
Finally, we verify that our fromString function works on some simple test cases:
  assert(fromString<int>("1234") == 1234);

  assert(fromString<short>("-5") == -5);

  assert(fromString<bsl::string>("abc") == "abc");

Typedef Documentation

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
typedef CHAR_TYPE bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::char_type [inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
typedef CHAR_TRAITS bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::traits_type [inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
typedef ALLOCATOR bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::allocator_type [inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
typedef traits_type::int_type bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::int_type [inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
typedef traits_type::off_type bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::off_type [inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
typedef traits_type::pos_type bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::pos_type [inherited]

Function Documentation

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( const allocator_type allocator = allocator_type()  )  [inline, explicit, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( ios_base::openmode  modeBitMask,
const allocator_type allocator = allocator_type() 
) [inline, explicit, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( const StringType initialString,
const allocator_type allocator = allocator_type() 
) [inline, explicit, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( const StringType initialString,
ios_base::openmode  modeBitMask,
const allocator_type allocator = allocator_type() 
) [inline, inherited]

Create a basic_istringstream object. Optionally specify a modeBitMask indicating whether the underlying stream-buffer may also be written to (rdbuf is created using modeBitMask | ios_base::in). If modeBitMask is not supplied, rdbuf will be created using ios_base::in. Optionally specify an initialString indicating the sequence of characters from which input will be streamed. If initialString is not supplied, there will not be data to stream (until a subsequent call to the str manipulator). Optionally specify the allocator used to supply memory. If allocator is not supplied, a default-constructed object of the (template parameter) ALLOCATOR type is used. If the ALLOCATOR argument is of type bsl::allocator (the default), then allocator, if supplied, shall be convertible to bslma::Allocator *. If the ALLOCATOR argument is of type bsl::allocator and allocator is not supplied, the currently installed default allocator will be used to supply memory. If initialString is passed by MovableRef, it is left in a valid but unspecified state.

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( BloombergLP::bslmf::MovableRef< StringType initialString  )  [inline, explicit, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( BloombergLP::bslmf::MovableRef< StringType initialString,
const allocator_type allocator 
) [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( BloombergLP::bslmf::MovableRef< StringType initialString,
ios_base::openmode  modeBitMask 
) [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_istringstream ( BloombergLP::bslmf::MovableRef< StringType initialString,
ios_base::openmode  modeBitMask,
const allocator_type allocator 
) [inline, inherited]

Create a basic_istringstream object. Use the specified initialString indicating the initial sequence of characters from which input will be streamed. Optionally specify a modeBitMask indicating whether the underlying stream-buffer may also be written to (rdbuf is created using modeBitMask | ios_base::in). If modeBitMask is not supplied, rdbuf will be created using ios_base::in. Optionally specify the allocator used to supply memory. If allocator is not supplied, the allocator in initialString is used. initialString is left in a valid but unspecified state.

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
template<class SALLOC >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::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 
) [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
template<class SALLOC >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::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 
) [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::~basic_istringstream (  )  [inherited]

Destroy this object.

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
void bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str ( const StringType value  )  [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
void bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str ( BloombergLP::bslmf::MovableRef< StringType value  )  [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
template<class SALLOC >
bsl::enable_if<!bsl::is_same<ALLOCATOR, SALLOC>::value, void>::type bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str ( const basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &  value  )  [inline, inherited]
Parameters:
value Reset the internally buffered sequence of characters provided as input by this stream to the specified value. If value is passed by MovableRef, it is left in a valid but unspecified state.

Note: implemented inline due to Sun CC compilation error.

References bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf(), and bsl::basic_stringbuf< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str().

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::StreamBufType * bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf (  )  const [inline, inherited]

Return an address providing modifiable access to the basic_stringbuf object that is internally used by this string stream to buffer unformatted characters.

Reimplemented from bsl::StringBufContainer< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >.

References bsl::StringBufContainer< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf().

Referenced by bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str(), and bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::view().

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::StringType bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str (  )  const [inline, inherited]

Return the internally buffered sequence of characters maintained by this stream object.

References bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf(), and bsl::basic_stringbuf< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str().

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
template<class SALLOC >
bsl::enable_if< bsl::IsStdAllocator<SALLOC>::value, basic_string<CHAR_TYPE, CHAR_TRAITS, SALLOC> >::type bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str ( const SALLOC &  allocator  )  const [inline, inherited]

< Return a copy of the internally buffered sequence of characters maintained by this stream object in a basic_string that uses the specified allocator.

Note: implemented inline due to Sun CC compilation error.

References bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf(), and bsl::basic_stringbuf< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str().

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::ViewType bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::view (  )  const [inline, inherited]

Return a view of the internally buffered sequence of characters maintained by this stream object.

References bsl::basic_istringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf(), and bsl::basic_stringbuf< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::view().