BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslx_testoutstream.h
Go to the documentation of this file.
1/// @file bslx_testoutstream.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslx_testoutstream.h -*-C++-*-
8#ifndef INCLUDED_BSLX_TESTOUTSTREAM
9#define INCLUDED_BSLX_TESTOUTSTREAM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslx_testoutstream bslx_testoutstream
15/// @brief Enable externalization of fundamental types with identification.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslx
19/// @{
20/// @addtogroup bslx_testoutstream
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslx_testoutstream-purpose"> Purpose</a>
25/// * <a href="#bslx_testoutstream-classes"> Classes </a>
26/// * <a href="#bslx_testoutstream-description"> Description </a>
27/// * <a href="#bslx_testoutstream-versioning"> Versioning </a>
28/// * <a href="#bslx_testoutstream-usage"> Usage </a>
29/// * <a href="#bslx_testoutstream-example-1-basic-externalization"> Example 1: Basic Externalization </a>
30///
31/// # Purpose {#bslx_testoutstream-purpose}
32/// Enable externalization of fundamental types with identification.
33///
34/// # Classes {#bslx_testoutstream-classes}
35///
36/// - bslx::TestOutStream: byte-array-based output stream for fundamental types
37///
38/// @see bslx_testinstream, bslx_byteoutstream
39///
40/// # Description {#bslx_testoutstream-description}
41/// This component implements a byte-array-based output stream
42/// class, `bslx::TestOutStream`, that provides platform-independent output
43/// methods ("externalization") on values, and arrays of values, of fundamental
44/// types, and on `bsl::string`. This component also externalizes information
45/// to the stream that can be used by the reader of the stream to verify, for
46/// these types, that the type of data requested from the input stream matches
47/// what was written by this output stream. This component is meant for testing
48/// only.
49///
50/// This component is intended to be used in conjunction with the
51/// @ref bslx_testinstream "unexternalization" component. Each output method of
52/// `bslx::TestOutStream` writes a value or a homogeneous array of values to an
53/// internally managed buffer. The values are formatted to be readable by the
54/// corresponding `bslx::TestInStream` method. In general, the user cannot rely
55/// on any other mechanism to read data written by `bslx::TestOutStream` unless
56/// that mechanism explicitly states its ability to do so.
57///
58/// The supported types and required content are listed in the `bslx`
59/// package-level documentation under "Supported Types".
60///
61/// Note that the values are stored in big-endian format (i.e., network byte
62/// order).
63///
64/// Note that output streams can be *invalidated* explicitly and queried for
65/// *validity*. Writing to an initially invalid stream has no effect. Whenever
66/// an output operation fails, the stream should be invalidated explicitly.
67///
68/// ## Versioning {#bslx_testoutstream-versioning}
69///
70///
71/// BDEX provides two concepts that support versioning the BDEX serialization
72/// format of a type: `version` and `versionSelector`. A `version` is a 1-based
73/// integer indicating one of the supported formats (e.g., format 1, format 2,
74/// etc.). A `versionSelector` is a value that is mapped to a `version` for a
75/// type by the type's implementation of `maxSupportedBdexVersion`.
76///
77/// Selecting a value for a `versionSelector` is required at two different
78/// points: (1) when implementing a new `version` format within the
79/// `bdexStreamIn` and `bdexStreamOut` methods of a type, and (2) when
80/// implementing code that constructs a BDEX `OutStream`. In both cases, the
81/// value should be a *compile*-time-selected value.
82///
83/// When a new `version` format is implemented within the `bdexStreamIn` and
84/// `bdexStreamOut` methods of a type, a new mapping in
85/// `maxSupportedBdexVersion` should be created to expose this new `version`
86/// with a `versionSelector`. A simple - and the recommended - approach is to
87/// use a value having the pattern "YYYYMMDD", where "YYYYMMDD" corresponds to
88/// the "go-live" date of the corresponding `version` format.
89///
90/// When constructing an `OutStream`, a simple approach is to use the current
91/// date as a *compile*-time constant value. In combination with the
92/// recommended selection of `versionSelector` values for
93/// `maxSupportedBdexVersion`, this will result in consistent and predictable
94/// behavior while externalizing types. Note that this recommendation is chosen
95/// for its simplicity: to ensure the largest possible audience for an
96/// externalized representation, clients can select the minimum date value that
97/// will result in the desired version of all types externalized with
98/// `operator<<` being selected.
99///
100/// See the `bslx` package-level documentation for more detailed information
101/// about versioning.
102///
103/// ## Usage {#bslx_testoutstream-usage}
104///
105///
106/// This section illustrates intended use of this component.
107///
108/// ### Example 1: Basic Externalization {#bslx_testoutstream-example-1-basic-externalization}
109///
110///
111/// A `bslx::TestOutStream` can be used to externalize values in a
112/// platform-neutral way. Writing out fundamental C++ types and `bsl::string`
113/// requires no additional work on the part of the client; the client can simply
114/// use the stream directly. The following code serializes a few representative
115/// values using a `bslx::TestOutStream`, compares the contents of this stream
116/// to the expected value, and then writes the contents of this stream's buffer
117/// to `stdout`.
118///
119/// First, we create a `bslx::TestOutStream` with an arbitrary value for its
120/// `versionSelector` and externalize some values:
121/// @code
122/// bslx::TestOutStream outStream(20131127);
123/// outStream.putInt32(1);
124/// outStream.putInt32(2);
125/// outStream.putInt8('c');
126/// outStream.putString(bsl::string("hello"));
127/// @endcode
128/// Then, we compare the contents of the stream to the expected value:
129/// @code
130/// const char *theChars = outStream.data();
131/// bsl::size_t length = outStream.length();
132/// assert(24 == length);
133/// assert( 0 == bsl::memcmp(theChars,
134/// "\xE6\x00\x00\x00\x01\xE6\x00\x00\x00\x02\xE0"
135/// "c\xE0\x05\xE1\x00\x00\x00\x05""hello",
136/// length));
137/// @endcode
138/// Finally, we print the stream's contents to `bsl::cout`.
139/// @code
140/// for (bsl::size_t i = 0; i < length; ++i) {
141/// if(bsl::isalnum(static_cast<unsigned char>(theChars[i]))) {
142/// bsl::cout << "nextByte (char): " << theChars[i] << bsl::endl;
143/// }
144/// else {
145/// bsl::cout << "nextByte (int): "
146/// << static_cast<int>(theChars[i])
147/// << bsl::endl;
148/// }
149/// }
150/// @endcode
151/// Executing the above code results in the following output:
152/// @code
153/// nextByte (int): -26
154/// nextByte (int): 0
155/// nextByte (int): 0
156/// nextByte (int): 0
157/// nextByte (int): 1
158/// nextByte (int): -26
159/// nextByte (int): 0
160/// nextByte (int): 0
161/// nextByte (int): 0
162/// nextByte (int): 2
163/// nextByte (int): -32
164/// nextByte (char): c
165/// nextByte (int): -32
166/// nextByte (int): 5
167/// nextByte (int): -31
168/// nextByte (char): h
169/// nextByte (char): e
170/// nextByte (char): l
171/// nextByte (char): l
172/// nextByte (char): o
173/// @endcode
174/// Note the negative numeric values indicate the "type" of the data that
175/// follows (see @ref bslx_typecode ).
176///
177/// See the @ref bslx_testinstream component usage example for a more practical
178/// example of using this test output stream.
179/// @}
180/** @} */
181/** @} */
182
183/** @addtogroup bsl
184 * @{
185 */
186/** @addtogroup bslx
187 * @{
188 */
189/** @addtogroup bslx_testoutstream
190 * @{
191 */
192
193#include <bslscm_version.h>
194
195#include <bslx_byteoutstream.h>
197
198#include <bsls_types.h>
199
200#include <bsl_cstddef.h>
201#include <bsl_iosfwd.h>
202#include <bsl_string.h>
203
204
205
206namespace bslma { class Allocator; }
207
208namespace bslx {
209
210 // ===================
211 // class TestOutStream
212 // ===================
213
214/// This class implements output methods to externalize fundamental types
215/// and their associated type identification data. It stores the
216/// accumulated result in network byte order. See the `bslx` package-level
217/// documentation for the definition of the BDEX `OutStream` protocol.
218///
219/// See @ref bslx_testoutstream
221
222 // DATA
223 ByteOutStream d_imp; // byte out stream implementation
224
225 bool d_makeNextInvalidFlag; // if 'true', next "put" operation
226 // outputs the invalid data indicator
227 // and resets this flag to 'false'
228
229 // FRIENDS
230 friend bsl::ostream& operator<<(bsl::ostream&, const TestOutStream&);
231
232 // NOT IMPLEMENTED
234 TestOutStream& operator=(const TestOutStream&);
235
236 public:
237 // CREATORS
238
239 /// Create an empty output byte stream that will use the specified
240 /// (*compile*-time-defined) `versionSelector` as needed (see
241 /// {Versioning}). Optionally specify a `basicAllocator` used to supply
242 /// memory. If `basicAllocator` is 0, the currently installed default
243 /// allocator is used. Note that the `versionSelector` is expected to
244 /// be formatted as "YYYYMMDD", a date representation.
245 explicit TestOutStream(int versionSelector,
246 bslma::Allocator *basicAllocator = 0);
247
248 /// Create an empty output byte stream having an initial buffer capacity
249 /// of at least the specified `initialCapacity` (in bytes) and that will
250 /// use the specified (*compile*-time-defined) `versionSelector` as
251 /// needed (see {Versioning}). Optionally specify a `basicAllocator`
252 /// used to supply memory. If `basicAllocator` is 0, the currently
253 /// installed default allocator is used. Note that the
254 /// `versionSelector` is expected to be formatted as "YYYYMMDD", a date
255 /// representation.
256 TestOutStream(int versionSelector,
257 bsl::size_t initialCapacity,
258 bslma::Allocator *basicAllocator = 0);
259
260 /// Destroy this object.
262
263 // MANIPULATORS
264
265 /// Put this output stream in an invalid state. This function has no
266 /// effect if this stream is already invalid.
267 void invalidate();
268
269 /// Make the next output operation externalize the invalid data
270 /// indicator, as opposed to the actual type indicator, to this output
271 /// stream; the data associated with the next output operation is still
272 /// externalized. Note that the invalid data indicator can be detected
273 /// by a corresponding `TestInStream` object.
274 void makeNextInvalid();
275
276 /// If the specified `length` is less than 128, write to this stream the
277 /// one-byte type indicator for a one-byte integer and the one-byte
278 /// integer comprised of the least-significant one byte of the `length`;
279 /// otherwise, write to this stream the one-byte type indicator for a
280 /// four-byte integer and the four-byte, two's complement integer (in
281 /// network byte order) comprised of the least-significant four bytes of
282 /// the `length` (in host byte order) with the most-significant bit set.
283 /// Return a reference to this stream. If this stream is initially
284 /// invalid, this operation has no effect. If the next output operation
285 /// has been set to be marked invalid (see `makeNextInvalid`), reset
286 /// this marking and emit the invalid indicator instead of the type
287 /// indicator. The behavior is undefined unless `0 <= length`.
289
290 /// Write to this stream the one-byte type indicator for a one-byte
291 /// unsigned integer and the one-byte, two's complement unsigned integer
292 /// comprised of the least-significant one byte of the specified
293 /// `version`, and return a reference to this stream. If this stream is
294 /// initially invalid, this operation has no effect. If the next output
295 /// operation has been set to be marked invalid (see `makeNextInvalid`),
296 /// reset this marking and emit the invalid indicator instead of the
297 /// type indicator.
299
300 /// Set the internal buffer size of this stream to be at least the
301 /// specified `newCapacity` (in bytes).
302 void reserveCapacity(bsl::size_t newCapacity);
303
304 /// Remove all content in this stream and validate this stream if it is
305 /// currently invalid.
306 void reset();
307
308 // *** scalar integer values ***
309
310 /// Write to this stream the one-byte type indicator for an eight-byte
311 /// integer and the eight-byte, two's complement integer (in network
312 /// byte order) comprised of the least-significant eight bytes of the
313 /// specified `value` (in host byte order), and return a reference to
314 /// this stream. If this stream is initially invalid, this operation
315 /// has no effect. If the next output operation has been set to be
316 /// marked invalid (see `makeNextInvalid`), reset this marking and emit
317 /// the invalid indicator instead of the type indicator.
319
320 /// Write to this stream the one-byte type indicator for an eight-byte
321 /// unsigned integer and the eight-byte, two's complement unsigned
322 /// integer (in network byte order) comprised of the least-significant
323 /// eight bytes of the specified `value` (in host byte order), and
324 /// return a reference to this stream. If this stream is initially
325 /// invalid, this operation has no effect. If the next output operation
326 /// has been set to be marked invalid (see `makeNextInvalid`), reset
327 /// this marking and emit the invalid indicator instead of the type
328 /// indicator.
330
331 /// Write to this stream the one-byte type indicator for a seven-byte
332 /// integer and the seven-byte, two's complement integer (in network
333 /// byte order) comprised of the least-significant seven bytes of the
334 /// specified `value` (in host byte order), and return a reference to
335 /// this stream. If this stream is initially invalid, this operation
336 /// has no effect. If the next output operation has been set to be
337 /// marked invalid (see `makeNextInvalid`), reset this marking and emit
338 /// the invalid indicator instead of the type indicator.
340
341 /// Write to this stream the one-byte type indicator for a seven-byte
342 /// unsigned integer and the seven-byte, two's complement unsigned
343 /// integer (in network byte order) comprised of the least-significant
344 /// seven bytes of the specified `value` (in host byte order), and
345 /// return a reference to this stream. If this stream is initially
346 /// invalid, this operation has no effect. If the next output operation
347 /// has been set to be marked invalid (see `makeNextInvalid`), reset
348 /// this marking and emit the invalid indicator instead of the type
349 /// indicator.
351
352 /// Write to this stream the one-byte type indicator for a six-byte
353 /// integer and the six-byte, two's complement integer (in network byte
354 /// order) comprised of the least-significant six bytes of the specified
355 /// `value` (in host byte order), and return a reference to this stream.
356 /// If this stream is initially invalid, this operation has no effect.
357 /// If the next output operation has been set to be marked invalid (see
358 /// `makeNextInvalid`), reset this marking and emit the invalid
359 /// indicator instead of the type indicator.
361
362 /// Write to this stream the one-byte type indicator for a six-byte
363 /// unsigned integer and the six-byte, two's complement unsigned integer
364 /// (in network byte order) comprised of the least-significant six bytes
365 /// of the specified `value` (in host byte order), and return a
366 /// reference to this stream. If this stream is initially invalid, this
367 /// operation has no effect. If the next output operation has been set
368 /// to be marked invalid (see `makeNextInvalid`), reset this marking and
369 /// emit the invalid indicator instead of the type indicator.
371
372 /// Write to this stream the one-byte type indicator for a five-byte
373 /// integer and the five-byte, two's complement integer (in network byte
374 /// order) comprised of the least-significant five bytes of the
375 /// specified `value` (in host byte order), and return a reference to
376 /// this stream. If this stream is initially invalid, this operation
377 /// has no effect. If the next output operation has been set to be
378 /// marked invalid (see `makeNextInvalid`), reset this marking and emit
379 /// the invalid indicator instead of the type indicator.
381
382 /// Write to this stream the one-byte type indicator for a five-byte
383 /// unsigned integer and the five-byte, two's complement unsigned
384 /// integer (in network byte order) comprised of the least-significant
385 /// five bytes of the specified `value` (in host byte order), and return
386 /// a reference to this stream. If this stream is initially invalid,
387 /// this operation has no effect. If the next output operation has been
388 /// set to be marked invalid (see `makeNextInvalid`), reset this marking
389 /// and emit the invalid indicator instead of the type indicator.
391
392 /// Write to this stream the one-byte type indicator for a four-byte
393 /// integer and the four-byte, two's complement integer (in network byte
394 /// order) comprised of the least-significant four bytes of the
395 /// specified `value` (in host byte order), and return a reference to
396 /// this stream. If this stream is initially invalid, this operation
397 /// has no effect. If the next output operation has been set to be
398 /// marked invalid (see `makeNextInvalid`), reset this marking and emit
399 /// the invalid indicator instead of the type indicator.
401
402 /// Write to this stream the one-byte type indicator for a four-byte
403 /// unsigned integer and the four-byte, two's complement unsigned
404 /// integer (in network byte order) comprised of the least-significant
405 /// four bytes of the specified `value` (in host byte order), and return
406 /// a reference to this stream. If this stream is initially invalid,
407 /// this operation has no effect. If the next output operation has been
408 /// set to be marked invalid (see `makeNextInvalid`), reset this marking
409 /// and emit the invalid indicator instead of the type indicator.
410 TestOutStream& putUint32(unsigned int value);
411
412 /// Write to this stream the one-byte type indicator for a three-byte
413 /// integer and the three-byte, two's complement integer (in network
414 /// byte order) comprised of the least-significant three bytes of the
415 /// specified `value` (in host byte order), and return a reference to
416 /// this stream. If this stream is initially invalid, this operation
417 /// has no effect. If the next output operation has been set to be
418 /// marked invalid (see `makeNextInvalid`), reset this marking and emit
419 /// the invalid indicator instead of the type indicator.
421
422 /// Write to this stream the one-byte type indicator for a three-byte
423 /// unsigned integer and the three-byte, two's complement unsigned
424 /// integer (in network byte order) comprised of the least-significant
425 /// three bytes of the specified `value` (in host byte order), and
426 /// return a reference to this stream. If this stream is initially
427 /// invalid, this operation has no effect. If the next output operation
428 /// has been set to be marked invalid (see `makeNextInvalid`), reset
429 /// this marking and emit the invalid indicator instead of the type
430 /// indicator.
431 TestOutStream& putUint24(unsigned int value);
432
433 /// Write to this stream the one-byte type indicator for a two-byte
434 /// integer and the two-byte, two's complement integer (in network byte
435 /// order) comprised of the least-significant two bytes of the specified
436 /// `value` (in host byte order), and return a reference to this stream.
437 /// If this stream is initially invalid, this operation has no effect.
438 /// If the next output operation has been set to be marked invalid (see
439 /// `makeNextInvalid`), reset this marking and emit the invalid
440 /// indicator instead of the type indicator.
442
443 /// Write to this stream the one-byte type indicator for a two-byte
444 /// unsigned integer and the two-byte, two's complement unsigned integer
445 /// (in network byte order) comprised of the least-significant two bytes
446 /// of the specified `value` (in host byte order), and return a
447 /// reference to this stream. If this stream is initially invalid, this
448 /// operation has no effect. If the next output operation has been set
449 /// to be marked invalid (see `makeNextInvalid`), reset this marking and
450 /// emit the invalid indicator instead of the type indicator.
451 TestOutStream& putUint16(unsigned int value);
452
453 /// Write to this stream the one-byte type indicator for a one-byte
454 /// integer and the one-byte, two's complement integer comprised of the
455 /// least-significant one byte of the specified `value`, and return a
456 /// reference to this stream. If this stream is initially invalid, this
457 /// operation has no effect. If the next output operation has been set
458 /// to be marked invalid (see `makeNextInvalid`), reset this marking and
459 /// emit the invalid indicator instead of the type indicator.
461
462 /// Write to this stream the one-byte type indicator for a one-byte
463 /// unsigned integer and the one-byte, two's complement unsigned integer
464 /// comprised of the least-significant one byte of the specified
465 /// `value`, and return a reference to this stream. If this stream is
466 /// initially invalid, this operation has no effect. If the next output
467 /// operation has been set to be marked invalid (see `makeNextInvalid`),
468 /// reset this marking and emit the invalid indicator instead of the
469 /// type indicator.
470 TestOutStream& putUint8(unsigned int value);
471
472 // *** scalar floating-point values ***
473
474 /// Write to this stream the one-byte type indicator for an eight-byte
475 /// double-precision floating-point number and the eight-byte IEEE
476 /// double-precision floating-point number (in network byte order)
477 /// comprised of the most-significant eight bytes of the specified
478 /// `value` (in host byte order), and return a reference to this stream.
479 /// If this stream is initially invalid, this operation has no effect.
480 /// If the next output operation has been set to be marked invalid (see
481 /// `makeNextInvalid`), reset this marking and emit the invalid
482 /// indicator instead of the type indicator. Note that for
483 /// non-conforming platforms, this operation may be lossy.
484 TestOutStream& putFloat64(double value);
485
486 /// Write to this stream the one-byte type indicator for a four-byte
487 /// single-precision floating-point number and the four-byte IEEE
488 /// single-precision floating-point number (in network byte order)
489 /// comprised of the most-significant four bytes of the specified
490 /// `value` (in host byte order), and return a reference to this stream.
491 /// If this stream is initially invalid, this operation has no effect.
492 /// If the next output operation has been set to be marked invalid (see
493 /// `makeNextInvalid`), reset this marking and emit the invalid
494 /// indicator instead of the type indicator. Note that for
495 /// non-conforming platforms, this operation may be lossy.
497
498 // *** string values ***
499
500 /// Write to this stream the one-byte type indicator for a length (see
501 /// `putLength`), the length of the specified `value` (see `putLength`),
502 /// the one-byte type indicator for an array of one-byte unsigned
503 /// integers, and an array of one-byte, two's complement unsigned
504 /// integers comprised of the least-significant one byte of each
505 /// character in the `value`, and return a reference to this stream. If
506 /// this stream is initially invalid, this operation has no effect. If
507 /// the next output operation has been set to be marked invalid (see
508 /// `makeNextInvalid`), reset this marking and emit the invalid
509 /// indicator instead of the type indicator.
510 TestOutStream& putString(const bsl::string& value);
511
512 // *** arrays of integer values ***
513
514 /// Write to this stream the one-byte type indicator for an eight-byte
515 /// integer, the four-byte, two's complement integer (in network byte
516 /// order) comprised of the least-significant four bytes of the
517 /// specified `numValues` (in host byte order), and the consecutive
518 /// eight-byte, two's complement integers (in network byte order)
519 /// comprised of the least-significant eight bytes of each of the
520 /// `numValues` leading entries in the specified `values` (in host byte
521 /// order), and return a reference to this stream. If this stream is
522 /// initially invalid, this operation has no effect. If the next output
523 /// operation has been set to be marked invalid (see `makeNextInvalid`),
524 /// reset this marking and emit the invalid indicator instead of the
525 /// type indicator. The behavior is undefined unless `0 <= numValues`
526 /// and `values` has sufficient contents.
528 int numValues);
529
530 /// Write to this stream the one-byte type indicator for an eight-byte
531 /// unsigned integer, the four-byte, two's complement integer (in
532 /// network byte order) comprised of the least-significant four bytes of
533 /// the specified `numValues` (in host byte order), and the consecutive
534 /// eight-byte, two's complement unsigned integers (in network byte
535 /// order) comprised of the least-significant eight bytes of each of the
536 /// `numValues` leading entries in the specified `values` (in host byte
537 /// order), and return a reference to this stream. If this stream is
538 /// initially invalid, this operation has no effect. If the next output
539 /// operation has been set to be marked invalid (see `makeNextInvalid`),
540 /// reset this marking and emit the invalid indicator instead of the
541 /// type indicator. The behavior is undefined unless `0 <= numValues`
542 /// and `values` has sufficient contents.
544 int numValues);
545
546 /// Write to this stream the one-byte type indicator for a seven-byte
547 /// integer, the four-byte, two's complement integer (in network byte
548 /// order) comprised of the least-significant four bytes of the
549 /// specified `numValues` (in host byte order), and the consecutive
550 /// seven-byte, two's complement integers (in network byte order)
551 /// comprised of the least-significant seven bytes of each of the
552 /// `numValues` leading entries in the specified `values` (in host byte
553 /// order), and return a reference to this stream. If this stream is
554 /// initially invalid, this operation has no effect. If the next output
555 /// operation has been set to be marked invalid (see `makeNextInvalid`),
556 /// reset this marking and emit the invalid indicator instead of the
557 /// type indicator. The behavior is undefined unless `0 <= numValues`
558 /// and `values` has sufficient contents.
560 int numValues);
561
562 /// Write to this stream the one-byte type indicator for a seven-byte
563 /// unsigned integer, the four-byte, two's complement integer (in
564 /// network byte order) comprised of the least-significant four bytes of
565 /// the specified `numValues` (in host byte order), and the consecutive
566 /// seven-byte, two's complement unsigned integers (in network byte
567 /// order) comprised of the least-significant seven bytes of each of the
568 /// `numValues` leading entries in the specified `values` (in host byte
569 /// order), and return a reference to this stream. If this stream is
570 /// initially invalid, this operation has no effect. If the next output
571 /// operation has been set to be marked invalid (see `makeNextInvalid`),
572 /// reset this marking and emit the invalid indicator instead of the
573 /// type indicator. The behavior is undefined unless `0 <= numValues`
574 /// and `values` has sufficient contents.
576 int numValues);
577
578 /// Write to this stream the one-byte type indicator for a six-byte
579 /// integer, the four-byte, two's complement integer (in network byte
580 /// order) comprised of the least-significant four bytes of the
581 /// specified `numValues` (in host byte order), and the consecutive
582 /// six-byte, two's complement integers (in network byte order)
583 /// comprised of the least-significant six bytes of each of the
584 /// `numValues` leading entries in the specified `values` (in host byte
585 /// order), and return a reference to this stream. If this stream is
586 /// initially invalid, this operation has no effect. If the next output
587 /// operation has been set to be marked invalid (see `makeNextInvalid`),
588 /// reset this marking and emit the invalid indicator instead of the
589 /// type indicator. The behavior is undefined unless `0 <= numValues`
590 /// and `values` has sufficient contents.
592 int numValues);
593
594 /// Write to this stream the one-byte type indicator for a six-byte
595 /// unsigned integer, the four-byte, two's complement integer (in
596 /// network byte order) comprised of the least-significant four bytes of
597 /// the specified `numValues` (in host byte order), and the consecutive
598 /// six-byte, two's complement unsigned integers (in network byte order)
599 /// comprised of the least-significant six bytes of each of the
600 /// `numValues` leading entries in the specified `values` (in host byte
601 /// order), and return a reference to this stream. If this stream is
602 /// initially invalid, this operation has no effect. If the next output
603 /// operation has been set to be marked invalid (see `makeNextInvalid`),
604 /// reset this marking and emit the invalid indicator instead of the
605 /// type indicator. The behavior is undefined unless `0 <= numValues`
606 /// and `values` has sufficient contents.
608 int numValues);
609
610 /// Write to this stream the one-byte type indicator for a five-byte
611 /// integer, the four-byte, two's complement integer (in network byte
612 /// order) comprised of the least-significant four bytes of the
613 /// specified `numValues` (in host byte order), and the consecutive
614 /// five-byte, two's complement integers (in network byte order)
615 /// comprised of the least-significant five bytes of each of the
616 /// `numValues` leading entries in the specified `values` (in host byte
617 /// order), and return a reference to this stream. If this stream is
618 /// initially invalid, this operation has no effect. If the next output
619 /// operation has been set to be marked invalid (see `makeNextInvalid`),
620 /// reset this marking and emit the invalid indicator instead of the
621 /// type indicator. The behavior is undefined unless `0 <= numValues`
622 /// and `values` has sufficient contents.
624 int numValues);
625
626 /// Write to this stream the one-byte type indicator for a five-byte
627 /// unsigned integer, the four-byte, two's complement integer (in
628 /// network byte order) comprised of the least-significant four bytes of
629 /// the specified `numValues` (in host byte order), and the consecutive
630 /// five-byte, two's complement unsigned integers (in network byte
631 /// order) comprised of the least-significant five bytes of each of the
632 /// `numValues` leading entries in the specified `values` (in host byte
633 /// order), and return a reference to this stream. If this stream is
634 /// initially invalid, this operation has no effect. If the next output
635 /// operation has been set to be marked invalid (see `makeNextInvalid`),
636 /// reset this marking and emit the invalid indicator instead of the
637 /// type indicator. The behavior is undefined unless `0 <= numValues`
638 /// and `values` has sufficient contents.
640 int numValues);
641
642 /// Write to this stream the one-byte type indicator for a four-byte
643 /// integer, the four-byte, two's complement integer (in network byte
644 /// order) comprised of the least-significant four bytes of the
645 /// specified `numValues` (in host byte order), and the consecutive
646 /// four-byte, two's complement integers (in network byte order)
647 /// comprised of the least-significant four bytes of each of the
648 /// `numValues` leading entries in the specified `values` (in host byte
649 /// order), and return a reference to this stream. If this stream is
650 /// initially invalid, this operation has no effect. If the next output
651 /// operation has been set to be marked invalid (see `makeNextInvalid`),
652 /// reset this marking and emit the invalid indicator instead of the
653 /// type indicator. The behavior is undefined unless `0 <= numValues`
654 /// and `values` has sufficient contents.
655 TestOutStream& putArrayInt32(const int *values, int numValues);
656
657 /// Write to this stream the one-byte type indicator for a four-byte
658 /// unsigned integer, the four-byte, two's complement integer (in
659 /// network byte order) comprised of the least-significant four bytes of
660 /// the specified `numValues` (in host byte order), and the consecutive
661 /// four-byte, two's complement unsigned integers (in network byte
662 /// order) comprised of the least-significant four bytes of each of the
663 /// `numValues` leading entries in the specified `values` (in host byte
664 /// order), and return a reference to this stream. If this stream is
665 /// initially invalid, this operation has no effect. If the next output
666 /// operation has been set to be marked invalid (see `makeNextInvalid`),
667 /// reset this marking and emit the invalid indicator instead of the
668 /// type indicator. The behavior is undefined unless `0 <= numValues`
669 /// and `values` has sufficient contents.
670 TestOutStream& putArrayUint32(const unsigned int *values, int numValues);
671
672 /// Write to this stream the one-byte type indicator for a three-byte
673 /// integer, the four-byte, two's complement integer (in network byte
674 /// order) comprised of the least-significant four bytes of the
675 /// specified `numValues` (in host byte order), and the consecutive
676 /// three-byte, two's complement integers (in network byte order)
677 /// comprised of the least-significant three bytes of each of the
678 /// `numValues` leading entries in the specified `values` (in host byte
679 /// order), and return a reference to this stream. If this stream is
680 /// initially invalid, this operation has no effect. If the next output
681 /// operation has been set to be marked invalid (see `makeNextInvalid`),
682 /// reset this marking and emit the invalid indicator instead of the
683 /// type indicator. The behavior is undefined unless `0 <= numValues`
684 /// and `values` has sufficient contents.
685 TestOutStream& putArrayInt24(const int *values, int numValues);
686
687 /// Write to this stream the one-byte type indicator for a three-byte
688 /// unsigned integer, the four-byte, two's complement integer (in
689 /// network byte order) comprised of the least-significant four bytes of
690 /// the specified `numValues` (in host byte order), and the consecutive
691 /// three-byte, two's complement unsigned integers (in network byte
692 /// order) comprised of the least-significant three bytes of each of the
693 /// `numValues` leading entries in the specified `values` (in host byte
694 /// order), and return a reference to this stream. If this stream is
695 /// initially invalid, this operation has no effect. If the next output
696 /// operation has been set to be marked invalid (see `makeNextInvalid`),
697 /// reset this marking and emit the invalid indicator instead of the
698 /// type indicator. The behavior is undefined unless `0 <= numValues`
699 /// and `values` has sufficient contents.
700 TestOutStream& putArrayUint24(const unsigned int *values, int numValues);
701
702 /// Write to this stream the one-byte type indicator for a two-byte
703 /// integer, the four-byte, two's complement integer (in network byte
704 /// order) comprised of the least-significant four bytes of the
705 /// specified `numValues` (in host byte order), and the consecutive
706 /// two-byte, two's complement integers (in network byte order)
707 /// comprised of the least-significant two bytes of each of the
708 /// `numValues` leading entries in the specified `values` (in host byte
709 /// order), and return a reference to this stream. If this stream is
710 /// initially invalid, this operation has no effect. If the next output
711 /// operation has been set to be marked invalid (see `makeNextInvalid`),
712 /// reset this marking and emit the invalid indicator instead of the
713 /// type indicator. The behavior is undefined unless `0 <= numValues`
714 /// and `values` has sufficient contents.
715 TestOutStream& putArrayInt16(const short *values, int numValues);
716
717 /// Write to this stream the one-byte type indicator for a two-byte
718 /// unsigned integer, the four-byte, two's complement integer (in
719 /// network byte order) comprised of the least-significant four bytes of
720 /// the specified `numValues` (in host byte order), and the consecutive
721 /// two-byte, two's complement unsigned integers (in network byte order)
722 /// comprised of the least-significant two bytes of each of the
723 /// `numValues` leading entries in the specified `values` (in host byte
724 /// order), and return a reference to this stream. If this stream is
725 /// initially invalid, this operation has no effect. If the next output
726 /// operation has been set to be marked invalid (see `makeNextInvalid`),
727 /// reset this marking and emit the invalid indicator instead of the
728 /// type indicator. The behavior is undefined unless `0 <= numValues`
729 /// and `values` has sufficient contents.
730 TestOutStream& putArrayUint16(const unsigned short *values, int numValues);
731
732 /// Write to this stream the one-byte type indicator for a one-byte
733 /// integer, the four-byte, two's complement integer (in network byte
734 /// order) comprised of the least-significant four bytes of the
735 /// specified `numValues` (in host byte order), and the consecutive
736 /// one-byte, two's complement integers comprised of the
737 /// least-significant one byte of each of the `numValues` leading
738 /// entries in the specified `values`, and return a reference to this
739 /// stream. If this stream is initially invalid, this operation has no
740 /// effect. If the next output operation has been set to be marked
741 /// invalid (see `makeNextInvalid`), reset this marking and emit the
742 /// invalid indicator instead of the type indicator. The behavior is
743 /// undefined unless `0 <= numValues` and `values` has sufficient
744 /// contents.
745 TestOutStream& putArrayInt8(const char *values, int numValues);
746 TestOutStream& putArrayInt8(const signed char *values, int numValues);
747
748 /// Write to this stream the one-byte type indicator for a one-byte
749 /// unsigned integer, the four-byte, two's complement integer (in
750 /// network byte order) comprised of the least-significant four bytes of
751 /// the specified `numValues` (in host byte order), and the consecutive
752 /// one-byte, two's complement unsigned integers comprised of the
753 /// least-significant one byte of each of the `numValues` leading
754 /// entries in the specified `values`, and return a reference to this
755 /// stream. If this stream is initially invalid, this operation has no
756 /// effect. If the next output operation has been set to be marked
757 /// invalid (see `makeNextInvalid`), reset this marking and emit the
758 /// invalid indicator instead of the type indicator. The behavior is
759 /// undefined unless `0 <= numValues` and `values` has sufficient
760 /// contents.
761 TestOutStream& putArrayUint8(const char *values, int numValues);
762 TestOutStream& putArrayUint8(const unsigned char *values, int numValues);
763
764 // *** arrays of floating-point values ***
765
766 /// Write to this stream the one-byte type indicator for an eight-byte
767 /// double-precision floating-point number, the four-byte, two's
768 /// complement integer (in network byte order) comprised of the
769 /// least-significant four bytes of the specified `numValues` (in host
770 /// byte order), and the consecutive eight-byte IEEE double-precision
771 /// floating-point numbers (in network byte order) comprised of the
772 /// most-significant eight bytes of each of the `numValues` leading
773 /// entries in the specified `values` (in host byte order), and return a
774 /// reference to this stream. If this stream is initially invalid, this
775 /// operation has no effect. If the next output operation has been set
776 /// to be marked invalid (see `makeNextInvalid`), reset this marking and
777 /// emit the invalid indicator instead of the type indicator. The
778 /// behavior is undefined unless `0 <= numValues` and `values` has
779 /// sufficient contents. Note that for non-conforming platforms, this
780 /// operation may be lossy.
781 TestOutStream& putArrayFloat64(const double *values, int numValues);
782
783 /// Write to this stream the one-byte type indicator for a four-byte
784 /// single-precision floating-point number, the four-byte, two's
785 /// complement integer (in network byte order) comprised of the
786 /// least-significant four bytes of the specified `numValues` (in host
787 /// byte order), and the consecutive four-byte IEEE single-precision
788 /// floating-point numbers (in network byte order) comprised of the
789 /// most-significant four bytes of each of the `numValues` leading
790 /// entries in the specified `values` (in host byte order), and return a
791 /// reference to this stream. If this stream is initially invalid, this
792 /// operation has no effect. If the next output operation has been set
793 /// to be marked invalid (see `makeNextInvalid`), reset this marking and
794 /// emit the invalid indicator instead of the type indicator. The
795 /// behavior is undefined unless `0 <= numValues` and `values` has
796 /// sufficient contents. Note that for non-conforming platforms, this
797 /// operation may be lossy.
798 TestOutStream& putArrayFloat32(const float *values, int numValues);
799
800 // ACCESSORS
801
802 /// Return a non-zero value if this stream is valid, and 0 otherwise.
803 /// An invalid stream is a stream for which an output operation was
804 /// detected to have failed or `invalidate` was called.
805 operator const void *() const;
806
807 /// Return the `versionSelector` to be used with `operator<<` for BDEX
808 /// streaming as per the `bslx` package-level documentation.
809 int bdexVersionSelector() const;
810
811 /// Return the address of the contiguous, non-modifiable internal memory
812 /// buffer of this stream. The address will remain valid as long as
813 /// this array is not destroyed or modified (i.e., the current capacity
814 /// is not exceeded). The behavior of accessing elements outside the
815 /// range `[ data() .. data() + (length() - 1) ]` is undefined.
816 const char *data() const;
817
818 /// Return `true` if this stream is valid, and `false` otherwise. An
819 /// invalid stream is a stream for which an output operation was
820 /// detected to have failed or `invalidate` was called.
821 bool isValid() const;
822
823 /// Return the number of bytes in this stream.
824 bsl::size_t length() const;
825};
826
827// FREE OPERATORS
828
829/// Write the specified `object` to the specified output `stream` in some
830/// reasonable (multi-line) format, and return a reference to `stream`.
831bsl::ostream& operator<<(bsl::ostream& stream,
832 const TestOutStream& object);
833
834/// Write the specified `value` to the specified output `stream` following
835/// the requirements of the BDEX protocol (see the `bslx` package-level
836/// documentation), and return a reference to `stream`. The behavior is
837/// undefined unless `TYPE` is BDEX-compliant.
838template <class TYPE>
839TestOutStream& operator<<(TestOutStream& stream, const TYPE& value);
840
841// ============================================================================
842// INLINE DEFINITIONS
843// ============================================================================
844
845 // -------------------
846 // class TestOutStream
847 // -------------------
848
849// MANIPULATORS
850inline
852{
853 d_imp.invalidate();
854}
855
856inline
858{
859 d_makeNextInvalidFlag = true;
860}
861
862inline
863void TestOutStream::reserveCapacity(bsl::size_t newCapacity)
864{
865 d_imp.reserveCapacity(newCapacity);
866}
867
868inline
870{
871 d_imp.reset();
872}
873
874 // *** string values ***
875
876inline
878{
879 putLength(static_cast<int>(value.length()));
880 return putArrayUint8(value.data(), static_cast<int>(value.length()));
881}
882
883// ACCESSORS
884inline
885TestOutStream::operator const void *() const
886{
887 return d_imp;
888}
889
890inline
892{
893 return d_imp.bdexVersionSelector();
894}
895
896inline
897const char *TestOutStream::data() const
898{
899 return d_imp.data();
900}
901
902inline
904{
905 return d_imp.isValid();
906}
907
908inline
909bsl::size_t TestOutStream::length() const
910{
911 return d_imp.length();
912}
913
914// FREE OPERATORS
915template <class TYPE>
916inline
917TestOutStream& operator<<(TestOutStream& stream, const TYPE& value)
918{
919 return OutStreamFunctions::bdexStreamOut(stream, value);
920}
921
922} // close package namespace
923
924
925// TRAITS
926
927namespace bslma {
928
929template <>
930struct UsesBslmaAllocator<bslx::TestOutStream> : bsl::true_type {};
931
932} // close namespace bslma
933
934
935#endif
936
937// ----------------------------------------------------------------------------
938// Copyright 2014 Bloomberg Finance L.P.
939//
940// Licensed under the Apache License, Version 2.0 (the "License");
941// you may not use this file except in compliance with the License.
942// You may obtain a copy of the License at
943//
944// http://www.apache.org/licenses/LICENSE-2.0
945//
946// Unless required by applicable law or agreed to in writing, software
947// distributed under the License is distributed on an "AS IS" BASIS,
948// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
949// See the License for the specific language governing permissions and
950// limitations under the License.
951// ----------------------------- END-OF-FILE ----------------------------------
952
953/** @} */
954/** @} */
955/** @} */
Definition bslstl_string.h:1281
size_type length() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6601
CHAR_TYPE * data() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6477
Definition bslma_allocator.h:457
Definition bslx_byteoutstream.h:212
void invalidate()
Definition bslx_byteoutstream.h:697
bool isValid() const
Definition bslx_byteoutstream.h:1583
void reserveCapacity(bsl::size_t newCapacity)
Definition bslx_byteoutstream.h:722
bsl::size_t length() const
Return the number of bytes in this stream.
Definition bslx_byteoutstream.h:1589
const char * data() const
Definition bslx_byteoutstream.h:1577
int bdexVersionSelector() const
Definition bslx_byteoutstream.h:1571
void reset()
Definition bslx_byteoutstream.h:728
Definition bslx_testoutstream.h:220
TestOutStream & putUint48(bsls::Types::Uint64 value)
TestOutStream & putArrayUint32(const unsigned int *values, int numValues)
TestOutStream & putUint16(unsigned int value)
TestOutStream & putInt24(int value)
TestOutStream(int versionSelector, bsl::size_t initialCapacity, bslma::Allocator *basicAllocator=0)
TestOutStream & putArrayUint56(const bsls::Types::Uint64 *values, int numValues)
TestOutStream & putInt56(bsls::Types::Int64 value)
TestOutStream & putLength(int length)
TestOutStream & putFloat64(double value)
TestOutStream & putArrayInt64(const bsls::Types::Int64 *values, int numValues)
TestOutStream & putArrayInt48(const bsls::Types::Int64 *values, int numValues)
TestOutStream & putUint8(unsigned int value)
TestOutStream & putArrayUint48(const bsls::Types::Uint64 *values, int numValues)
TestOutStream & putArrayInt8(const signed char *values, int numValues)
TestOutStream & putUint32(unsigned int value)
TestOutStream & putInt48(bsls::Types::Int64 value)
TestOutStream & putString(const bsl::string &value)
Definition bslx_testoutstream.h:877
TestOutStream & putInt16(int value)
TestOutStream & putArrayFloat32(const float *values, int numValues)
void invalidate()
Definition bslx_testoutstream.h:851
void makeNextInvalid()
Definition bslx_testoutstream.h:857
TestOutStream & putUint24(unsigned int value)
TestOutStream & putArrayUint16(const unsigned short *values, int numValues)
TestOutStream & putArrayInt16(const short *values, int numValues)
TestOutStream & putArrayInt56(const bsls::Types::Int64 *values, int numValues)
int bdexVersionSelector() const
Definition bslx_testoutstream.h:891
TestOutStream & putUint56(bsls::Types::Uint64 value)
friend bsl::ostream & operator<<(bsl::ostream &, const TestOutStream &)
TestOutStream & putArrayFloat64(const double *values, int numValues)
void reserveCapacity(bsl::size_t newCapacity)
Definition bslx_testoutstream.h:863
void reset()
Definition bslx_testoutstream.h:869
TestOutStream(int versionSelector, bslma::Allocator *basicAllocator=0)
bool isValid() const
Definition bslx_testoutstream.h:903
TestOutStream & putArrayUint40(const bsls::Types::Uint64 *values, int numValues)
TestOutStream & putArrayUint8(const char *values, int numValues)
TestOutStream & putVersion(int version)
bsl::size_t length() const
Return the number of bytes in this stream.
Definition bslx_testoutstream.h:909
~TestOutStream()
Destroy this object.
TestOutStream & putInt32(int value)
const char * data() const
Definition bslx_testoutstream.h:897
TestOutStream & putInt40(bsls::Types::Int64 value)
TestOutStream & putFloat32(float value)
TestOutStream & putArrayInt24(const int *values, int numValues)
TestOutStream & putArrayUint24(const unsigned int *values, int numValues)
TestOutStream & putInt8(int value)
TestOutStream & putUint64(bsls::Types::Uint64 value)
TestOutStream & putInt64(bsls::Types::Int64 value)
TestOutStream & putUint40(bsls::Types::Uint64 value)
TestOutStream & putArrayInt40(const bsls::Types::Int64 *values, int numValues)
TestOutStream & putArrayUint64(const bsls::Types::Uint64 *values, int numValues)
TestOutStream & putArrayInt8(const char *values, int numValues)
TestOutStream & putArrayInt32(const int *values, int numValues)
TestOutStream & putArrayUint8(const unsigned char *values, int numValues)
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balxml_encoderoptions.h:68
STREAM & bdexStreamOut(STREAM &stream, const TYPE &value)
Definition bslx_outstreamfunctions.h:992
Definition bslx_byteinstream.h:377
bsl::ostream & operator<<(bsl::ostream &stream, const ByteInStream &object)
Definition bslma_usesbslmaallocator.h:343
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132