BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlb_bigendian.h
Go to the documentation of this file.
1/// @file bdlb_bigendian.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlb_bigendian.h -*-C++-*-
8#ifndef INCLUDED_BDLB_BIGENDIAN
9#define INCLUDED_BDLB_BIGENDIAN
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlb_bigendian bdlb_bigendian
15/// @brief Provide big-endian integer types.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlb
19/// @{
20/// @addtogroup bdlb_bigendian
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlb_bigendian-purpose"> Purpose</a>
25/// * <a href="#bdlb_bigendian-classes"> Classes </a>
26/// * <a href="#bdlb_bigendian-description"> Description </a>
27/// * <a href="#bdlb_bigendian-usage"> Usage </a>
28/// * <a href="#bdlb_bigendian-example-1-basic-use-of-bdlb-bigendian"> Example 1: Basic Use of bdlb::BigEndian </a>
29///
30/// # Purpose {#bdlb_bigendian-purpose}
31/// Provide big-endian integer types.
32///
33/// # Classes {#bdlb_bigendian-classes}
34///
35/// - bdlb::BigEndianInt16: signed 16-bit in-core big-endian integer
36/// - bdlb::BigEndianUint16: unsigned 16-bit in-core big-endian integer
37/// - bdlb::BigEndianInt32: signed 32-bit in-core big-endian integer
38/// - bdlb::BigEndianUint32: unsigned 32-bit in-core big-endian integer
39/// - bdlb::BigEndianInt64: signed 64-bit in-core big-endian integer
40/// - bdlb::BigEndianUint64: unsigned 64-bit in-core big-endian integer
41///
42/// @see bsls_types
43///
44/// # Description {#bdlb_bigendian-description}
45/// This component provides generic in-core big-endian integer
46/// types `bdlb::BigEndianInt16`, `bdlb::BigEndianUint16`,
47/// `bdlb::BigEndianInt32`, `bdlb::BigEndianUint32`, `bdlb::BigEndianInt64` and
48/// `bdlb::BigEndianUint64` that store integral values that they represent in a
49/// big-endian byte order. For example, an integer value 0x01020304 will be
50/// internally stored by the `bdlb::BigEndianInt32` object as 0x04030201 on
51/// little-endian platforms.
52///
53/// ## Usage {#bdlb_bigendian-usage}
54///
55///
56/// This section illustrates intended use of this component.
57///
58/// ### Example 1: Basic Use of bdlb::BigEndian {#bdlb_bigendian-example-1-basic-use-of-bdlb-bigendian}
59///
60///
61/// This example demonstrates using `bdlb::BigEndian` types to represent a
62/// structure meant to be exchanged over the network ( which historically uses
63/// big-endian byte order ) or stored in-core as big-endian integers. First, we
64/// define the structure:
65/// @code
66/// /// This structure represents the header of the protocol. All integer
67/// /// values are stored in the network byte-order (i.e., big-endian).
68/// struct ProtocolHeader {
69///
70/// bdlb::BigEndianUint16 d_protocolVersion;
71/// bdlb::BigEndianUint16 d_messageType;
72/// bdlb::BigEndianUint32 d_messageLength;
73/// };
74/// @endcode
75/// Next, we prepare in-memory representation of the protocol header with
76/// protocol version set to `0x1`, message type set to `0x02` and message length
77/// set to `0x1234` in the big-endian byte order (most significant bytes
78/// first):
79/// @code
80/// const char buffer[8] = { 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x12, 0x34 };
81/// @endcode
82/// Now, we create an instance of the `ProtocolHeader` structure and emulate
83/// packet reception over the network:
84/// @code
85/// struct ProtocolHeader header;
86/// assert(8 == sizeof(header));
87/// memcpy(static_cast<void*>(&header), buffer, 8);
88/// @endcode
89/// Next, we verify that actual in-core values depend on the endianess of the
90/// underlying platform:
91/// @code
92/// #ifdef BSLS_PLATFORM_IS_LITTLE_ENDIAN
93/// assert(0x0100 ==
94/// static_cast<short>(*(reinterpret_cast<unsigned short*>(
95/// &header.d_protocolVersion))));
96///
97/// assert(0x0200 ==
98/// static_cast<short>(*(reinterpret_cast<unsigned short*>(
99/// &header.d_messageType))));
100///
101/// assert(0x34120000 == *(reinterpret_cast<unsigned int*>(
102/// &header.d_messageLength)));
103/// #endif // BSLS_PLATFORM_IS_LITTLE_ENDIAN
104///
105/// #ifdef BSLS_PLATFORM_IS_BIG_ENDIAN
106/// assert(0x01 ==
107/// static_cast<short>(*(reinterpret_cast<unsigned short*>(
108/// &header.d_protocolVersion))));
109///
110/// assert(0x02 ==
111/// static_cast<short>(*(reinterpret_cast<unsigned short*>(
112/// &header.d_messageType))));
113///
114/// assert(0x1234 == *(reinterpret_cast<unsigned int*>(
115/// &header.d_messageLength)));
116/// #endif // BSLS_PLATFORM_IS_BIG_ENDIAN
117/// @endcode
118/// Finally, we verify that the received protocol header can be validated on
119/// platforms of any endianess:
120/// @code
121/// assert(0x01 == header.d_protocolVersion);
122/// assert(0x02 == header.d_messageType);
123/// assert(0x1234 == header.d_messageLength);
124/// @endcode
125/// @}
126/** @} */
127/** @} */
128
129/** @addtogroup bdl
130 * @{
131 */
132/** @addtogroup bdlb
133 * @{
134 */
135/** @addtogroup bdlb_bigendian
136 * @{
137 */
138
139#include <bdlscm_version.h>
140
141#include <bdlb_printmethods.h> // 'bdlb::HasPrintMethod'
142
145
146#include <bsls_byteorder.h>
147#include <bsls_platform.h>
148#include <bsls_types.h>
149
150#include <bsl_iosfwd.h>
151
152
153namespace bdlb {
154
155 // ====================
156 // class BigEndianInt16
157 // ====================
158
159/// This class provides a container for an in-core representation of a
160/// signed 16-bit big-endian integer. It supports a complete set of *value*
161/// *semantic* operations, including copy construction, assignment, equality
162/// comparison, `bsl::ostream` printing, and BDEX serialization.
163///
164/// \note Note that the copy constructor and copy-assignment operator are provided by the
165/// compiler. Any object of this class can be converted to a `short`
166/// allowing comparison with any other object of this class. This class is
167/// *exception* *neutral* with no guarantee of rollback: if an exception is
168/// thrown during the invocation of a method on a pre-existing object, the
169/// object is left in a valid state, but its value is undefined. In no
170/// event is memory leaked. Finally, *aliasing* (e.g., using all or part of
171/// an object as both source and destination) is supported in all cases.
172///
173/// See @ref bdlb_bigendian
175
176 // DATA
177 short d_value; // in-core value (network byte-order)
178
179 // FRIENDS
180 friend bool operator==(const BigEndianInt16& lhs,
181 const BigEndianInt16& rhs);
182 friend bool operator!=(const BigEndianInt16& lhs,
183 const BigEndianInt16& rhs);
184
185 public:
186 // TRAITS
189
190 // CLASS METHODS
191
192 /// Create and initialize a `BigEndianInt16` object that stores the
193 /// specified `value` as a signed 16-bit big-endian integer.
194 static BigEndianInt16 make(short value);
195
196#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
197
198 /// Return the most current BDEX streaming version number supported by
199 /// this class. See the `bslx` package-level documentation for more
200 /// information on BDEX streaming of value-semantic types and
201 /// containers.
202 static int maxSupportedBdexVersion();
203#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
204
205 /// Return the maximum valid BDEX format version, as indicated by the
206 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
207 ///
208 /// \note Note that the `versionSelector` is expected to be formatted
209 /// as `yyyymmdd`, a date representation. See the `bslx` package-level
210 /// documentation for more information on BDEX streaming of
211 /// value-semantic types and containers.
212 static int maxSupportedBdexVersion(int versionSelector);
213
214 // CREATORS
215 BigEndianInt16() = default;
216 BigEndianInt16(const BigEndianInt16& other) = default;
217 ~BigEndianInt16() = default;
218
219 // MANIPULATORS
220 BigEndianInt16& operator=(const BigEndianInt16& other) = default;
221
222 /// Store in this object the specified `value` as a signed 16-bit
223 /// big-endian integer, and return a reference to this modifiable
224 /// object.
225 BigEndianInt16& operator=(short value);
226
227 /// Assign to this object the value read from the specified input
228 /// `stream` using the specified `version` format, and return a
229 /// reference to `stream`. If `stream` is initially invalid, this
230 /// operation has no effect. If `version` is not supported, this object
231 /// is unaltered and `stream` is invalidated but otherwise unmodified.
232 /// If `version` is supported but `stream` becomes invalid during this
233 /// operation, this object has an undefined, but valid, state.
234 ///
235 /// \note Note that no version is read from `stream`. See the `bslx` package-level
236 /// documentation for more information on BDEX streaming of
237 /// value-semantic types and containers.
238 template <class STREAM>
239 STREAM& bdexStreamIn(STREAM& stream, int version);
240
241 // ACCESSORS
242
243 /// Return the value stored in this object as a `short` in the native
244 /// byte-order.
245 operator short() const;
246
247 /// Format this object to the specified output `stream` at the (absolute
248 /// value of) the optionally specified indentation `level` and return a
249 /// reference to `stream`. If `level` is specified, optionally specify
250 /// `spacesPerLevel`, the number of spaces per indentation level for
251 /// this and all of its nested objects. If `level` is negative,
252 /// suppress indentation of the first line. If `spacesPerLevel` is
253 /// negative, format the entire output on one line, suppressing all but
254 /// the initial indentation (as governed by `level`). If `stream` is
255 /// not valid on entry, this operation has no effect.
256 bsl::ostream& print(bsl::ostream& stream,
257 int level = 0,
258 int spacesPerLevel = 4) const;
259
260 /// Write this value to the specified output `stream` using the
261 /// specified `version` format, and return a reference to `stream`. If
262 /// `stream` is initially invalid, this operation has no effect. If
263 /// `version` is not supported, `stream` is invalidated but otherwise unmodified.
264 ///
265 /// \note Note that `version` is not written to `stream`. See
266 /// the `bslx` package-level documentation for more information on BDEX
267 /// streaming of value-semantic types and containers.
268 template <class STREAM>
269 STREAM& bdexStreamOut(STREAM& stream, int version) const;
270};
271
272// FREE OPERATORS
273
274/// Return `true` if the specified `lhs` and `rhs` `BigEndianInt16` objects
275/// have the same value, and `false` otherwise. Two `BigEndianInt16`
276/// objects have the same value if and only if the respective integral
277/// network byte-order values that they represent have the same value.
278bool operator==(const BigEndianInt16& lhs, const BigEndianInt16& rhs);
279
280/// Return `true` if the specified `lhs` and `rhs` `BigEndianInt16` objects
281/// do not have the same value, and `false` otherwise. Two `BigEndianInt16`
282/// objects do not have the same value if and only if the respective
283/// integral network byte-order values that they represent do not have the
284/// same value.
285bool operator!=(const BigEndianInt16& lhs, const BigEndianInt16& rhs);
286
287/// Write the specified `integer` to the specified output `stream` and
288/// return a reference to the modifiable `stream`.
289bsl::ostream& operator<<(bsl::ostream& stream,
290 const BigEndianInt16& integer);
291
292/// Invoke the specified `hashAlgorithm` on the attributes of the specified
293/// `object`.
294template <class HASH_ALGORITHM>
295void hashAppend(HASH_ALGORITHM& hashAlgorithm, const BigEndianInt16& object);
296
297 // =====================
298 // class BigEndianUint16
299 // =====================
300
301/// This class provides a container for an in-core representation of an
302/// unsigned 16-bit big-endian integer. It supports a complete set of
303/// *value* *semantic* operations, including copy construction, assignment,
304/// equality comparison, `bsl::ostream` printing, and BDEX serialization.
305///
306/// \note Note that the copy constructor and copy-assignment operator are provided
307/// by the compiler. Any object of this class can be converted to an
308/// `unsigned short` allowing comparison with any other object of this
309/// class. This class is *exception* *neutral* with no guarantee of
310/// rollback: if an exception is thrown during the invocation of a method on
311/// a pre-existing object, the object is left in a valid state, but its
312/// value is undefined. In no event is memory leaked. Finally, *aliasing*
313/// (e.g., using all or part of an object as both source and destination) is
314/// supported in all cases.
315///
316/// See @ref bdlb_bigendian
318
319 // DATA
320 unsigned short d_value; // in-core value (network byte-order)
321
322 // FRIENDS
323 friend bool operator==(const BigEndianUint16& lhs,
324 const BigEndianUint16& rhs);
325 friend bool operator!=(const BigEndianUint16& lhs,
326 const BigEndianUint16& rhs);
327
328 public:
329 // TRAITS
333
334 // CLASS METHODS
335
336 /// Create and initialize a `BigEndianUint16` object that stores the
337 /// specified `value` as a unsigned 16-bit big-endian integer.
338 static BigEndianUint16 make(unsigned short value);
339
340#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
341
342 /// Return the most current BDEX streaming version number supported by
343 /// this class. See the `bslx` package-level documentation for more
344 /// information on BDEX streaming of value-semantic types and
345 /// containers.
346 static int maxSupportedBdexVersion();
347#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
348
349 /// Return the maximum valid BDEX format version, as indicated by the
350 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
351 ///
352 /// \note Note that the `versionSelector` is expected to be formatted
353 /// as `yyyymmdd`, a date representation. See the `bslx` package-level
354 /// documentation for more information on BDEX streaming of
355 /// value-semantic types and containers.
356 static int maxSupportedBdexVersion(int versionSelector);
357
358 // CREATORS
359 BigEndianUint16() = default;
360 BigEndianUint16(const BigEndianUint16& other) = default;
361 ~BigEndianUint16() = default;
362
363 // MANIPULATORS
364 BigEndianUint16& operator=(const BigEndianUint16& other) = default;
365
366 /// Store in this object the specified `value` as an unsigned 16-bit
367 /// big-endian integer, and return a reference to this modifiable
368 /// object.
369 BigEndianUint16& operator=(unsigned short value);
370
371 /// Assign to this object the value read from the specified input
372 /// `stream` using the specified `version` format, and return a
373 /// reference to `stream`. If `stream` is initially invalid, this
374 /// operation has no effect. If `version` is not supported, this object
375 /// is unaltered and `stream` is invalidated but otherwise unmodified.
376 /// If `version` is supported but `stream` becomes invalid during this
377 /// operation, this object has an undefined, but valid, state.
378 ///
379 /// \note Note that no version is read from `stream`. See the `bslx` package-level
380 /// documentation for more information on BDEX streaming of
381 /// value-semantic types and containers.
382 template <class STREAM>
383 STREAM& bdexStreamIn(STREAM& stream, int version);
384
385 // ACCESSORS
386
387 /// Return the value stored in this object as a `unsigned short` in the
388 /// native byte-order.
389 operator unsigned short() const;
390
391 /// Format this object to the specified output `stream` at the (absolute
392 /// value of) the optionally specified indentation `level` and return a
393 /// reference to `stream`. If `level` is specified, optionally specify
394 /// `spacesPerLevel`, the number of spaces per indentation level for
395 /// this and all of its nested objects. If `level` is negative,
396 /// suppress indentation of the first line. If `spacesPerLevel` is
397 /// negative, format the entire output on one line, suppressing all but
398 /// the initial indentation (as governed by `level`). If `stream` is
399 /// not valid on entry, this operation has no effect.
400 bsl::ostream& print(bsl::ostream& stream,
401 int level = 0,
402 int spacesPerLevel = 4) const;
403
404 /// Write this value to the specified output `stream` using the
405 /// specified `version` format, and return a reference to `stream`. If
406 /// `stream` is initially invalid, this operation has no effect. If
407 /// `version` is not supported, `stream` is invalidated but otherwise unmodified.
408 ///
409 /// \note Note that `version` is not written to `stream`. See
410 /// the `bslx` package-level documentation for more information on BDEX
411 /// streaming of value-semantic types and containers.
412 template <class STREAM>
413 STREAM& bdexStreamOut(STREAM& stream, int version) const;
414};
415
416// FREE OPERATORS
417
418/// Return `true` if the specified `lhs` and `rhs` `BigEndianUint16` objects
419/// have the same value, and `false` otherwise. Two `BigEndianUint16`
420/// objects have the same value if and only if the respective integral
421/// network byte-order values that they represent have the same value.
422bool operator==(const BigEndianUint16& lhs, const BigEndianUint16& rhs);
423
424/// Return `true` if the specified `lhs` and `rhs` `BigEndianUint16` objects
425/// do not have the same value, and `false` otherwise. Two
426/// `BigEndianUint16` objects do not have the same value if and only if the
427/// respective integral network byte-order values that they represent do not
428/// have the same value.
429bool operator!=(const BigEndianUint16& lhs, const BigEndianUint16& rhs);
430
431/// Write the specified `integer` to the specified output `stream`, and
432/// return a reference to the modifiable `stream`.
433bsl::ostream& operator<<(bsl::ostream& stream,
434 const BigEndianUint16& integer);
435
436/// Invoke the specified `hashAlgorithm` on the attributes of the specified
437/// `object`.
438template <class HASH_ALGORITHM>
439void hashAppend(HASH_ALGORITHM& hashAlgorithm, const BigEndianUint16& object);
440
441 // ====================
442 // class BigEndianInt32
443 // ====================
444
445/// This class provides a container for an in-core representation of a
446/// signed 32-bit big-endian integer. It supports a complete set of *value*
447/// *semantic* operations, including copy construction, assignment, equality
448/// comparison, `bsl::ostream` printing, and BDEX serialization.
449///
450/// \note Note that the copy constructor and copy-assignment operator are provided by the
451/// compiler. Any object of this class can be converted to an `int`
452/// allowing comparison with any other object of this class. This class is
453/// *exception* *neutral* with no guarantee of rollback: if an exception is
454/// thrown during the invocation of a method on a pre-existing object, the
455/// object is left in a valid state, but its value is undefined. In no
456/// event is memory leaked. Finally, *aliasing* (e.g., using all or part of
457/// an object as both source and destination) is supported in all cases.
458///
459/// See @ref bdlb_bigendian
461
462 // DATA
463 int d_value; // in-core value (network byte-order)
464
465 // FRIENDS
466 friend bool operator==(const BigEndianInt32& lhs,
467 const BigEndianInt32& rhs);
468 friend bool operator!=(const BigEndianInt32& lhs,
469 const BigEndianInt32& rhs);
470
471 public:
472 // TRAITS
475
476 // CLASS METHODS
477
478 /// Create and initialize a `BigEndianInt32` object that stores the
479 /// specified `value` as a signed 32-bit big-endian integer.
480 static BigEndianInt32 make(int value);
481
482#ifndef BDE_OMIT_INTERNAL_DEPRECATED
483 /// Return the most current BDEX streaming version number supported by
484 /// this class. See the `bslx` package-level documentation for more
485 /// information on BDEX streaming of value-semantic types and
486 /// containers.
487 static int maxSupportedBdexVersion();
488#endif // BDE_OMIT_INTERNAL_DEPRECATED
489
490 /// Return the maximum valid BDEX format version, as indicated by the
491 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
492 ///
493 /// \note Note that the `versionSelector` is expected to be formatted
494 /// as `yyyymmdd`, a date representation. See the `bslx` package-level
495 /// documentation for more information on BDEX streaming of
496 /// value-semantic types and containers.
497 static int maxSupportedBdexVersion(int versionSelector);
498
499 // CREATORS
500 BigEndianInt32() = default;
501 BigEndianInt32(const BigEndianInt32& other) = default;
502 ~BigEndianInt32() = default;
503
504 // MANIPULATORS
505 BigEndianInt32& operator=(const BigEndianInt32& other) = default;
506
507 /// Store in this object the specified `value` as a signed 32-bit
508 /// big-endian integer, and return a reference to this modifiable
509 /// object.
510 BigEndianInt32& operator=(int value);
511
512 /// Assign to this object the value read from the specified input
513 /// `stream` using the specified `version` format, and return a
514 /// reference to `stream`. If `stream` is initially invalid, this
515 /// operation has no effect. If `version` is not supported, this object
516 /// is unaltered and `stream` is invalidated but otherwise unmodified.
517 /// If `version` is supported but `stream` becomes invalid during this
518 /// operation, this object has an undefined, but valid, state.
519 ///
520 /// \note Note that no version is read from `stream`. See the `bslx` package-level
521 /// documentation for more information on BDEX streaming of
522 /// value-semantic types and containers.
523 template <class STREAM>
524 STREAM& bdexStreamIn(STREAM& stream, int version);
525
526 // ACCESSORS
527
528 /// Return the value stored in this object as a `int` in the native
529 /// byte-order.
530 operator int() const;
531
532 /// Format this object to the specified output `stream` at the (absolute
533 /// value of) the optionally specified indentation `level` and return a
534 /// reference to `stream`. If `level` is specified, optionally specify
535 /// `spacesPerLevel`, the number of spaces per indentation level for
536 /// this and all of its nested objects. If `level` is negative,
537 /// suppress indentation of the first line. If `spacesPerLevel` is
538 /// negative, format the entire output on one line, suppressing all but
539 /// the initial indentation (as governed by `level`). If `stream` is
540 /// not valid on entry, this operation has no effect.
541 bsl::ostream& print(bsl::ostream& stream,
542 int level = 0,
543 int spacesPerLevel = 4) const;
544
545 /// Write this value to the specified output `stream` using the
546 /// specified `version` format, and return a reference to `stream`. If
547 /// `stream` is initially invalid, this operation has no effect. If
548 /// `version` is not supported, `stream` is invalidated but otherwise unmodified.
549 ///
550 /// \note Note that `version` is not written to `stream`. See
551 /// the `bslx` package-level documentation for more information on BDEX
552 /// streaming of value-semantic types and containers.
553 template <class STREAM>
554 STREAM& bdexStreamOut(STREAM& stream, int version) const;
555};
556
557// FREE OPERATORS
558
559/// Return `true` if the specified `lhs` and `rhs` `BigEndianInt32` objects
560/// have the same value, and `false` otherwise. Two `BigEndianInt32`
561/// objects have the same value if and only if the respective integral
562/// network byte-order values that they represent have the same value.
563bool operator==(const BigEndianInt32& lhs, const BigEndianInt32& rhs);
564
565/// Return `true` if the specified `lhs` and `rhs` `BigEndianInt32` objects
566/// do not have the same value, and `false` otherwise. Two `BigEndianInt32`
567/// objects do not have the same value if and only if the respective
568/// integral network byte-order values that they represent do not have the
569/// same value.
570bool operator!=(const BigEndianInt32& lhs, const BigEndianInt32& rhs);
571
572/// Write the specified `integer` to the specified output `stream`, and
573/// return a reference to the modifiable `stream`.
574bsl::ostream& operator<<(bsl::ostream& stream,
575 const BigEndianInt32& integer);
576
577/// Invoke the specified `hashAlgorithm` on the attributes of the specified
578/// `object`.
579template <class HASH_ALGORITHM>
580void hashAppend(HASH_ALGORITHM& hashAlgorithm, const BigEndianInt32& object);
581
582 // =====================
583 // class BigEndianUint32
584 // =====================
585
586/// This class provides a container for an in-core representation of an
587/// unsigned 32-bit big-endian integer. It supports a complete set of
588/// *value* *semantic* operations, including copy construction, assignment,
589/// equality comparison, `bsl::ostream` printing, and BDEX serialization.
590///
591/// \note Note that the copy constructor and copy-assignment operator are provided
592/// by the compiler. Any object of this class can be converted to an
593/// `unsigned int` allowing comparison with any other object of this class.
594/// This class is *exception* *neutral* with no guarantee of rollback: if an
595/// exception is thrown during the invocation of a method on a pre-existing
596/// object, the object is left in a valid state, but its value is undefined.
597/// In no event is memory leaked. Finally, *aliasing* (e.g., using all or
598/// part of an object as both source and destination) is supported in all
599/// cases.
600///
601/// See @ref bdlb_bigendian
603
604 // DATA
605 unsigned int d_value; // in-core value (network byte-order)
606
607 // FRIENDS
608 friend bool operator==(const BigEndianUint32& lhs,
609 const BigEndianUint32& rhs);
610 friend bool operator!=(const BigEndianUint32& lhs,
611 const BigEndianUint32& rhs);
612
613 public:
614 // TRAITS
618
619 // CLASS METHODS
620
621 /// Create and initialize a `BigEndianUint32` object that stores the
622 /// specified `value` as a unsigned 32-bit big-endian integer.
623 static BigEndianUint32 make(unsigned int value);
624
625#ifndef BDE_OMIT_INTERNAL_DEPRECATED
626 /// Return the most current BDEX streaming version number supported by
627 /// this class. See the `bslx` package-level documentation for more
628 /// information on BDEX streaming of value-semantic types and
629 /// containers.
630 static int maxSupportedBdexVersion();
631#endif // BDE_OMIT_INTERNAL_DEPRECATED
632
633 /// Return the maximum valid BDEX format version, as indicated by the
634 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
635 ///
636 /// \note Note that the `versionSelector` is expected to be formatted
637 /// as `yyyymmdd`, a date representation. See the `bslx` package-level
638 /// documentation for more information on BDEX streaming of
639 /// value-semantic types and containers.
640 static int maxSupportedBdexVersion(int versionSelector);
641
642 // CREATORS
643 BigEndianUint32() = default;
644 BigEndianUint32(const BigEndianUint32& other) = default;
645 ~BigEndianUint32() = default;
646
647 // MANIPULATORS
648 BigEndianUint32& operator=(const BigEndianUint32& other) = default;
649
650 /// Store in this object the specified `value` as an unsigned 32-bit
651 /// big-endian integer, and return a reference to this modifiable
652 /// object.
653 BigEndianUint32& operator=(unsigned int value);
654
655 /// Assign to this object the value read from the specified input
656 /// `stream` using the specified `version` format, and return a
657 /// reference to `stream`. If `stream` is initially invalid, this
658 /// operation has no effect. If `version` is not supported, this object
659 /// is unaltered and `stream` is invalidated but otherwise unmodified.
660 /// If `version` is supported but `stream` becomes invalid during this
661 /// operation, this object has an undefined, but valid, state.
662 ///
663 /// \note Note that no version is read from `stream`. See the `bslx` package-level
664 /// documentation for more information on BDEX streaming of
665 /// value-semantic types and containers.
666 template <class STREAM>
667 STREAM& bdexStreamIn(STREAM& stream, int version);
668
669 // ACCESSORS
670
671 /// Return the value stored in this object as a `unsigned int` in the
672 /// native byte-order.
673 operator unsigned int() const;
674
675 /// Format this object to the specified output `stream` at the (absolute
676 /// value of) the optionally specified indentation `level` and return a
677 /// reference to `stream`. If `level` is specified, optionally specify
678 /// `spacesPerLevel`, the number of spaces per indentation level for
679 /// this and all of its nested objects. If `level` is negative,
680 /// suppress indentation of the first line. If `spacesPerLevel` is
681 /// negative, format the entire output on one line, suppressing all but
682 /// the initial indentation (as governed by `level`). If `stream` is
683 /// not valid on entry, this operation has no effect.
684 bsl::ostream& print(bsl::ostream& stream,
685 int level = 0,
686 int spacesPerLevel = 4) const;
687
688 /// Write this value to the specified output `stream` using the
689 /// specified `version` format, and return a reference to `stream`. If
690 /// `stream` is initially invalid, this operation has no effect. If
691 /// `version` is not supported, `stream` is invalidated but otherwise unmodified.
692 ///
693 /// \note Note that `version` is not written to `stream`. See
694 /// the `bslx` package-level documentation for more information on BDEX
695 /// streaming of value-semantic types and containers.
696 template <class STREAM>
697 STREAM& bdexStreamOut(STREAM& stream, int version) const;
698};
699
700// FREE OPERATORS
701
702/// Return `true` if the specified `lhs` and `rhs` `BigEndianUint32` objects
703/// have the same value, and `false` otherwise. Two `BigEndianUint32`
704/// objects have the same value if and only if the respective integral
705/// network byte-order values that they represent have the same value.
706bool operator==(const BigEndianUint32& lhs, const BigEndianUint32& rhs);
707
708/// Return `true` if the specified `lhs` and `rhs` `BigEndianUint32` objects
709/// do not have the same value, and `false` otherwise. Two
710/// `BigEndianUint32` objects do not have the same value if and only if the
711/// respective integral network byte-order values that they represent do not
712/// have the same value.
713bool operator!=(const BigEndianUint32& lhs, const BigEndianUint32& rhs);
714
715/// Write the specified `integer` to the specified output `stream`, and
716/// return a reference to the modifiable `stream`.
717bsl::ostream& operator<<(bsl::ostream& stream,
718 const BigEndianUint32& integer);
719
720/// Invoke the specified `hashAlgorithm` on the attributes of the specified
721/// `object`.
722template <class HASH_ALGORITHM>
723void hashAppend(HASH_ALGORITHM& hashAlgorithm, const BigEndianUint32& object);
724
725 // ====================
726 // class BigEndianInt64
727 // ====================
728
729/// This class provides a container for an in-core representation of a
730/// signed 64-bit big-endian integer. It supports a complete set of *value*
731/// *semantic* operations, including copy construction, assignment, equality
732/// comparison, `bsl::ostream` printing, and BDEX serialization.
733///
734/// \note Note that the copy constructor and copy-assignment operator are provided by the
735/// compiler. Any object of this class can be converted to an `Int64`
736/// allowing comparison with any other object of this class. This class is
737/// *exception* *neutral* with no guarantee of rollback: if an exception is
738/// thrown during the invocation of a method on a pre-existing object, the
739/// object is left in a valid state, but its value is undefined. In no
740/// event is memory leaked. Finally, *aliasing* (e.g., using all or part of
741/// an object as both source and destination) is supported in all cases.
742///
743/// See @ref bdlb_bigendian
745
746 // DATA
747 bsls::Types::Int64 d_value; // in-core value (network byte-order)
748
749 // FRIENDS
750 friend bool operator==(const BigEndianInt64& lhs,
751 const BigEndianInt64& rhs);
752 friend bool operator!=(const BigEndianInt64& lhs,
753 const BigEndianInt64& rhs);
754
755 public:
756 // TRAITS
759
760 // CLASS METHODS
761
762 /// Create and initialize a `BigEndianInt64` object that stores the
763 /// specified `value` as a signed 64-bit big-endian integer.
765
766#ifndef BDE_OMIT_INTERNAL_DEPRECATED
767
768 /// Return the most current BDEX streaming version number supported by
769 /// this class. See the `bslx` package-level documentation for more
770 /// information on BDEX streaming of value-semantic types and
771 /// containers.
772 static int maxSupportedBdexVersion();
773#endif // BDE_OMIT_INTERNAL_DEPRECATED
774
775 /// Return the maximum valid BDEX format version, as indicated by the
776 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
777 ///
778 /// \note Note that the `versionSelector` is expected to be formatted
779 /// as `yyyymmdd`, a date representation. See the `bslx` package-level
780 /// documentation for more information on BDEX streaming of
781 /// value-semantic types and containers.
782 static int maxSupportedBdexVersion(int versionSelector);
783
784 // CREATORS
785 BigEndianInt64() = default;
786 BigEndianInt64(const BigEndianInt64& other) = default;
787 ~BigEndianInt64() = default;
788
789 // MANIPULATORS
790 BigEndianInt64& operator=(const BigEndianInt64& other) = default;
791
792 /// Store in this object the specified `value` as a signed 64-bit
793 /// big-endian integer, and return a reference to this modifiable
794 /// object.
796
797 /// Assign to this object the value read from the specified input
798 /// `stream` using the specified `version` format, and return a
799 /// reference to `stream`. If `stream` is initially invalid, this
800 /// operation has no effect. If `version` is not supported, this object
801 /// is unaltered and `stream` is invalidated but otherwise unmodified.
802 /// If `version` is supported but `stream` becomes invalid during this
803 /// operation, this object has an undefined, but valid, state.
804 ///
805 /// \note Note that no version is read from `stream`. See the `bslx` package-level
806 /// documentation for more information on BDEX streaming of
807 /// value-semantic types and containers.
808 template <class STREAM>
809 STREAM& bdexStreamIn(STREAM& stream, int version);
810
811 // ACCESSORS
812
813 /// Return the value stored in this object as a `bsls::Types::Int64` in
814 /// the native byte-order.
815 operator bsls::Types::Int64() const;
816
817 /// Format this object to the specified output `stream` at the (absolute
818 /// value of) the optionally specified indentation `level` and return a
819 /// reference to `stream`. If `level` is specified, optionally specify
820 /// `spacesPerLevel`, the number of spaces per indentation level for
821 /// this and all of its nested objects. If `level` is negative,
822 /// suppress indentation of the first line. If `spacesPerLevel` is
823 /// negative, format the entire output on one line, suppressing all but
824 /// the initial indentation (as governed by `level`). If `stream` is
825 /// not valid on entry, this operation has no effect.
826 bsl::ostream& print(bsl::ostream& stream,
827 int level = 0,
828 int spacesPerLevel = 4) const;
829
830 /// Write this value to the specified output `stream` using the
831 /// specified `version` format, and return a reference to `stream`. If
832 /// `stream` is initially invalid, this operation has no effect. If
833 /// `version` is not supported, `stream` is invalidated but otherwise unmodified.
834 ///
835 /// \note Note that `version` is not written to `stream`. See
836 /// the `bslx` package-level documentation for more information on BDEX
837 /// streaming of value-semantic types and containers.
838 template <class STREAM>
839 STREAM& bdexStreamOut(STREAM& stream, int version) const;
840};
841
842// FREE OPERATORS
843
844/// Return `true` if the specified `lhs` and `rhs` `BigEndianInt64` objects
845/// have the same value, and `false` otherwise. Two `BigEndianInt64`
846/// objects have the same value if and only if the respective integral
847/// network byte-order values that they represent have the same value.
848bool operator==(const BigEndianInt64& lhs, const BigEndianInt64& rhs);
849
850/// Return `true` if the specified `lhs` and `rhs` `BigEndianInt64` objects
851/// do not have the same value, and `false` otherwise. Two `BigEndianInt64`
852/// objects do not have the same value if and only if the respective
853/// integral network byte-order values that they represent do not have the
854/// same value.
855bool operator!=(const BigEndianInt64& lhs, const BigEndianInt64& rhs);
856
857/// Write the specified `integer` to the specified output `stream`, and
858/// return a reference to the modifiable `stream`.
859bsl::ostream& operator<<(bsl::ostream& stream,
860 const BigEndianInt64& integer);
861
862/// Invoke the specified `hashAlgorithm` on the attributes of the specified
863/// `object`.
864template <class HASH_ALGORITHM>
865void hashAppend(HASH_ALGORITHM& hashAlgorithm, const BigEndianInt64& object);
866
867 // =====================
868 // class BigEndianUint64
869 // =====================
870
871/// This class provides a container for an in-core representation of an
872/// unsigned 64-bit big-endian integer. It supports a complete set of
873/// *value* *semantic* operations, including copy construction, assignment,
874/// equality comparison, `bsl::ostream` printing, and BDEX serialization.
875///
876/// \note Note that the copy constructor and copy-assignment operator are provided
877/// by the compiler. Any object of this class can be converted to a
878/// `Uint64` allowing comparison with any other object of this class. This
879/// class is *exception* *neutral* with no guarantee of rollback: if an
880/// exception is thrown during the invocation of a method on a pre-existing
881/// object, the object is left in a valid state, but its value is undefined.
882/// In no event is memory leaked. Finally, *aliasing* (e.g., using all or
883/// part of an object as both source and destination) is supported in all
884/// cases.
885///
886/// See @ref bdlb_bigendian
888
889 // DATA
890 bsls::Types::Uint64 d_value; // in-core value (network byte-order)
891
892 // FRIENDS
893 friend bool operator==(const BigEndianUint64& lhs,
894 const BigEndianUint64& rhs);
895 friend bool operator!=(const BigEndianUint64& lhs,
896 const BigEndianUint64& rhs);
897
898 public:
899 // TRAITS
903
904 // CLASS METHODS
905
906 /// Create and initialize a `BigEndianInt64` object that stores the
907 /// specified `value` as an unsigned 64-bit big-endian integer.
909
910#ifndef BDE_OMIT_INTERNAL_DEPRECATED
911 /// Return the most current BDEX streaming version number supported by
912 /// this class. See the `bslx` package-level documentation for more
913 /// information on BDEX streaming of value-semantic types and
914 /// containers.
915 static int maxSupportedBdexVersion();
916#endif // BDE_OMIT_INTERNAL_DEPRECATED
917
918 /// Return the maximum valid BDEX format version, as indicated by the
919 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
920 ///
921 /// \note Note that the `versionSelector` is expected to be formatted
922 /// as `yyyymmdd`, a date representation. See the `bslx` package-level
923 /// documentation for more information on BDEX streaming of
924 /// value-semantic types and containers.
925 static int maxSupportedBdexVersion(int versionSelector);
926
927 // CREATORS
928 BigEndianUint64() = default;
929 BigEndianUint64(const BigEndianUint64& other) = default;
930 ~BigEndianUint64() = default;
931
932 // MANIPULATORS
933 BigEndianUint64& operator=(const BigEndianUint64& other) = default;
934
935 /// Store in this object the specified `value` as an unsigned 64-bit
936 /// big-endian integer, and return a reference to this modifiable
937 /// object.
939
940 /// Assign to this object the value read from the specified input
941 /// `stream` using the specified `version` format, and return a
942 /// reference to `stream`. If `stream` is initially invalid, this
943 /// operation has no effect. If `version` is not supported, this object
944 /// is unaltered and `stream` is invalidated but otherwise unmodified.
945 /// If `version` is supported but `stream` becomes invalid during this
946 /// operation, this object has an undefined, but valid, state.
947 ///
948 /// \note Note that no version is read from `stream`. See the `bslx` package-level
949 /// documentation for more information on BDEX streaming of
950 /// value-semantic types and containers.
951 template <class STREAM>
952 STREAM& bdexStreamIn(STREAM& stream, int version);
953
954 // ACCESSORS
955
956 /// Return the value stored in this object as a `bsls::Types::Uint64` in
957 /// the native byte-order.
958 operator bsls::Types::Uint64() const;
959
960 /// Format this object to the specified output `stream` at the (absolute
961 /// value of) the optionally specified indentation `level` and return a
962 /// reference to `stream`. If `level` is specified, optionally specify
963 /// `spacesPerLevel`, the number of spaces per indentation level for
964 /// this and all of its nested objects. If `level` is negative,
965 /// suppress indentation of the first line. If `spacesPerLevel` is
966 /// negative, format the entire output on one line, suppressing all but
967 /// the initial indentation (as governed by `level`). If `stream` is
968 /// not valid on entry, this operation has no effect.
969 bsl::ostream& print(bsl::ostream& stream,
970 int level = 0,
971 int spacesPerLevel = 4) const;
972
973 /// Write this value to the specified output `stream` using the
974 /// specified `version` format, and return a reference to `stream`. If
975 /// `stream` is initially invalid, this operation has no effect. If
976 /// `version` is not supported, `stream` is invalidated but otherwise unmodified.
977 ///
978 /// \note Note that `version` is not written to `stream`. See
979 /// the `bslx` package-level documentation for more information on BDEX
980 /// streaming of value-semantic types and containers.
981 template <class STREAM>
982 STREAM& bdexStreamOut(STREAM& stream, int version) const;
983};
984
985// FREE OPERATORS
986
987/// Return `true` if the specified `lhs` and `rhs` `BigEndianUint64` objects
988/// have the same value, and `false` otherwise. Two `BigEndianUint64`
989/// objects have the same value if and only if the respective integral
990/// network byte-order values that they represent have the same value.
991bool operator==(const BigEndianUint64& lhs, const BigEndianUint64& rhs);
992
993/// Return `true` if the specified `lhs` and `rhs` `BigEndianUint64` objects
994/// do not have the same value, and `false` otherwise. Two
995/// `BigEndianUint64` objects do not have the same value if and only if the
996/// respective integral network byte-order values that they represent do not
997/// have the same value.
998bool operator!=(const BigEndianUint64& lhs, const BigEndianUint64& rhs);
999
1000/// Write the specified `integer` to the specified output `stream`, and
1001/// return a reference to the modifiable `stream`.
1002bsl::ostream& operator<<(bsl::ostream& stream, const BigEndianUint64& integer);
1003
1004/// Invoke the specified `hashAlgorithm` on the attributes of the specified
1005/// `object`.
1006template <class HASH_ALGORITHM>
1007void hashAppend(HASH_ALGORITHM& hashAlgorithm, const BigEndianUint64& object);
1008
1009// ============================================================================
1010// INLINE DEFINITIONS
1011// ============================================================================
1012
1013 // --------------------
1014 // class BigEndianInt16
1015 // --------------------
1016
1017// CLASS METHODS
1018inline
1020{
1021 BigEndianInt16 ret;
1022 return ret = value;
1023}
1024
1025#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1026inline
1031#endif // BDE_OMIT_INTERNAL_DEPRECATED
1032
1033inline
1034int BigEndianInt16::maxSupportedBdexVersion(int /* versionSelector */)
1035{
1036 return 1;
1037}
1038
1039// MANIPULATORS
1040inline
1042{
1043 d_value = BSLS_BYTEORDER_HOST_U16_TO_BE(value);
1044 return *this;
1045}
1046
1047template <class STREAM>
1048STREAM& BigEndianInt16::bdexStreamIn(STREAM& stream, int version)
1049{
1050 if (stream) {
1051 switch (version) {
1052 case 1: {
1053 stream.getArrayUint8(reinterpret_cast<unsigned char *>(&d_value),
1054 sizeof d_value);
1055 } break;
1056 default: {
1057 stream.invalidate();
1058 }
1059 }
1060 }
1061 return stream;
1062}
1063} // close package namespace
1064
1065// ACCESSORS
1066inline
1067bdlb::BigEndianInt16::operator short() const
1068{
1069 return BSLS_BYTEORDER_BE_U16_TO_HOST(d_value);
1070}
1071
1072namespace bdlb {
1073template <class STREAM>
1074STREAM& BigEndianInt16::bdexStreamOut(STREAM& stream, int version) const
1075{
1076 switch (version) {
1077 case 1: {
1078 stream.putArrayUint8(reinterpret_cast<const unsigned char *>(&d_value),
1079 sizeof d_value);
1080 } break;
1081 default: {
1082 stream.invalidate();
1083 }
1084 }
1085 return stream;
1086}
1087} // close package namespace
1088
1089// FREE OPERATORS
1090inline
1091bool bdlb::operator==(const BigEndianInt16& lhs, const BigEndianInt16& rhs)
1092{
1093 return lhs.d_value == rhs.d_value;
1094}
1095
1096inline
1097bool bdlb::operator!=(const BigEndianInt16& lhs, const BigEndianInt16& rhs)
1098{
1099 return lhs.d_value != rhs.d_value;
1100}
1101
1102inline
1103bsl::ostream& bdlb::operator<<(bsl::ostream& stream,
1104 const BigEndianInt16& integer)
1105{
1106 integer.print(stream, 0, -1);
1107 return stream;
1108}
1109
1110template <class HASH_ALGORITHM>
1111inline
1112void bdlb::hashAppend(HASH_ALGORITHM& hashAlgorithm,
1113 const BigEndianInt16& object)
1114{
1115 hashAlgorithm(reinterpret_cast<const char *>(&object),
1116 sizeof(BigEndianInt16));
1117}
1118
1119namespace bdlb {
1120 // ---------------------
1121 // class BigEndianUint16
1122 // ---------------------
1123
1124// CLASS METHODS
1125inline
1127{
1128 BigEndianUint16 ret;
1129 return ret = value;
1130}
1131
1132#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1133inline
1138#endif // BDE_OMIT_INTERNAL_DEPRECATED
1139
1140inline
1141int BigEndianUint16::maxSupportedBdexVersion(int /* versionSelector */)
1142{
1143 return 1;
1144}
1145
1146// MANIPULATORS
1147inline
1149{
1150 d_value = BSLS_BYTEORDER_HOST_U16_TO_BE(value);
1151 return *this;
1152}
1153
1154template <class STREAM>
1155STREAM& BigEndianUint16::bdexStreamIn(STREAM& stream, int version)
1156{
1157 if (stream) {
1158 switch (version) {
1159 case 1: {
1160 stream.getArrayUint8(reinterpret_cast<unsigned char *>(&d_value),
1161 sizeof d_value);
1162 } break;
1163 default: {
1164 stream.invalidate();
1165 }
1166 }
1167 }
1168 return stream;
1169}
1170} // close package namespace
1171
1172// ACCESSORS
1173inline
1174bdlb::BigEndianUint16::operator unsigned short() const
1175{
1176 return BSLS_BYTEORDER_BE_U16_TO_HOST(d_value);
1177}
1178
1179namespace bdlb {
1180template <class STREAM>
1181STREAM& BigEndianUint16::bdexStreamOut(STREAM& stream, int version) const
1182{
1183 switch (version) {
1184 case 1: {
1185 stream.putArrayUint8(reinterpret_cast<const unsigned char *>(&d_value),
1186 sizeof d_value);
1187 } break;
1188 default: {
1189 stream.invalidate();
1190 }
1191 }
1192 return stream;
1193}
1194} // close package namespace
1195
1196// FREE OPERATORS
1197inline
1198bool bdlb::operator==(const BigEndianUint16& lhs, const BigEndianUint16& rhs)
1199{
1200 return lhs.d_value == rhs.d_value;
1201}
1202
1203inline
1204bool bdlb::operator!=(const BigEndianUint16& lhs, const BigEndianUint16& rhs)
1205{
1206 return lhs.d_value != rhs.d_value;
1207}
1208
1209inline
1210bsl::ostream& bdlb::operator<<(bsl::ostream& stream,
1211 const BigEndianUint16& integer)
1212{
1213 integer.print(stream, 0, -1);
1214 return stream;
1215}
1216
1217template <class HASH_ALGORITHM>
1218inline
1219void bdlb::hashAppend(HASH_ALGORITHM& hashAlgorithm,
1220 const BigEndianUint16& object)
1221{
1222 hashAlgorithm(reinterpret_cast<const char *>(&object),
1223 sizeof(BigEndianUint16));
1224}
1225
1226namespace bdlb {
1227 // --------------------
1228 // class BigEndianInt32
1229 // --------------------
1230
1231// CLASS METHODS
1232inline
1234{
1235 BigEndianInt32 ret;
1236 return ret = value;
1237}
1238
1239#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1240inline
1245#endif // BDE_OMIT_INTERNAL_DEPRECATED
1246
1247inline
1248int BigEndianInt32::maxSupportedBdexVersion(int /* versionSelector */)
1249{
1250 return 1;
1251}
1252
1253// MANIPULATORS
1254inline
1256{
1257 d_value = BSLS_BYTEORDER_HOST_U32_TO_BE(value);
1258 return *this;
1259}
1260
1261template <class STREAM>
1262STREAM& BigEndianInt32::bdexStreamIn(STREAM& stream, int version)
1263{
1264 switch (version) {
1265 case 1: {
1266 stream.getArrayUint8(reinterpret_cast<unsigned char *>(&d_value),
1267 sizeof d_value);
1268 } break;
1269 default: {
1270 stream.invalidate();
1271 }
1272 }
1273 return stream;
1274}
1275} // close package namespace
1276
1277// ACCESSORS
1278inline
1279bdlb::BigEndianInt32::operator int() const
1280{
1281 return BSLS_BYTEORDER_BE_U32_TO_HOST(d_value);
1282}
1283
1284namespace bdlb {
1285template <class STREAM>
1286STREAM& BigEndianInt32::bdexStreamOut(STREAM& stream, int version) const
1287{
1288 switch (version) {
1289 case 1: {
1290 stream.putArrayUint8(reinterpret_cast<const unsigned char *>(&d_value),
1291 sizeof d_value);
1292 } break;
1293 default: {
1294 stream.invalidate();
1295 }
1296 }
1297 return stream;
1298}
1299} // close package namespace
1300
1301// FREE OPERATORS
1302inline
1303bool bdlb::operator==(const BigEndianInt32& lhs, const BigEndianInt32& rhs)
1304{
1305 return lhs.d_value == rhs.d_value;
1306}
1307
1308inline
1309bool bdlb::operator!=(const BigEndianInt32& lhs, const BigEndianInt32& rhs)
1310{
1311 return lhs.d_value != rhs.d_value;
1312}
1313
1314inline
1315bsl::ostream& bdlb::operator<<(bsl::ostream& stream,
1316 const BigEndianInt32& integer)
1317{
1318 integer.print(stream, 0, -1);
1319 return stream;
1320}
1321
1322template <class HASH_ALGORITHM>
1323inline
1324void bdlb::hashAppend(HASH_ALGORITHM& hashAlgorithm,
1325 const BigEndianInt32& object)
1326{
1327 hashAlgorithm(reinterpret_cast<const char *>(&object),
1328 sizeof(BigEndianInt32));
1329}
1330
1331namespace bdlb {
1332 // ---------------------
1333 // class BigEndianUint32
1334 // ---------------------
1335
1336// CLASS METHODS
1337inline
1339{
1340 BigEndianUint32 ret;
1341 return ret = value;
1342}
1343
1344#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1345inline
1350#endif // BDE_OMIT_INTERNAL_DEPRECATED
1351
1352inline
1353int BigEndianUint32::maxSupportedBdexVersion(int /* versionSelector */)
1354{
1355 return 1;
1356}
1357
1358// MANIPULATORS
1359inline
1361{
1362 d_value = BSLS_BYTEORDER_HOST_U32_TO_BE(value);
1363 return *this;
1364}
1365
1366template <class STREAM>
1367STREAM& BigEndianUint32::bdexStreamIn(STREAM& stream, int version)
1368{
1369 if (stream) {
1370 switch (version) {
1371 case 1: {
1372 stream.getArrayUint8(reinterpret_cast<unsigned char *>(&d_value),
1373 sizeof d_value);
1374 } break;
1375 default: {
1376 stream.invalidate();
1377 }
1378 }
1379 }
1380 return stream;
1381}
1382} // close package namespace
1383
1384// ACCESSORS
1385inline
1386bdlb::BigEndianUint32::operator unsigned int() const
1387{
1388 return BSLS_BYTEORDER_BE_U32_TO_HOST(d_value);
1389}
1390
1391namespace bdlb {
1392template <class STREAM>
1393STREAM& BigEndianUint32::bdexStreamOut(STREAM& stream, int version) const
1394{
1395 switch (version) {
1396 case 1: {
1397 stream.putArrayUint8(reinterpret_cast<const unsigned char *>(&d_value),
1398 sizeof d_value);
1399 } break;
1400 default: {
1401 stream.invalidate();
1402 }
1403 }
1404 return stream;
1405}
1406} // close package namespace
1407
1408// FREE OPERATORS
1409inline
1410bool bdlb::operator==(const BigEndianUint32& lhs, const BigEndianUint32& rhs)
1411{
1412 return lhs.d_value == rhs.d_value;
1413}
1414
1415inline
1416bool bdlb::operator!=(const BigEndianUint32& lhs, const BigEndianUint32& rhs)
1417{
1418 return lhs.d_value != rhs.d_value;
1419}
1420
1421inline
1422bsl::ostream& bdlb::operator<<(bsl::ostream& stream,
1423 const BigEndianUint32& integer)
1424{
1425 integer.print(stream, 0, -1);
1426 return stream;
1427}
1428
1429template <class HASH_ALGORITHM>
1430inline
1431void bdlb::hashAppend(HASH_ALGORITHM& hashAlgorithm,
1432 const BigEndianUint32& object)
1433{
1434 hashAlgorithm(reinterpret_cast<const char *>(&object),
1435 sizeof(BigEndianUint32));
1436}
1437
1438namespace bdlb {
1439 // --------------------
1440 // class BigEndianInt64
1441 // --------------------
1442
1443// CLASS METHODS
1444inline
1446{
1447 BigEndianInt64 ret;
1448 return ret = value;
1449}
1450
1451#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1452inline
1457#endif // BDE_OMIT_INTERNAL_DEPRECATED
1458
1459inline
1460int BigEndianInt64::maxSupportedBdexVersion(int /* versionSelector */)
1461{
1462 return 1;
1463}
1464
1465// MANIPULATORS
1466inline
1468{
1469 d_value = BSLS_BYTEORDER_HOST_U64_TO_BE(value);
1470 return *this;
1471}
1472
1473template <class STREAM>
1474STREAM& BigEndianInt64::bdexStreamIn(STREAM& stream, int version)
1475{
1476 switch (version) {
1477 case 1: {
1478 stream.getArrayUint8(reinterpret_cast<unsigned char *>(&d_value),
1479 sizeof d_value);
1480 } break;
1481 default: {
1482 stream.invalidate();
1483 }
1484 }
1485 return stream;
1486}
1487} // close package namespace
1488
1489// ACCESSORS
1490inline
1491bdlb::BigEndianInt64::operator bsls::Types::Int64() const
1492{
1493 return BSLS_BYTEORDER_BE_U64_TO_HOST(d_value);
1494}
1495
1496namespace bdlb {
1497template <class STREAM>
1498STREAM& BigEndianInt64::bdexStreamOut(STREAM& stream, int version) const
1499{
1500 switch (version) {
1501 case 1: {
1502 stream.putArrayUint8(reinterpret_cast<const unsigned char *>(&d_value),
1503 sizeof d_value);
1504 } break;
1505 default: {
1506 stream.invalidate();
1507 }
1508 }
1509 return stream;
1510}
1511} // close package namespace
1512
1513// FREE OPERATORS
1514inline
1515bool bdlb::operator==(const BigEndianInt64& lhs, const BigEndianInt64& rhs)
1516{
1517 return lhs.d_value == rhs.d_value;
1518}
1519
1520inline
1521bool bdlb::operator!=(const BigEndianInt64& lhs, const BigEndianInt64& rhs)
1522{
1523 return lhs.d_value != rhs.d_value;
1524}
1525
1526inline
1527bsl::ostream& bdlb::operator<<(bsl::ostream& stream,
1528 const BigEndianInt64& integer)
1529{
1530 integer.print(stream, 0, -1);
1531 return stream;
1532}
1533
1534template <class HASH_ALGORITHM>
1535inline
1536void bdlb::hashAppend(HASH_ALGORITHM& hashAlgorithm,
1537 const BigEndianInt64& object)
1538{
1539 hashAlgorithm(reinterpret_cast<const char *>(&object),
1540 sizeof(BigEndianInt64));
1541}
1542
1543namespace bdlb {
1544 // ---------------------
1545 // class BigEndianUint64
1546 // ---------------------
1547
1548// CLASS METHODS
1549inline
1550BigEndianUint64 BigEndianUint64::make(bsls::Types::Uint64 value)
1551{
1552 BigEndianUint64 ret;
1553 return ret = value;
1554}
1555
1556#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1557inline
1558int BigEndianUint64::maxSupportedBdexVersion()
1559{
1560 return maxSupportedBdexVersion(0);
1561}
1562#endif // BDE_OMIT_INTERNAL_DEPRECATED
1563
1564inline
1565int BigEndianUint64::maxSupportedBdexVersion(int /* versionSelector */)
1566{
1567 return 1;
1568}
1569
1570// MANIPULATORS
1571inline
1572BigEndianUint64& BigEndianUint64::operator=(bsls::Types::Uint64 value)
1573{
1574 d_value = BSLS_BYTEORDER_HOST_U64_TO_BE(value);
1575 return *this;
1576}
1577
1578template <class STREAM>
1579STREAM& BigEndianUint64::bdexStreamIn(STREAM& stream, int version)
1580{
1581 switch (version) {
1582 case 1: {
1583 stream.getArrayUint8(reinterpret_cast<unsigned char *>(&d_value),
1584 sizeof d_value);
1585 } break;
1586 default: {
1587 stream.invalidate();
1588 }
1589 }
1590 return stream;
1591}
1592} // close package namespace
1593
1594// ACCESSORS
1595inline
1596bdlb::BigEndianUint64::operator bsls::Types::Uint64() const
1597{
1598 return BSLS_BYTEORDER_BE_U64_TO_HOST(d_value);
1599}
1600
1601namespace bdlb {
1602template <class STREAM>
1603STREAM& BigEndianUint64::bdexStreamOut(STREAM& stream, int version) const
1604{
1605 switch (version) {
1606 case 1: {
1607 stream.putArrayUint8(reinterpret_cast<const unsigned char *>(&d_value),
1608 sizeof d_value);
1609 } break;
1610 default: {
1611 stream.invalidate();
1612 }
1613 }
1614 return stream;
1615}
1616} // close package namespace
1617
1618// FREE OPERATORS
1619inline
1620bool bdlb::operator==(const BigEndianUint64& lhs, const BigEndianUint64& rhs)
1621{
1622 return lhs.d_value == rhs.d_value;
1623}
1624
1625inline
1626bool bdlb::operator!=(const BigEndianUint64& lhs, const BigEndianUint64& rhs)
1627{
1628 return lhs.d_value != rhs.d_value;
1629}
1630
1631inline
1632bsl::ostream& bdlb::operator<<(bsl::ostream& stream,
1633 const BigEndianUint64& integer)
1634{
1635 integer.print(stream, 0, -1);
1636 return stream;
1637}
1638
1639template <class HASH_ALGORITHM>
1640inline
1641void bdlb::hashAppend(HASH_ALGORITHM& hashAlgorithm,
1642 const BigEndianUint64& object)
1643{
1644 hashAlgorithm(reinterpret_cast<const char *>(&object),
1645 sizeof(BigEndianUint64));
1646}
1647
1648
1649
1650#endif
1651
1652// ----------------------------------------------------------------------------
1653// Copyright 2015 Bloomberg Finance L.P.
1654//
1655// Licensed under the Apache License, Version 2.0 (the "License");
1656// you may not use this file except in compliance with the License.
1657// You may obtain a copy of the License at
1658//
1659// http://www.apache.org/licenses/LICENSE-2.0
1660//
1661// Unless required by applicable law or agreed to in writing, software
1662// distributed under the License is distributed on an "AS IS" BASIS,
1663// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1664// See the License for the specific language governing permissions and
1665// limitations under the License.
1666// ----------------------------- END-OF-FILE ----------------------------------
1667
1668/** @} */
1669/** @} */
1670/** @} */
Definition bdlb_bigendian.h:174
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianInt16, bsl::is_trivially_copyable)
BigEndianInt16(const BigEndianInt16 &other)=default
BigEndianInt16()=default
friend bool operator==(const BigEndianInt16 &lhs, const BigEndianInt16 &rhs)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
friend bool operator!=(const BigEndianInt16 &lhs, const BigEndianInt16 &rhs)
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianInt16, bdlb::HasPrintMethod)
static int maxSupportedBdexVersion()
Definition bdlb_bigendian.h:1027
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_bigendian.h:1074
~BigEndianInt16()=default
BigEndianInt16 & operator=(const BigEndianInt16 &other)=default
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_bigendian.h:1048
static BigEndianInt16 make(short value)
Definition bdlb_bigendian.h:1019
Definition bdlb_bigendian.h:460
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianInt32, bsl::is_trivially_copyable)
friend bool operator!=(const BigEndianInt32 &lhs, const BigEndianInt32 &rhs)
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_bigendian.h:1286
BigEndianInt32 & operator=(const BigEndianInt32 &other)=default
BigEndianInt32()=default
friend bool operator==(const BigEndianInt32 &lhs, const BigEndianInt32 &rhs)
BigEndianInt32(const BigEndianInt32 &other)=default
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_bigendian.h:1262
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
~BigEndianInt32()=default
static int maxSupportedBdexVersion()
Definition bdlb_bigendian.h:1241
static BigEndianInt32 make(int value)
Definition bdlb_bigendian.h:1233
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianInt32, bdlb::HasPrintMethod)
Definition bdlb_bigendian.h:744
friend bool operator==(const BigEndianInt64 &lhs, const BigEndianInt64 &rhs)
BigEndianInt64 & operator=(const BigEndianInt64 &other)=default
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianInt64, bsl::is_trivially_copyable)
BigEndianInt64()=default
BigEndianInt64(const BigEndianInt64 &other)=default
static int maxSupportedBdexVersion()
Definition bdlb_bigendian.h:1453
friend bool operator!=(const BigEndianInt64 &lhs, const BigEndianInt64 &rhs)
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_bigendian.h:1498
static BigEndianInt64 make(bsls::Types::Int64 value)
Definition bdlb_bigendian.h:1445
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
~BigEndianInt64()=default
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianInt64, bdlb::HasPrintMethod)
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_bigendian.h:1474
Definition bdlb_bigendian.h:317
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_bigendian.h:1181
static int maxSupportedBdexVersion()
Definition bdlb_bigendian.h:1134
BigEndianUint16 & operator=(const BigEndianUint16 &other)=default
~BigEndianUint16()=default
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianUint16, bdlb::HasPrintMethod)
static BigEndianUint16 make(unsigned short value)
Definition bdlb_bigendian.h:1126
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_bigendian.h:1155
BigEndianUint16(const BigEndianUint16 &other)=default
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
friend bool operator!=(const BigEndianUint16 &lhs, const BigEndianUint16 &rhs)
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianUint16, bsl::is_trivially_copyable)
friend bool operator==(const BigEndianUint16 &lhs, const BigEndianUint16 &rhs)
Definition bdlb_bigendian.h:602
BigEndianUint32(const BigEndianUint32 &other)=default
BigEndianUint32 & operator=(const BigEndianUint32 &other)=default
static BigEndianUint32 make(unsigned int value)
Definition bdlb_bigendian.h:1338
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianUint32, bsl::is_trivially_copyable)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
~BigEndianUint32()=default
static int maxSupportedBdexVersion()
Definition bdlb_bigendian.h:1346
friend bool operator!=(const BigEndianUint32 &lhs, const BigEndianUint32 &rhs)
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianUint32, bdlb::HasPrintMethod)
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_bigendian.h:1367
friend bool operator==(const BigEndianUint32 &lhs, const BigEndianUint32 &rhs)
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_bigendian.h:1393
Definition bdlb_bigendian.h:887
friend bool operator!=(const BigEndianUint64 &lhs, const BigEndianUint64 &rhs)
~BigEndianUint64()=default
BigEndianUint64(const BigEndianUint64 &other)=default
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlb_bigendian.h:1603
BigEndianUint64 & operator=(const BigEndianUint64 &other)=default
static BigEndianUint64 make(bsls::Types::Uint64 value)
Definition bdlb_bigendian.h:1550
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianUint64, bsl::is_trivially_copyable)
static int maxSupportedBdexVersion()
Definition bdlb_bigendian.h:1558
friend bool operator==(const BigEndianUint64 &lhs, const BigEndianUint64 &rhs)
BSLMF_NESTED_TRAIT_DECLARATION(BigEndianUint64, bdlb::HasPrintMethod)
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlb_bigendian.h:1579
#define BSLS_BYTEORDER_BE_U16_TO_HOST(x)
Definition bsls_byteorder.h:369
#define BSLS_BYTEORDER_HOST_U16_TO_BE(x)
Definition bsls_byteorder.h:373
#define BSLS_BYTEORDER_HOST_U32_TO_BE(x)
Definition bsls_byteorder.h:374
#define BSLS_BYTEORDER_BE_U32_TO_HOST(x)
Definition bsls_byteorder.h:370
#define BSLS_BYTEORDER_BE_U64_TO_HOST(x)
Definition bsls_byteorder.h:371
#define BSLS_BYTEORDER_HOST_U64_TO_BE(x)
Definition bsls_byteorder.h:375
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlb_algorithmworkaroundutil.h:74
bool operator!=(const BigEndianInt16 &lhs, const BigEndianInt16 &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const BigEndianInt16 &integer)
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const BigEndianInt16 &object)
bool operator==(const BigEndianInt16 &lhs, const BigEndianInt16 &rhs)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
Definition bdlb_printmethods.h:306
Definition bslmf_istriviallycopyable.h:324
unsigned long long Uint64
Definition bsls_types.h:139
long long Int64
Definition bsls_types.h:134