Quick Links:

bal | bbl | bdl | bsl

Classes | Typedefs | Functions

Component bslstl_ostringstream
[Package bslstl]

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

Classes

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

Typedefs

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

Functions

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

Detailed Description

Outline
Purpose:
Provide a C++03-compatible ostringstream class.
Classes:
bsl::ostringstream C++03-compatible ostringstream 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_ostringstream, implementing a standard output stream that provides a method for obtaining a bsl::basic_string, which contains the characters that have been written to the stream (see 27.8.4 [ostringstream] of the C++11 standard). This component also defines two standard aliases, bsl::ostringstream and bsl::wostringstream, that refer to specializations of the bsl::basic_ostringstream template for char and wchar_t types, respectively. The bsl::basic_ostringstream 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_ostringstream 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::ostringstream and bsl::wostringstream both use bsl::allocator.
bslma-Style Allocators:
If the type supplied for the ALLOCATOR template parameter of an ostringstream 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 Output Operations:
The following example demonstrates the use of bsl::ostringstream to write data of various types into a bsl::string object.
Suppose we want to implement a simplified converter from a generic type, TYPE, to bsl::string. We use bsl::ostringstream to implement the toString function. We write the data into the stream with operator<< and then use the str method to retrieve the resulting string from the stream:
  template <class TYPE>
  bsl::string toString(const TYPE& what)
  {
      bsl::ostringstream out;
      out << what;
      return out.str();
  }
Finally, we verify that our toString function works on some simple test cases:
  assert(toString(1234) == "1234");

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

  assert(toString("abc") == "abc");

Typedef Documentation

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

Function Documentation

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

Create a basic_ostringstream object. Optionally specify a modeBitMask indicating whether the underlying stream-buffer may also be read from (rdbuf is created using modeBitMask | ios_base::out). If modeBitMask is not supplied, rdbuf will be created using ios_base::out. Optionally specify an initialString indicating the value that will be returned by a call to str prior to any streaming operations performed on this object. If initialString is not supplied, str will initially return an empty string. 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.

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

Create a basic_ostringstream object. Use the specified initialString indicating the value that will be returned by a call to str prior to any streaming operations performed on this object. Optionally specify a modeBitMask indicating whether the underlying stream-buffer may also be read from (rdbuf is created using modeBitMask | ios_base::out). If modeBitMask is not supplied, rdbuf will be created using ios_base::out. 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_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::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 
) [inline, inherited]
template<class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
template<class SALLOC >
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::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 
) [inline, inherited]
template<class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::~basic_ostringstream (  )  [inherited]

Destroy this object.

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
void bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str ( const StringType value  )  [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
void bsl::basic_ostringstream< 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_ostringstream< 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 maintained by this stream object 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_ostringstream< 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 >
void bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::swap ( basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > &  other  )  [inline, inherited]

Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee if *this and other allocators compare equal. The behavior is undefined unless either *this and other allocators compare equal or propagate_on_container_swap is true. Note that this function is only available for C++11 (and later) language standards because it requires that swap be provided on the (platform supplied) base class for this type.

References BSLS_ASSERT, bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::get_allocator(), and bsl::StringBufContainer< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::swap().

template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::allocator_type bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::get_allocator (  )  const [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::StreamBufType * bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf (  )  const [inline, inherited]
template<class CHAR_TYPE , class CHAR_TRAITS , class ALLOCATOR >
basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::StringType bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str (  )  const [inline, inherited]

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

References bsl::basic_ostringstream< 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_ostringstream< 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_ostringstream< 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_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::ViewType bsl::basic_ostringstream< 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_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf(), and bsl::basic_stringbuf< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::view().