]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/endian/example/use_cases.cpp
1 // endian/example/uses_cases.cpp -----------------------------------------------------//
3 // Copyright Beman Dawes 2014
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 //--------------------------------------------------------------------------------------//
10 #ifndef _SCL_SECURE_NO_WARNINGS
11 # define _SCL_SECURE_NO_WARNINGS
14 #ifndef _CRT_SECURE_NO_WARNINGS
15 # define _CRT_SECURE_NO_WARNINGS
19 #include <boost/endian/conversion.hpp>
20 #include <boost/endian/buffers.hpp>
21 #include <boost/endian/arithmetic.hpp>
24 using namespace boost::endian
;
32 { // Use case 2 - Endian buffer types
36 big_ubuf32_t count
; // big endian
37 big_buf32_t value
; // big endian
42 read(&rec
, sizeof(Record
));
44 uint32_t count
= rec
.count
.value();
45 int32_t value
= rec
.value
.value();
53 write(&rec
, sizeof(Record
));
56 { // Use case 3a - Endian arithmetic types
60 big_uint32_t count
; // big endian
61 big_int32_t value
; // big endian
66 read(&rec
, sizeof(Record
));
71 write(&rec
, sizeof(Record
));
74 { // Use case 3b - Endian arithmetic types
78 big_uint32_t count
; // big endian
79 big_int32_t value
; // big endian
84 read(&rec
, sizeof(Record
));
86 uint32_t count
= rec
.count
;
87 int32_t value
= rec
.value
;
95 write(&rec
, sizeof(Record
));
98 // Recommended approach when conversion time is not a concern
100 // Conversion time is not a concert with this application because the minimum
101 // possible number of conversions is performed and because I/O time will be
102 // much greater than conversion time.
107 big_uint32_t count
; // big endian
108 big_int32_t value
; // big endian
113 read(&rec
, sizeof(Record
));
118 write(&rec
, sizeof(Record
));
121 // Recommended approach when conversion time is a concern
123 // Conversion time is a concert with this application because (1) any conversions
124 // performed in the loop will consume a great deal of time and because (2)
125 // computation time will be much greater than I/O time.
130 big_uint32_t count
; // big endian
131 big_int32_t value
; // big endian
136 read(&rec
, sizeof(Record
));
138 uint32_t count
= rec
.count
;
139 int32_t value
= rec
.value
;
141 for (long long i
= 0; i
< several_gazillion
; ++i
) // (1)
143 ... immensely
complex computation
using rec variables many times
// (2)
149 write(&rec
, sizeof(Record
));