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