Quick Links: |
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 |
ostringstream
class. bsl::ostringstream | C++03-compatible ostringstream class |
<bsl_sstream.h>
instead. 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. 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
. 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
). bsl::ostringstream
to write data of various types into a bsl::string
object. 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(); }
toString
function works on some simple test cases: typedef CHAR_TYPE bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::char_type [inherited] |
typedef CHAR_TRAITS bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::traits_type [inherited] |
typedef ALLOCATOR bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::allocator_type [inherited] |
typedef traits_type::int_type bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::int_type [inherited] |
typedef traits_type::off_type bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::off_type [inherited] |
typedef traits_type::pos_type bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::pos_type [inherited] |
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_ostringstream | ( | const allocator_type & | allocator = allocator_type() |
) | [inline, explicit, inherited] |
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_ostringstream | ( | ios_base::openmode | modeBitMask, | |
const allocator_type & | allocator = allocator_type() | |||
) | [inline, explicit, inherited] |
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_ostringstream | ( | const StringType & | initialString, | |
const allocator_type & | allocator = allocator_type() | |||
) | [inline, explicit, inherited] |
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.
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_ostringstream | ( | BloombergLP::bslmf::MovableRef< StringType > | initialString | ) | [inline, explicit, inherited] |
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_ostringstream | ( | BloombergLP::bslmf::MovableRef< StringType > | initialString, | |
const allocator_type & | allocator | |||
) | [inline, inherited] |
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::basic_ostringstream | ( | BloombergLP::bslmf::MovableRef< StringType > | initialString, | |
ios_base::openmode | modeBitMask | |||
) | [inline, inherited] |
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.
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] |
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] |
bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::~basic_ostringstream | ( | ) | [inherited] |
Destroy this object.
void bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str | ( | const StringType & | value | ) | [inline, inherited] |
void bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str | ( | BloombergLP::bslmf::MovableRef< StringType > | value | ) | [inline, inherited] |
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] |
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().
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().
basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::allocator_type bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::get_allocator | ( | ) | const [inline, inherited] |
Return the allocator used by the underlying buffer to supply memory.
References bsl::basic_stringbuf< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::get_allocator(), and bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::rdbuf().
Referenced by bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::swap().
basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::StreamBufType * bsl::basic_ostringstream< 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_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::get_allocator(), bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::str(), and bsl::basic_ostringstream< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR >::view().
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().
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().
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().