text
stringlengths 0
2.2M
|
---|
// values using a 'bslx::StreambufOutStream', compares the contents of this
|
// stream to the expected value, and then writes the contents of this stream's
|
// buffer to 'stdout'.
|
//
|
// First, we create a 'bslx::StreambufOutStream' with an arbitrary value for
|
// its 'versionSelector' and externalize some values:
|
//..
|
bsl::stringbuf buffer;
|
bslx::StreambufOutStream outStream(&buffer, 20131127);
|
outStream.putInt32(1);
|
outStream.putInt32(2);
|
outStream.putInt8('c');
|
outStream.putString(bsl::string("hello"));
|
//..
|
// Then, we compare the contents of the stream to the expected value:
|
//..
|
bsl::string theChars = buffer.str();
|
ASSERT(15 == theChars.size());
|
ASSERT( 0 == bsl::memcmp(theChars.data(),
|
"\x00\x00\x00\x01\x00\x00\x00\x02""c\x05""hello",
|
15));
|
//..
|
// Finally, we print the stream's contents to 'bsl::cout'.
|
//..
|
if (veryVerbose)
|
for (bsl::size_t i = 0; i < theChars.size(); ++i) {
|
if (bsl::isalnum(static_cast<unsigned char>(theChars[i]))) {
|
bsl::cout << "nextByte (char): " << theChars[i] << bsl::endl;
|
}
|
else {
|
bsl::cout << "nextByte (int): "
|
<< static_cast<int>(theChars[i])
|
<< bsl::endl;
|
}
|
}
|
//..
|
// Executing the above code results in the following output:
|
//..
|
// nextByte (int): 0
|
// nextByte (int): 0
|
// nextByte (int): 0
|
// nextByte (int): 1
|
// nextByte (int): 0
|
// nextByte (int): 0
|
// nextByte (int): 0
|
// nextByte (int): 2
|
// nextByte (char): c
|
// nextByte (int): 5
|
// nextByte (char): h
|
// nextByte (char): e
|
// nextByte (char): l
|
// nextByte (char): l
|
// nextByte (char): o
|
//..
|
// See the 'bslx_byteinstream' component usage example for a more practical
|
// example of using 'bslx' streams.
|
} break;
|
case 1: {
|
// --------------------------------------------------------------------
|
// TYPEDEF
|
// Verify the 'typedef' is correct.
|
//
|
// Concerns:
|
//: 1 The 'typedef' is correct.
|
//
|
// Plan:
|
//: 1 Externalize a few items with 'bslx::StreambufOutStream' (using a
|
//: 'bsl::stringbuf') and 'bslx::GenericOutStream', and verify the
|
//: results are the same.
|
//
|
// Testing:
|
// TYPEDEF
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "TYPEDEF" << endl
|
<< "=======" << endl;
|
bsl::stringbuf expected;
|
bslx::GenericOutStream<bsl::streambuf> mX(&expected, 20131127);
|
bsl::stringbuf buffer;
|
bslx::StreambufOutStream mY(&buffer, 20131127);
|
mX.putInt32(3);
|
mY.putInt32(3);
|
ASSERT(expected.str() == buffer.str());
|
mX.putFloat64(3.14);
|
mY.putFloat64(3.14);
|
ASSERT(expected.str() == buffer.str());
|
mX.putString(bsl::string("alpha"));
|
mY.putString(bsl::string("alpha"));
|
ASSERT(expected.str() == buffer.str());
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.