BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslx_instreamfunctions.h
Go to the documentation of this file.
1/// @file bslx_instreamfunctions.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslx_instreamfunctions.h -*-C++-*-
8#ifndef INCLUDED_BSLX_INSTREAMFUNCTIONS
9#define INCLUDED_BSLX_INSTREAMFUNCTIONS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslx_instreamfunctions bslx_instreamfunctions
15/// @brief Facilitate uniform unexternalization of user and fundamental types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslx
19/// @{
20/// @addtogroup bslx_instreamfunctions
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslx_instreamfunctions-purpose"> Purpose</a>
25/// * <a href="#bslx_instreamfunctions-classes"> Classes </a>
26/// * <a href="#bslx_instreamfunctions-description"> Description </a>
27/// * <a href="#bslx_instreamfunctions-component-design-anticipated-usage-and-the-bdex-contract"> Component Design, Anticipated Usage, and the BDEX Contract </a>
28/// * <a href="#bslx_instreamfunctions-implementing-bdex-streaming-in-value-semantic-template-classes"> Implementing BDEX Streaming in Value-Semantic Template Classes </a>
29/// * <a href="#bslx_instreamfunctions-usage"> Usage </a>
30/// * <a href="#bslx_instreamfunctions-example-1-using-bslx-instreamfunctions-to-unexternalize-data"> Example 1: Using bslx::InStreamFunctions to Unexternalize Data </a>
31///
32/// # Purpose {#bslx_instreamfunctions-purpose}
33/// Facilitate uniform unexternalization of user and fundamental types.
34///
35/// # Classes {#bslx_instreamfunctions-classes}
36///
37/// - bslx::InStreamFunctions: namespace for BDEX unexternalization functions
38///
39/// @see bslx_outstreamfunctions, bslx_versionfunctions
40///
41/// # Description {#bslx_instreamfunctions-description}
42/// This component provides a namespace, `bslx::InStreamFunctions`,
43/// that facilitates uniform support for BDEX unexternalization across all
44/// BDEX-compliant user-defined types, including template types and containers,
45/// as well as those fundamental types (and `bsl::string` and `bsl::vector`) for
46/// which the BDEX protocol provides direct support.
47///
48/// The namespace `bslx::InStreamFunctions` facilitates client unexternalization
49/// of objects in a uniform, type-independent manner. It contains the
50/// `bdexStreamIn` function that unexternalizes objects of all BDEX-compliant
51/// types. This function unexternalizes the specified `object` in the specified
52/// `version` or the `version` read from the input stream as required by the
53/// BDEX protocol. The `bdexStreamIn` function is overloaded for fundamental
54/// types, enumeration types, `bsl::string`, and `bsl::vector`. Note that,
55/// excluding `bsl::vector`, version information is never read from the stream
56/// while unexternalizing these types.
57///
58/// By default, objects of enumeration type are streamed in as 32-bit `int`
59/// values. Users can override this behavior by providing overloads of the
60/// `InStreamFunctions::bdexStreamIn` function in the enumeration's namespace
61/// for their enumeration types. The general form of this overload is:
62/// @code
63/// template <class STREAM>
64/// STREAM& bdexStreamIn(STREAM& stream, MyEnum& variable, int version)
65/// {
66/// using bslx::InStreamFunctions::bdexStreamIn;
67///
68/// // Code to stream in objects of 'MyEnum' type.
69///
70/// return stream;
71/// }
72/// @endcode
73/// For value-semantic types that support the BDEX protocol, the free function
74/// `bdexStreamIn` calls the `bdexStreamIn` member function for that type.
75///
76/// ## Component Design, Anticipated Usage, and the BDEX Contract {#bslx_instreamfunctions-component-design-anticipated-usage-and-the-bdex-contract}
77///
78///
79/// @ref bslx_instreamfunctions is an integral part of the BDEX unexternalization
80/// contract. The BDEX contract is at least in part "collaborative", which is
81/// to say that each developer of a given *kind* of component (e.g., a stream or
82/// a value-semantic container) must comply with the relevant portions of the
83/// contract to ensure that the "system as a whole" works for everybody.
84/// @ref bslx_instreamfunctions plays several related but different roles in
85/// helping various developers to produce BDEX-compliant components. In this
86/// section we briefly highlight how and why @ref bslx_instreamfunctions is helpful
87/// (or required) for these different developers. By discussing different
88/// aspects of usage, we convey the general design goals of this component, and,
89/// to a certain extent, the overall BDEX contract. See the `bslx`
90/// package-level documentation for a full specification of the BDEX contract.
91///
92/// ### Implementing BDEX Streaming in Value-Semantic Template Classes {#bslx_instreamfunctions-implementing-bdex-streaming-in-value-semantic-template-classes}
93///
94///
95/// The author of a non-template value-semantic type has full knowledge of the
96/// details of the "value" of that type, and may choose to use the appropriate
97/// input stream `get` methods directly when implementing the required
98/// `bdexStreamIn` method for that type. However, if one or more aspects of the
99/// value are of template parameter type, then the author cannot in general know
100/// how to stream the value using the `get` methods. For example, if a type has
101/// as its value one `int` data member:
102/// @code
103/// int d_value;
104/// @endcode
105/// then the implementation of the `bdexStreamIn` method can contain:
106/// @code
107/// stream.getInt32(d_value);
108/// @endcode
109/// However, if the data member is of (template parameter) `VALUE_TYPE`:
110/// @code
111/// VALUE_TYPE d_value;
112/// @endcode
113/// then the implementation of the `bdexStreamIn` method must rely on the
114/// `bslx::InStreamFunctions` implementation to input the value:
115/// @code
116/// using bslx::InStreamFunctions::bdexStreamIn;
117/// bdexStreamIn(stream, d_value, 1);
118/// @endcode
119/// This call will resolve to the correct sequence of `get` calls no matter
120/// whether `VALUE_TYPE` is a fundamental type, a BDEX-compliant `enum`, or a
121/// proper BDEX-compliant class. In the latter two cases, the explicit
122/// specification of the version format (in this case, 1) guarantees the stable
123/// operation of this method whether or not `VALUE_TYPE` is provided additional
124/// version formats.
125///
126/// ## Usage {#bslx_instreamfunctions-usage}
127///
128///
129/// This section illustrates intended use of this component.
130///
131/// ### Example 1: Using bslx::InStreamFunctions to Unexternalize Data {#bslx_instreamfunctions-example-1-using-bslx-instreamfunctions-to-unexternalize-data}
132///
133///
134/// In this example we illustrate the primary intended use of the parameterized
135/// methods of this component, as well as a few trivial invocations just to show
136/// the syntax clearly. To accomplish this, we exhibit three separate example
137/// "components": an `enum`, a value-semantic point object, and an input stream.
138/// In all cases, the component designs are very simple, with much of the
139/// implied functionality omitted, in order to focus attention on the key
140/// aspects of the functionality of *this* component.
141///
142/// First, consider an `enum` `Color` that enumerates a set of colors:
143/// @code
144/// enum Color {
145/// RED = 0,
146/// GREEN = 1,
147/// BLUE = 2
148/// };
149/// @endcode
150/// Next, we consider a very special-purpose point that has as a data member its
151/// color. Such a point provides an excellent opportunity for factoring, but
152/// since we are interested in highlighting BDEX streaming of various types, we
153/// will present a simple and unfactored design here. In a real-world problem,
154/// the `mypoint` component would be implemented differently.
155///
156/// Note that the `MyPoint` class in this example represents its coordinates as
157/// `short` integer values; this is done to make the BDEX stream input byte
158/// pattern somewhat easier for the reader of this example to recognize when the
159/// input buffer is printed.
160/// @code
161/// // mypoint.h
162///
163/// class MyPoint {
164/// // This class provides a geometric point having integer coordinates and
165/// // an enumerated color property.
166///
167/// short d_x; // x coordinate
168/// short d_y; // y coordinate
169/// Color d_color; // enumerated color property
170///
171/// public:
172/// // CLASS METHODS
173/// // ...
174///
175/// // CREATORS
176/// MyPoint();
177/// // Create a default point.
178///
179/// MyPoint(short x, short y, Color color);
180/// // Create a point having the specified 'x' and 'y' coordinates
181/// // and the specified 'color'.
182///
183/// ~MyPoint();
184/// // Destroy this point.
185///
186/// // MANIPULATORS
187/// // ...
188///
189/// // ACCESSORS
190/// short x() const;
191/// // Return the x coordinate of this point.
192///
193/// short y() const;
194/// // Return the y coordinate of this point.
195///
196/// Color color() const;
197/// // Return the enumerated color of this point.
198///
199/// template <class STREAM>
200/// STREAM& bdexStreamIn(STREAM& stream, int version);
201/// // Assign to this object the value read from the specified input
202/// // 'stream' using the specified 'version' format, and return a
203/// // reference to 'stream'. If 'stream' is initially invalid, this
204/// // operation has no effect. If 'version' is not supported, this
205/// // object is unaltered and 'stream' is invalidated, but otherwise
206/// // unmodified. If 'version' is supported but 'stream' becomes
207/// // invalid during this operation, this object has an undefined, but
208/// // valid, state. Note that no version is read from 'stream'. See
209/// // the 'bslx' package-level documentation for more information on
210/// // BDEX streaming of value-semantic types and containers.
211/// };
212///
213/// // FREE OPERATORS
214/// inline
215/// bool operator==(const MyPoint& lhs, const MyPoint& rhs);
216/// // Return 'true' if the specified 'lhs' and 'rhs' points have the same
217/// // value, and 'false' otherwise. Two points have the same value if
218/// // they have the same x and y coordinates and the same color.
219/// @endcode
220/// Representative (inline) implementations of these methods are shown below:
221/// @code
222/// // ========================================================================
223/// // INLINE FUNCTION DEFINITIONS
224/// // ========================================================================
225///
226/// // CREATORS
227/// inline
228/// MyPoint::MyPoint()
229/// {
230/// }
231///
232/// inline
233/// MyPoint::MyPoint(short x, short y, Color color)
234/// : d_x(x)
235/// , d_y(y)
236/// , d_color(color)
237/// {
238/// }
239///
240/// inline
241/// MyPoint::~MyPoint()
242/// {
243/// }
244///
245/// // ...
246///
247/// // MANIPULATORS
248/// // ...
249///
250/// // ACCESSORS
251/// inline
252/// Color MyPoint::color() const
253/// {
254/// return d_color;
255/// }
256///
257/// inline
258/// short MyPoint::x() const
259/// {
260/// return d_x;
261/// }
262///
263/// inline
264/// short MyPoint::y() const
265/// {
266/// return d_y;
267/// }
268/// // ...
269///
270/// template <class STREAM>
271/// STREAM& MyPoint::bdexStreamIn(STREAM& stream, int version)
272/// {
273/// switch (version) {
274/// case 1: {
275/// stream.getInt16(d_x); // input the x coordinate
276/// stream.getInt16(d_y); // input the y coordinate
277/// char color;
278/// stream.getInt8(color); // input the color enum as one byte
279/// d_color = static_cast<Color>(color);
280/// } break;
281/// default: {
282/// stream.invalidate();
283/// } break;
284/// }
285/// return stream;
286/// }
287///
288/// // FREE OPERATORS
289/// inline
290/// bool operator==(const MyPoint& lhs, const MyPoint& rhs)
291/// {
292/// return lhs.x() == rhs.x()
293/// && lhs.y() == rhs.y()
294/// && lhs.color() == rhs.color();
295/// }
296/// @endcode
297/// Then, we will implement an extremely simple input stream that supports the
298/// BDEX documentation-only protocol. For simplicity, we will use an externally
299/// managed buffer, and will only show a few methods needed for this example.
300/// @code
301/// // myinstream.h
302/// // ...
303///
304/// class MyInStream {
305/// // This class implements a limited-size fixed-buffer input stream that
306/// // partially conforms to the BDEX protocol for input streams. This
307/// // class is suitable for demonstration purposes only.
308///
309/// const char *d_buffer; // input buffer, held but not owned
310/// int d_length; // length of 'd_buffer' (bytes)
311/// int d_cursor; // cursor (index into 'd_buffer')
312///
313/// public:
314/// // CREATORS
315/// MyInStream(const char *buffer, int length);
316/// // Create an input stream using the specified 'buffer' having the
317/// // specified 'length' (in bytes).
318///
319/// ~MyInStream();
320/// // Destroy this input byte stream.
321///
322/// // MANIPULATORS
323/// MyInStream& getVersion(int& version);
324/// // Consume a version value from this input stream, store that value
325/// // in the specified 'version', and return a reference to this
326/// // stream. ...
327///
328/// MyInStream& getInt32(int& value);
329/// // Consume a 32-bit signed integer value from this input stream,
330/// // store that value in the specified 'value', and return a reference
331/// // to this stream. ...
332///
333/// MyInStream& getInt16(short& value);
334/// // Consume a 16-bit signed integer value from this input stream,
335/// // store that value in the specified 'value', and return a reference
336/// // to this stream. ...
337///
338/// MyInStream& getInt8(char& value);
339/// // Consume an 8-bit signed integer value from this input stream,
340/// // store that value in the specified 'value', and return a reference
341/// // to this stream. ...
342///
343/// void invalidate();
344/// // Put this input stream in an invalid state. ...
345///
346/// // ACCESSORS
347/// operator const void *() const;
348/// // Return a non-zero value if this stream is valid, and 0
349/// // otherwise. An invalid stream is a stream in which insufficient
350/// // or invalid data was detected during an extraction operation.
351/// // Note that an empty stream will be valid unless an extraction
352/// // attempt or explicit invalidation causes it to be otherwise.
353///
354/// int cursor() const;
355/// // Return the index of the next byte to be extracted from this
356/// // stream.
357///
358/// bool isEmpty() const;
359/// // Return 'true' if this stream is empty, and 'false' otherwise.
360/// // Note that this function enables higher-level types to verify
361/// // that, after successfully reading all expected data, no data
362/// // remains.
363///
364/// int length() const;
365/// // Return the total number of bytes stored in this stream.
366/// };
367///
368/// @endcode
369/// The relevant (inline) implementations are as follows.
370/// @code
371/// // ========================================================================
372/// // INLINE FUNCTION DEFINITIONS
373/// // ========================================================================
374///
375/// // CREATORS
376/// inline
377/// MyInStream::MyInStream(const char *buffer, int length)
378/// : d_buffer(buffer)
379/// , d_length(length)
380/// , d_cursor(0)
381/// {
382/// }
383///
384/// inline
385/// MyInStream::~MyInStream()
386/// {
387/// }
388///
389/// // MANIPULATORS
390///
391/// inline
392/// MyInStream& MyInStream::getVersion(int& value)
393/// {
394/// value = static_cast<unsigned char>(d_buffer[d_cursor++]);
395/// return *this;
396/// }
397///
398/// inline
399/// MyInStream& MyInStream::getInt32(int& value)
400/// {
401/// const unsigned char *buffer =
402/// reinterpret_cast<const unsigned char *>(d_buffer);
403/// value = static_cast<int>((buffer[d_cursor ] << 24U) |
404/// (buffer[d_cursor + 1] << 16U) |
405/// (buffer[d_cursor + 2] << 8U) |
406/// (buffer[d_cursor + 3] ));
407/// d_cursor += 4;
408/// return *this;
409/// }
410///
411/// inline
412/// MyInStream& MyInStream::getInt16(short& value)
413/// {
414/// const unsigned char *buffer =
415/// reinterpret_cast<const unsigned char *>(d_buffer);
416/// value = static_cast<short>((buffer[d_cursor ] << 8) |
417/// (buffer[d_cursor + 1] ));
418/// d_cursor += 2;
419/// return *this;
420/// }
421///
422/// inline
423/// MyInStream& MyInStream::getInt8(char& value)
424/// {
425/// value = d_buffer[d_cursor];
426/// d_cursor += 1;
427/// return *this;
428/// }
429///
430/// inline
431/// void MyInStream::invalidate()
432/// {
433/// d_buffer = 0;
434/// }
435///
436/// // ACCESSORS
437/// inline
438/// MyInStream::operator const void *() const
439/// {
440/// return d_cursor <= d_length ? d_buffer : 0;
441/// }
442///
443/// inline
444/// int MyInStream::cursor() const
445/// {
446/// return d_cursor;
447/// }
448///
449/// inline
450/// bool MyInStream::isEmpty() const
451/// {
452/// return d_cursor >= d_length;
453/// }
454///
455/// inline
456/// int MyInStream::length() const
457/// {
458/// return d_length;
459/// }
460/// @endcode
461/// Finally, use the above `enum`, point class, and input stream to illustrate
462/// `bslx::InStreamFunctions` functionality. This test code does not attempt to
463/// do anything more useful than reading values from a stream whose buffer was
464/// written "by hand" and confirming that the expected values were read
465/// correctly from the known byte pattern in the buffer.
466/// @code
467/// using bslx::InStreamFunctions::bdexStreamIn;
468///
469/// {
470/// const int EXP = 0x0A0B0C0D;
471/// const char buffer[4] = { 0xA, 0xB, 0xC, 0xD }; // 'int' (no version)
472/// int i = 0;
473///
474/// MyInStream in1(buffer, 4); // use the one buffer
475/// bdexStreamIn(in1, i, 1);
476/// assert(in1); assert(EXP == i);
477///
478/// i = 0; // reset 'i'
479/// MyInStream in2(buffer, 4); // re-use 'buffer (no version)
480/// bdexStreamIn(in2, i, 0);
481/// assert(in2); assert(EXP == i);
482/// }
483///
484/// {
485/// const MyPoint EXP(0, -1, BLUE);
486/// const char buffer1[5] = { 0, 0, -1, -1, 2 }; // 'MyPoint' (no ver)
487/// const char buffer2[6] = { 1, 0, 0, -1, -1, 2 }; // version, 'MyPoint'
488/// MyPoint p1, p2; // two default points
489///
490/// MyInStream in1(buffer1, 5); // 'buffer1' has no version byte
491/// bdexStreamIn(in1, p1, 1);
492/// assert(in1); assert(EXP == p1);
493///
494/// MyInStream in2(buffer2, 6); // 'buffer2' *has* a version
495/// int version;
496/// in2.getVersion(version);
497/// assert(1 == version);
498/// bdexStreamIn(in2, p2, version);
499/// assert(in2); assert(EXP == p2);
500/// }
501/// @endcode
502/// @}
503/** @} */
504/** @} */
505
506/** @addtogroup bsl
507 * @{
508 */
509/** @addtogroup bslx
510 * @{
511 */
512/** @addtogroup bslx_instreamfunctions
513 * @{
514 */
515
516#include <bslscm_version.h>
517
519
520#include <bslmf_assert.h>
521#include <bslmf_conditional.h>
522#include <bslmf_isenum.h>
523
524#include <bsls_performancehint.h>
525#include <bsls_types.h>
526
527#include <bsl_string.h>
528#include <bsl_vector.h>
529
530#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
531#include <bslmf_if.h>
532#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
533
534
535namespace bslx {
536 // ===========================
537 // namespace InStreamFunctions
538 // ===========================
539
540namespace InStreamFunctions {
541 // This namespace facilitates unexternalization of all BDEX-compliant types
542 // in a type-independent manner. The unexternalization functions are
543 // overloaded for fundamental types, enumeration types, 'bsl::string', and
544 // 'bsl::vector'. A compilation error will occur if the (template
545 // parameter) 'VALUE_TYPE' of a non-overloaded method of
546 // 'bslx::InStreamFunctions' does not support 'bdexStreamIn' (with the
547 // appropriate signature).
548
549 // ======================================
550 // class InStreamFunctions_AccessorHelper
551 // ======================================
552
553/// This `struct` provides a namespace for implementation helper functions
554/// for this component. They are not intended for use outside this
555/// component.
556template <class STREAM>
558
559 /// Load into the specified `result` the specified `length` values read
560 /// from the specified `stream`, and return a reference to `stream`. If
561 /// `stream` is initially invalid, `*result` is unchanged. If `stream`
562 /// becomes invalid during this operation, the contents of `result` have
563 /// an undefined, but valid, state.
564 static STREAM& getArray(STREAM& stream, bool *result, int length);
565 static STREAM& getArray(STREAM& stream, char *result, int length);
566 static STREAM& getArray(STREAM& stream, signed char *result, int length);
567 static STREAM& getArray(STREAM& stream, unsigned char *result, int length);
568 static STREAM& getArray(STREAM& stream, short *result, int length);
569 static STREAM& getArray(STREAM& stream,
570 unsigned short *result,
571 int length);
572 static STREAM& getArray(STREAM& stream, int *result, int length);
573 static STREAM& getArray(STREAM& stream, unsigned int *result, int length);
574 static STREAM& getArray(STREAM& stream,
575 bsls::Types::Int64 *result,
576 int length);
577 static STREAM& getArray(STREAM& stream,
578 bsls::Types::Uint64 *result,
579 int length);
580 static STREAM& getArray(STREAM& stream, float *result, int length);
581 static STREAM& getArray(STREAM& stream, double *result, int length);
582
583 /// Assign to the specified `variable` the
584 /// `bsl::vector<VALUE_TYPE, ALLOC>` value read from the specified input
585 /// `stream`, and return a reference to `stream`. If `stream` is
586 /// initially invalid, this operation has no effect. If `stream`
587 /// becomes invalid during this operation, `variable` has an undefined,
588 /// but valid, state.
589 template <class VALUE_TYPE, class ALLOC>
590 static STREAM& getArray(STREAM& stream,
592};
593
594 // =================
595 // struct IsEnumType
596 // =================
597
598/// This `struct`, together with `IsNotEnumType` (below), is used to
599/// distinguish enumeration types from other types in function overload
600/// resolution. This `struct` contains no interface or implementation by
601/// design, and is meant for internal use only.
603 };
604
605 // ====================
606 // struct IsNotEnumType
607 // ====================
608
609 /// This `struct`, together with `IsEnumType` (above), is used to
610 /// distinguish enumeration types from other types in function overload
611 /// resolution. This `struct` contains no interface or implementation
612 /// by design, and is meant for internal use only.
614 };
615
616 // PRIVATE CLASS METHODS
617
618 /// Assign to the specified `variable` the `VALUE_TYPE` value read from
619 /// the specified input `stream`, and return a reference to `stream`.
620 /// The specified `version` is ignored. If `stream` is initially
621 /// invalid, this operation has no effect. If `version` is not
622 /// supported by `VALUE_TYPE`, `variable` is unaltered and `stream` is
623 /// invalidated, but otherwise unmodified. If `version` is supported
624 /// but `stream` becomes invalid during this operation, `variable` has
625 /// an undefined, but valid, state. Note that this function is called
626 /// only for enumeration types and that this function is for internal
627 /// use only. See the `bslx` package-level documentation for more
628 /// information on BDEX streaming of value-semantic types and
629 /// containers.
630 template <class STREAM, class VALUE_TYPE>
631 STREAM& bdexStreamInImp(STREAM& stream,
632 VALUE_TYPE& variable,
633 int version,
634 const IsEnumType&);
635
636 /// Assign to the specified `variable` the `VALUE_TYPE` value read from
637 /// the specified input `stream` using the specified `version` format,
638 /// and return a reference to `stream`. If `stream` is initially
639 /// invalid, this operation has no effect. If `version` is not
640 /// supported by `VALUE_TYPE`, `variable` is unaltered and `stream` is
641 /// invalidated, but otherwise unmodified. If `version` is supported
642 /// but `stream` becomes invalid during this operation, `variable` has
643 /// an undefined, but valid, state. Note that this function is for
644 /// internal use only. See the `bslx` package-level documentation for
645 /// more information on BDEX streaming of value-semantic types and
646 /// containers.
647 template <class STREAM, class VALUE_TYPE>
648 STREAM& bdexStreamInImp(STREAM& stream,
649 VALUE_TYPE& variable,
650 int version,
651 const IsNotEnumType&);
652
653 // CLASS METHODS
654
655 /// Assign to the specified `variable` the `VALUE_TYPE` value read from
656 /// the specified input `stream`, and return a reference to `stream`.
657 /// If `stream` is initially invalid, this operation has no effect. If
658 /// needed, first read the version information from the `stream` and if
659 /// this version is not supported by `VALUE_TYPE`, `stream` is
660 /// invalidated, but otherwise unmodified. If `stream` becomes invalid
661 /// during this operation, `variable` has an undefined, but valid,
662 /// state. Note that the version is only needed when the (template
663 /// parameter) `VALUE_TYPE` is a `bsl::vector` or a user-defined type.
664 /// See the `bslx` package-level documentation for more information on
665 /// BDEX streaming of value-semantic types and containers.
666 template <class STREAM, class VALUE_TYPE>
667 STREAM& bdexStreamIn(STREAM& stream, VALUE_TYPE& variable);
668
669 /// Assign to the specified `variable` the `VALUE_TYPE` value read from
670 /// the specified input `stream` using the specified `version` format,
671 /// and return a reference to `stream`. If `stream` is initially
672 /// invalid, this operation has no effect. If `version` is not
673 /// supported by `VALUE_TYPE`, `variable` is unaltered and `stream` is
674 /// invalidated, but otherwise unmodified. If `version` is supported
675 /// but `stream` becomes invalid during this operation, `variable` has
676 /// an undefined, but valid, state. See the `bslx` package-level
677 /// documentation for more information on BDEX streaming of
678 /// value-semantic types and containers.
679 template <class STREAM, class VALUE_TYPE>
680 STREAM& bdexStreamIn(STREAM& stream, VALUE_TYPE& variable, int version);
681
682 /* overloads */
683
684 /// Assign to the specified `variable` the `bool` value read from the
685 /// specified input `stream`, and return a reference to `stream`. The
686 /// optionally specified `version` is ignored. If `stream` is initially
687 /// invalid, this operation has no effect. If `stream` becomes invalid
688 /// during this operation, `variable` has an undefined, but valid,
689 /// state. See the `bslx` package-level documentation for more
690 /// information on BDEX streaming of value-semantic types and
691 /// containers.
692 template <class STREAM>
693 STREAM& bdexStreamIn(STREAM& stream, bool& variable, int version = 0);
694
695 /// Assign to the specified `variable` the `char` value read from the
696 /// specified input `stream`, and return a reference to `stream`. The
697 /// optionally specified `version` is ignored. If `stream` is initially
698 /// invalid, this operation has no effect. If `stream` becomes invalid
699 /// during this operation, `variable` has an undefined, but valid,
700 /// state. See the `bslx` package-level documentation for more
701 /// information on BDEX streaming of value-semantic types and
702 /// containers.
703 template <class STREAM>
704 STREAM& bdexStreamIn(STREAM& stream, char& variable, int version = 0);
705
706 /// Assign to the specified `variable` the `signed char` value read from
707 /// the specified input `stream`, and return a reference to `stream`.
708 /// The optionally specified `version` is ignored. If `stream` is
709 /// initially invalid, this operation has no effect. If `stream`
710 /// becomes invalid during this operation, `variable` has an undefined,
711 /// but valid, state. See the `bslx` package-level documentation for
712 /// more information on BDEX streaming of value-semantic types and
713 /// containers.
714 template <class STREAM>
715 STREAM& bdexStreamIn(STREAM& stream,
716 signed char& variable,
717 int version = 0);
718
719 /// Assign to the specified `variable` the `unsigned char` value read
720 /// from the specified input `stream`, and return a reference to
721 /// `stream`. The optionally specified `version` is ignored. If
722 /// `stream` is initially invalid, this operation has no effect. If
723 /// `stream` becomes invalid during this operation, `variable` has an
724 /// undefined, but valid, state. See the `bslx` package-level
725 /// documentation for more information on BDEX streaming of
726 /// value-semantic types and containers.
727 template <class STREAM>
728 STREAM& bdexStreamIn(STREAM& stream,
729 unsigned char& variable,
730 int version = 0);
731
732 /// Assign to the specified `variable` the `short` value read from the
733 /// specified input `stream`, and return a reference to `stream`. The
734 /// optionally specified `version` is ignored. If `stream` is initially
735 /// invalid, this operation has no effect. If `stream` becomes invalid
736 /// during this operation, `variable` has an undefined, but valid,
737 /// state. See the `bslx` package-level documentation for more
738 /// information on BDEX streaming of value-semantic types and
739 /// containers.
740 template <class STREAM>
741 STREAM& bdexStreamIn(STREAM& stream, short& variable, int version = 0);
742
743 /// Assign to the specified `variable` the `unsigned short` value read
744 /// from the specified input `stream`, and return a reference to
745 /// `stream`. The optionally specified `version` is ignored. If
746 /// `stream` is initially invalid, this operation has no effect. If
747 /// `stream` becomes invalid during this operation, `variable` has an
748 /// undefined, but valid, state. See the `bslx` package-level
749 /// documentation for more information on BDEX streaming of
750 /// value-semantic types and containers.
751 template <class STREAM>
752 STREAM& bdexStreamIn(STREAM& stream,
753 unsigned short& variable,
754 int version = 0);
755
756 /// Assign to the specified `variable` the `int` value read from the
757 /// specified input `stream`, and return a reference to `stream`. The
758 /// optionally specified `version` is ignored. If `stream` is initially
759 /// invalid, this operation has no effect. If `stream` becomes invalid
760 /// during this operation, `variable` has an undefined, but valid,
761 /// state. See the `bslx` package-level documentation for more
762 /// information on BDEX streaming of value-semantic types and
763 /// containers.
764 template <class STREAM>
765 STREAM& bdexStreamIn(STREAM& stream, int& variable, int version = 0);
766
767 /// Assign to the specified `variable` the `unsigned int` value read
768 /// from the specified input `stream`, and return a reference to
769 /// `stream`. The optionally specified `version` is ignored. If
770 /// `stream` is initially invalid, this operation has no effect. If
771 /// `stream` becomes invalid during this operation, `variable` has an
772 /// undefined, but valid, state. See the `bslx` package-level
773 /// documentation for more information on BDEX streaming of
774 /// value-semantic types and containers.
775 template <class STREAM>
776 STREAM& bdexStreamIn(STREAM& stream,
777 unsigned int& variable,
778 int version = 0);
779
780 /// Assign to the specified `variable` the 32-bit `int` value read from
781 /// the specified input `stream`, and return a reference to `stream`.
782 /// The optionally specified `version` is ignored. If `stream` is
783 /// initially invalid, this operation has no effect. If `stream`
784 /// becomes invalid during this operation, `variable` has an undefined,
785 /// but valid, state. See the `bslx` package-level documentation for
786 /// more information on BDEX streaming of value-semantic types and
787 /// containers.
788 template <class STREAM>
789 STREAM& bdexStreamIn(STREAM& stream, long& variable, int version = 0);
790
791 /// Assign to the specified `variable` the 32-bit `unsigned int` value
792 /// read from the specified input `stream`, and return a reference to
793 /// `stream`. The optionally specified `version` is ignored. If
794 /// `stream` is initially invalid, this operation has no effect. If
795 /// `stream` becomes invalid during this operation, `variable` has an
796 /// undefined, but valid, state. See the `bslx` package-level
797 /// documentation for more information on BDEX streaming of
798 /// value-semantic types and containers.
799 template <class STREAM>
800 STREAM& bdexStreamIn(STREAM& stream,
801 unsigned long& variable,
802 int version = 0);
803
804 /// Assign to the specified `variable` the `bsls::Types::Int64` value
805 /// read from the specified input `stream`, and return a reference to
806 /// `stream`. The optionally specified `version` is ignored. If
807 /// `stream` is initially invalid, this operation has no effect. If
808 /// `stream` becomes invalid during this operation, `variable` has an
809 /// undefined, but valid, state. See the `bslx` package-level
810 /// documentation for more information on BDEX streaming of
811 /// value-semantic types and containers.
812 template <class STREAM>
813 STREAM& bdexStreamIn(STREAM& stream,
814 bsls::Types::Int64& variable,
815 int version = 0);
816
817 /// Assign to the specified `variable` the `bsls::Types::Uint64` value
818 /// read from the specified input `stream`, and return a reference to
819 /// `stream`. The optionally specified `version` is ignored. If
820 /// `stream` is initially invalid, this operation has no effect. If
821 /// `stream` becomes invalid during this operation, `variable` has an
822 /// undefined, but valid, state. See the `bslx` package-level
823 /// documentation for more information on BDEX streaming of
824 /// value-semantic types and containers.
825 template <class STREAM>
826 STREAM& bdexStreamIn(STREAM& stream,
827 bsls::Types::Uint64& variable,
828 int version = 0);
829
830 /// Assign to the specified `variable` the `float` value read from the
831 /// specified input `stream`, and return a reference to `stream`. The
832 /// optionally specified `version` is ignored. If `stream` is initially
833 /// invalid, this operation has no effect. If `stream` becomes invalid
834 /// during this operation, `variable` has an undefined, but valid,
835 /// state. See the `bslx` package-level documentation for more
836 /// information on BDEX streaming of value-semantic types and
837 /// containers.
838 template <class STREAM>
839 STREAM& bdexStreamIn(STREAM& stream, float& variable, int version = 0);
840
841 /// Assign to the specified `variable` the `double` value read from the
842 /// specified input `stream`, and return a reference to `stream`. The
843 /// optionally specified `version` is ignored. If `stream` is initially
844 /// invalid, this operation has no effect. If `stream` becomes invalid
845 /// during this operation, `variable` has an undefined, but valid,
846 /// state. See the `bslx` package-level documentation for more
847 /// information on BDEX streaming of value-semantic types and
848 /// containers.
849 template <class STREAM>
850 STREAM& bdexStreamIn(STREAM& stream, double& variable, int version = 0);
851
852 /// Assign to the specified `variable` the `bsl::string` value read from
853 /// the specified input `stream`, and return a reference to `stream`.
854 /// The optionally specified `version` is ignored. If `stream` is
855 /// initially invalid, this operation has no effect. If `stream`
856 /// becomes invalid during this operation, `variable` has an undefined,
857 /// but valid, state. See the `bslx` package-level documentation for
858 /// more information on BDEX streaming of value-semantic types and
859 /// containers.
860 template <class STREAM>
861 STREAM& bdexStreamIn(STREAM& stream,
862 bsl::string& variable,
863 int version = 0);
864
865 /// Assign to the specified `variable` the `bsl::vector<char, ALLOC>`
866 /// value read from the specified input `stream`, and return a reference
867 /// to `stream`. The specified `version` is ignored. If `stream` is
868 /// initially invalid, this operation has no effect. If `stream`
869 /// becomes invalid during this operation, `variable` has an undefined,
870 /// but valid, state. See the `bslx` package-level documentation for
871 /// more information on BDEX streaming of value-semantic types and
872 /// containers.
873 template <class STREAM, class ALLOC>
874 STREAM& bdexStreamIn(STREAM& stream,
875 bsl::vector<char, ALLOC>& variable,
876 int version);
877
878 /// Assign to the specified `variable` the
879 /// `bsl::vector<signed char, ALLOC>` value read from the specified
880 /// input `stream`, and return a reference to `stream`. The specified
881 /// `version` is ignored. If `stream` is initially invalid, this
882 /// operation has no effect. If `stream` becomes invalid during this
883 /// operation, `variable` has an undefined, but valid, state. See the
884 /// `bslx` package-level documentation for more information on BDEX
885 /// streaming of value-semantic types and containers.
886 template <class STREAM, class ALLOC>
887 STREAM& bdexStreamIn(STREAM& stream,
889 int version);
890
891 /// Assign to the specified `variable` the
892 /// `bsl::vector<unsigned char, ALLOC>` value read from the specified
893 /// input `stream`, and return a reference to `stream`. The specified
894 /// `version` is ignored. If `stream` is initially invalid, this
895 /// operation has no effect. If `stream` becomes invalid during this
896 /// operation, `variable` has an undefined, but valid, state. See the
897 /// `bslx` package-level documentation for more information on BDEX
898 /// streaming of value-semantic types and containers.
899 template <class STREAM, class ALLOC>
900 STREAM& bdexStreamIn(STREAM& stream,
902 int version);
903
904 /// Assign to the specified `variable` the `bsl::vector<short, ALLOC>`
905 /// value read from the specified input `stream`, and return a reference
906 /// to `stream`. The specified `version` is ignored. If `stream` is
907 /// initially invalid, this operation has no effect. If `stream`
908 /// becomes invalid during this operation, `variable` has an undefined,
909 /// but valid, state. See the `bslx` package-level documentation for
910 /// more information on BDEX streaming of value-semantic types and
911 /// containers.
912 template <class STREAM, class ALLOC>
913 STREAM& bdexStreamIn(STREAM& stream,
915 int version);
916
917 /// Assign to the specified `variable` the
918 /// `bsl::vector<unsigned short, ALLOC>` value read from the specified
919 /// input `stream`, and return a reference to `stream`. The specified
920 /// `version` is ignored. If `stream` is initially invalid, this
921 /// operation has no effect. If `stream` becomes invalid during this
922 /// operation, `variable` has an undefined, but valid, state. See the
923 /// `bslx` package-level documentation for more information on BDEX
924 /// streaming of value-semantic types and containers.
925 template <class STREAM, class ALLOC>
926 STREAM& bdexStreamIn(STREAM& stream,
928 int version);
929
930 /// Assign to the specified `variable` the `bsl::vector<int, ALLOC>`
931 /// value read from the specified input `stream`, and return a reference
932 /// to `stream`. The specified `version` is ignored. If `stream` is
933 /// initially invalid, this operation has no effect. If `stream`
934 /// becomes invalid during this operation, `variable` has an undefined,
935 /// but valid, state. See the `bslx` package-level documentation for
936 /// more information on BDEX streaming of value-semantic types and
937 /// containers.
938 template <class STREAM, class ALLOC>
939 STREAM& bdexStreamIn(STREAM& stream,
940 bsl::vector<int, ALLOC>& variable,
941 int version);
942
943 /// Assign to the specified `variable` the
944 /// `bsl::vector<unsigned int, ALLOC>` value read from the specified
945 /// input `stream`, and return a reference to `stream`. The specified
946 /// `version` is ignored. If `stream` is initially invalid, this
947 /// operation has no effect. If `stream` becomes invalid during this
948 /// operation, `variable` has an undefined, but valid, state. See the
949 /// `bslx` package-level documentation for more information on BDEX
950 /// streaming of value-semantic types and containers.
951 template <class STREAM, class ALLOC>
952 STREAM& bdexStreamIn(STREAM& stream,
954 int version);
955
956 /// Assign to the specified `variable` the
957 /// `bsl::vector<bsls::Types::Int64, ALLOC>` value read from the
958 /// specified input `stream`, and return a reference to `stream`. The
959 /// specified `version` is ignored. If `stream` is initially invalid,
960 /// this operation has no effect. If `stream` becomes invalid during
961 /// this operation, `variable` has an undefined, but valid, state. See
962 /// the `bslx` package-level documentation for more information on BDEX
963 /// streaming of value-semantic types and containers.
964 template <class STREAM, class ALLOC>
965 STREAM& bdexStreamIn(STREAM& stream,
967 int version);
968
969 /// Assign to the specified `variable` the
970 /// `bsl::vector<bsls::Types::Uint64, ALLOC>` value read from the
971 /// specified input `stream`, and return a reference to `stream`. The
972 /// specified `version` is ignored. If `stream` is initially invalid,
973 /// this operation has no effect. If `stream` becomes invalid during
974 /// this operation, `variable` has an undefined, but valid, state. See
975 /// the `bslx` package-level documentation for more information on BDEX
976 /// streaming of value-semantic types and containers.
977 template <class STREAM, class ALLOC>
978 STREAM& bdexStreamIn(STREAM& stream,
980 int version);
981
982 /// Assign to the specified `variable` the `bsl::vector<float, ALLOC>`
983 /// value read from the specified input `stream`, and return a reference
984 /// to `stream`. The specified `version` is ignored. If `stream` is
985 /// initially invalid, this operation has no effect. If `stream`
986 /// becomes invalid during this operation, `variable` has an undefined,
987 /// but valid, state. See the `bslx` package-level documentation for
988 /// more information on BDEX streaming of value-semantic types and
989 /// containers.
990 template <class STREAM, class ALLOC>
991 STREAM& bdexStreamIn(STREAM& stream,
993 int version);
994
995 /// Assign to the specified `variable` the `bsl::vector<double, ALLOC>`
996 /// value read from the specified input `stream`, and return a reference
997 /// to `stream`. The specified `version` is ignored. If `stream` is
998 /// initially invalid, this operation has no effect. If `stream`
999 /// becomes invalid during this operation, `variable` has an undefined,
1000 /// but valid, state. See the `bslx` package-level documentation for
1001 /// more information on BDEX streaming of value-semantic types and
1002 /// containers.
1003 template <class STREAM, class ALLOC>
1004 STREAM& bdexStreamIn(STREAM& stream,
1006 int version);
1007
1008 /// Assign to the specified `variable` the
1009 /// `bsl::vector<VALUE_TYPE, ALLOC>` value read from the specified input
1010 /// `stream`, and return a reference to `stream`. If `stream` is
1011 /// initially invalid, this operation has no effect. First read the
1012 /// version information from the `stream` and if this version is not
1013 /// supported by `VALUE_TYPE` and the vector is not empty, `stream` is
1014 /// invalidated, but otherwise unmodified. If `stream` becomes invalid
1015 /// during this operation, `variable` has an undefined, but valid,
1016 /// state. See the `bslx` package-level documentation for more
1017 /// information on BDEX streaming of value-semantic types and
1018 /// containers.
1019 template <class STREAM, class VALUE_TYPE, class ALLOC>
1020 STREAM& bdexStreamIn(STREAM& stream,
1022
1023 /// Assign to the specified `variable` the
1024 /// `bsl::vector<VALUE_TYPE, ALLOC>` value read from the specified input
1025 /// `stream` using the specified `version` format, and return a
1026 /// reference to `stream`. If `stream` is initially invalid, this
1027 /// operation has no effect. If `version` is not supported by
1028 /// `VALUE_TYPE` and the vector is not empty, `stream` is invalidated,
1029 /// but otherwise unmodified. If `stream` becomes invalid during this
1030 /// operation, `variable` has an undefined, but valid, state. See the
1031 /// `bslx` package-level documentation for more information on BDEX
1032 /// streaming of value-semantic types and containers.
1033 template <class STREAM, class VALUE_TYPE, class ALLOC>
1034 STREAM& bdexStreamIn(STREAM& stream,
1036 int version);
1037
1038} // close namespace InStreamFunctions
1039
1040// ============================================================================
1041// INLINE DEFINITIONS
1042// ============================================================================
1043
1044 // --------------------------------------
1045 // class InStreamFunctions_AccessorHelper
1046 // --------------------------------------
1047
1048template <class STREAM>
1049inline
1051 STREAM& stream,
1052 bool *result,
1053 int length)
1054{
1055 return stream.getArrayInt8(reinterpret_cast<char*>(result), length);
1056}
1057
1058template <class STREAM>
1059inline
1061 STREAM& stream,
1062 char *result,
1063 int length)
1064{
1065 return stream.getArrayInt8(result, length);
1066}
1067
1068template <class STREAM>
1069inline
1071 STREAM& stream,
1072 signed char *result,
1073 int length)
1074{
1075 return stream.getArrayInt8(result, length);
1076}
1077
1078template <class STREAM>
1079inline
1081 STREAM& stream,
1082 unsigned char *result,
1083 int length)
1084{
1085 return stream.getArrayUint8(result, length);
1086}
1087
1088template <class STREAM>
1089inline
1091 STREAM& stream,
1092 short *result,
1093 int length)
1094{
1095 return stream.getArrayInt16(result, length);
1096}
1097
1098template <class STREAM>
1099inline
1101 STREAM& stream,
1102 unsigned short *result,
1103 int length)
1104{
1105 return stream.getArrayUint16(result, length);
1106}
1107
1108template <class STREAM>
1109inline
1111 STREAM& stream,
1112 int *result,
1113 int length)
1114{
1115 return stream.getArrayInt32(result, length);
1116}
1117
1118template <class STREAM>
1119inline
1121 STREAM& stream,
1122 unsigned int *result,
1123 int length)
1124{
1125 return stream.getArrayUint32(result, length);
1126}
1127
1128template <class STREAM>
1129inline
1131 STREAM& stream,
1132 bsls::Types::Int64 *result,
1133 int length)
1134{
1135 return stream.getArrayInt64(result, length);
1136}
1137
1138template <class STREAM>
1139inline
1141 STREAM& stream,
1142 bsls::Types::Uint64 *result,
1143 int length)
1144{
1145 return stream.getArrayUint64(result, length);
1146}
1147
1148template <class STREAM>
1149inline
1151 STREAM& stream,
1152 float *result,
1153 int length)
1154{
1155 return stream.getArrayFloat32(result, length);
1156}
1157
1158template <class STREAM>
1159inline
1161 STREAM& stream,
1162 double *result,
1163 int length)
1164{
1165 return stream.getArrayFloat64(result, length);
1166}
1167
1168template <class STREAM>
1169template <class VALUE_TYPE, class ALLOC>
1171 STREAM& stream,
1173{
1174 int length = 0;
1175 stream.getLength(length);
1176
1177 if (!stream) {
1178 return stream; // RETURN
1179 }
1180
1181 // 'length' could be corrupt or invalid, so we limit the initial
1182 // 'resize' to something that can accommodate the preponderance of
1183 // vectors that will arise in practice. The remaining portion of a
1184 // vector longer than 16M is read in via a second pass.
1185 enum {
1186 k_INITIAL_ALLOCATION_COUNT = 16 * 1024 * 1024 / sizeof(VALUE_TYPE)
1187 };
1188
1189 const int initialLength = length < k_INITIAL_ALLOCATION_COUNT
1190 ? length
1191 : k_INITIAL_ALLOCATION_COUNT;
1192
1193 variable.resize(initialLength);
1194
1195 if (0 == length) {
1196 return stream; // RETURN
1197 }
1198
1199 STREAM& result = getArray(stream, &variable[0], initialLength);
1200
1201 if (!!stream && length > initialLength) {
1202 variable.resize(length);
1203 return getArray(stream,
1204 &variable[initialLength],
1205 length - initialLength); // RETURN
1206 }
1207
1208 return result;
1209}
1210
1211
1212 // ---------------------------
1213 // namespace InStreamFunctions
1214 // ---------------------------
1215
1216template <class STREAM, class VALUE_TYPE>
1217inline
1219 VALUE_TYPE& variable,
1220 int /* version */,
1221 const IsEnumType&)
1222{
1223 int enumVariable = 0;
1224 stream.getInt32(enumVariable);
1225
1226 if (stream) {
1227 variable = static_cast<VALUE_TYPE>(enumVariable);
1228 }
1229 return stream;
1230}
1231
1232template <class STREAM, class VALUE_TYPE>
1233inline
1235 VALUE_TYPE& variable,
1236 int version,
1237 const IsNotEnumType&)
1238{
1239 // A compilation error indicating the next line of code implies the class
1240 // of 'VALUE_TYPE' does not support the 'bdexStreamIn' method.
1241
1242 return variable.bdexStreamIn(stream, version);
1243}
1244
1245template <class STREAM, class VALUE_TYPE>
1246inline
1247STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream, VALUE_TYPE& variable)
1248{
1250
1251 // Determine if the 'VALUE_TYPE' requires a version to be externalized
1252 // using an arbitrary value for 'versionSelector'.
1253
1254 int version = maxSupportedBdexVersion(&variable, 0);
1255 if (VersionFunctions::k_NO_VERSION != version) {
1256 stream.getVersion(version);
1257
1258 if (!stream) {
1259 return stream; // RETURN
1260 }
1261 }
1262
1263 return bdexStreamIn(stream, variable, version);
1264}
1265
1266template <class STREAM, class VALUE_TYPE>
1267inline
1268STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1269 VALUE_TYPE& variable,
1270 int version)
1271{
1273 IsEnumType,
1274 IsNotEnumType>::type dummyType;
1275 return bdexStreamInImp(stream, variable, version, dummyType());
1276}
1277
1278template <class STREAM>
1279inline
1280STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1281 bool& variable,
1282 int /* version */)
1283{
1284 char temp = 0;
1285
1286 stream.getInt8(temp);
1287 variable = static_cast<bool>(temp);
1288
1289 return stream;
1290}
1291
1292template <class STREAM>
1293inline
1294STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1295 char& variable,
1296 int /* version */)
1297{
1298 return stream.getInt8(variable);
1299}
1300
1301template <class STREAM>
1302inline
1303STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1304 signed char& variable,
1305 int /* version */)
1306{
1307 return stream.getInt8(variable);
1308}
1309
1310template <class STREAM>
1311inline
1312STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1313 unsigned char& variable,
1314 int /* version */)
1315{
1316 return stream.getUint8(variable);
1317}
1318
1319template <class STREAM>
1320inline
1321STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1322 short& variable,
1323 int /* version */)
1324{
1325 return stream.getInt16(variable);
1326}
1327
1328template <class STREAM>
1329inline
1330STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1331 unsigned short& variable,
1332 int /* version */)
1333{
1334 return stream.getUint16(variable);
1335}
1336
1337template <class STREAM>
1338inline
1339STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1340 int& variable,
1341 int /* version */)
1342{
1343 return stream.getInt32(variable);
1344}
1345
1346template <class STREAM>
1347inline
1348STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1349 unsigned int& variable,
1350 int /* version */)
1351{
1352 return stream.getUint32(variable);
1353}
1354
1355template <class STREAM>
1356inline
1357STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1358 long& variable,
1359 int /* version */)
1360{
1361 int temp = 0; // 'long' and 'int' may not be the same size.
1362 stream.getInt32(temp);
1363 variable = temp;
1364 return stream;
1365}
1366
1367template <class STREAM>
1368inline
1369STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1370 unsigned long& variable,
1371 int /* version */)
1372{
1373 unsigned int temp = 0; // 'unsigned long' and 'unsigned int' may not be
1374 // the same size.
1375 stream.getUint32(temp);
1376 variable = temp;
1377 return stream;
1378}
1379
1380template <class STREAM>
1381inline
1382STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1383 bsls::Types::Int64& variable,
1384 int /* version */)
1385{
1386 return stream.getInt64(variable);
1387}
1388
1389template <class STREAM>
1390inline
1391STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1392 bsls::Types::Uint64& variable,
1393 int /* version */)
1394{
1395 return stream.getUint64(variable);
1396}
1397
1398template <class STREAM>
1399inline
1400STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1401 float& variable,
1402 int /* version */)
1403{
1404 return stream.getFloat32(variable);
1405}
1406
1407template <class STREAM>
1408inline
1409STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1410 double& variable,
1411 int /* version */)
1412{
1413 return stream.getFloat64(variable);
1414}
1415
1416template <class STREAM>
1417inline
1418STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1419 bsl::string& variable,
1420 int /* version */)
1421{
1422 return stream.getString(variable);
1423}
1424
1425template <class STREAM, class ALLOC>
1426inline
1427STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1428 bsl::vector<char, ALLOC>& variable,
1429 int /* version */)
1430{
1432 variable);
1433}
1434
1435template <class STREAM, class ALLOC>
1436inline
1438 STREAM& stream,
1440 int /* version */)
1441{
1443 variable);
1444}
1445
1446template <class STREAM, class ALLOC>
1447inline
1449 STREAM& stream,
1451 int /* version */)
1452{
1454 variable);
1455}
1456
1457template <class STREAM, class ALLOC>
1458inline
1459STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1460 bsl::vector<short, ALLOC>& variable,
1461 int /* version */)
1462{
1464 variable);
1465}
1466
1467template <class STREAM, class ALLOC>
1468inline
1470 STREAM& stream,
1472 int /* version */)
1473{
1475 variable);
1476}
1477
1478template <class STREAM, class ALLOC>
1479inline
1480STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1481 bsl::vector<int, ALLOC>& variable,
1482 int /* version */)
1483{
1485 variable);
1486}
1487
1488template <class STREAM, class ALLOC>
1489inline
1491 STREAM& stream,
1493 int /* version */)
1494{
1496 variable);
1497}
1498
1499template <class STREAM, class ALLOC>
1500inline
1502 STREAM& stream,
1504 int /* version */)
1505{
1507 variable);
1508}
1509
1510template <class STREAM, class ALLOC>
1511inline
1513 STREAM& stream,
1515 int /* version */)
1516{
1518 variable);
1519}
1520
1521template <class STREAM, class ALLOC>
1522inline
1523STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1524 bsl::vector<float, ALLOC>& variable,
1525 int /* version */)
1526{
1528 variable);
1529}
1530
1531template <class STREAM, class ALLOC>
1532inline
1533STREAM& InStreamFunctions::bdexStreamIn(STREAM& stream,
1535 int /* version */)
1536{
1538 variable);
1539}
1540
1541template <class STREAM, class VALUE_TYPE, class ALLOC>
1542inline
1544 STREAM& stream,
1546{
1547 int version = 0;
1548 stream.getVersion(version);
1549
1550 if (!stream) {
1551 return stream; // RETURN
1552 }
1553
1554 return bdexStreamIn(stream, variable, version);
1555}
1556
1557template <class STREAM, class VALUE_TYPE, class ALLOC>
1559 STREAM& stream,
1561 int version)
1562{
1563 typedef typename bsl::vector<VALUE_TYPE, ALLOC>::iterator Iterator;
1564
1565 int length = 0;
1566 stream.getLength(length);
1567
1568 if (!stream) {
1569 return stream; // RETURN
1570 }
1571
1572 // 'length' could be corrupt or invalid, so we limit the initial 'resize'
1573 // to something that can accommodate the preponderance of vectors that will
1574 // arise in practice. The remaining portion of a vector longer than 16M
1575 // bytes is read in via a second pass.
1576
1577 enum {
1578 k_INITIAL_ALLOCATION_COUNT =
1579 16 * 1024 * 1024 / sizeof(VALUE_TYPE)
1580 };
1581
1582 const int initialLength = length < k_INITIAL_ALLOCATION_COUNT
1583 ? length
1584 : k_INITIAL_ALLOCATION_COUNT;
1585
1586 variable.resize(initialLength);
1587
1588 if (0 == length) {
1589 return stream; // RETURN
1590 }
1591
1592 for (Iterator it = variable.begin(); it != variable.end(); ++it) {
1593 bdexStreamIn(stream, *it, version);
1594
1595
1598 return stream; // RETURN
1599 }
1600 }
1601
1602 if (length > initialLength) {
1603 variable.resize(length);
1604
1605 for (Iterator it = variable.begin() + initialLength;
1606 it != variable.end();
1607 ++it) {
1608 bdexStreamIn(stream, *it, version);
1609
1612 return stream; // RETURN
1613 }
1614 }
1615 }
1616
1617 return stream;
1618}
1619
1620} // close package namespace
1621
1622
1623#endif
1624
1625// ----------------------------------------------------------------------------
1626// Copyright 2014 Bloomberg Finance L.P.
1627//
1628// Licensed under the Apache License, Version 2.0 (the "License");
1629// you may not use this file except in compliance with the License.
1630// You may obtain a copy of the License at
1631//
1632// http://www.apache.org/licenses/LICENSE-2.0
1633//
1634// Unless required by applicable law or agreed to in writing, software
1635// distributed under the License is distributed on an "AS IS" BASIS,
1636// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1637// See the License for the specific language governing permissions and
1638// limitations under the License.
1639// ----------------------------- END-OF-FILE ----------------------------------
1640
1641/** @} */
1642/** @} */
1643/** @} */
Definition bslstl_string.h:1281
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2511
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2519
Definition bslstl_vector.h:1025
VALUE_TYPE * iterator
Definition bslstl_vector.h:1057
void resize(size_type newSize)
Definition bslstl_vector.h:3616
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
Definition bsls_performancehint.h:484
#define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr)
Definition bsls_performancehint.h:452
STREAM & bdexStreamIn(STREAM &stream, VALUE_TYPE &variable)
Definition bslx_instreamfunctions.h:1247
STREAM & bdexStreamInImp(STREAM &stream, VALUE_TYPE &variable, int version, const IsEnumType &)
Definition bslx_instreamfunctions.h:1218
int maxSupportedBdexVersion(const TYPE *, int versionSelector)
Definition bslx_versionfunctions.h:519
@ k_NO_VERSION
Definition bslx_versionfunctions.h:334
Definition bslx_byteinstream.h:377
Definition bslmf_conditional.h:120
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132
Definition bslx_instreamfunctions.h:557
static STREAM & getArray(STREAM &stream, bool *result, int length)
Definition bslx_instreamfunctions.h:1050
Definition bslx_instreamfunctions.h:602
Definition bslx_instreamfunctions.h:613