MLBookProc 1.0.1
 
Loading...
Searching...
No Matches
ByteOrder.h
1/*
2 * Copyright (C) 2023-2025 Yury Bobylev <bobilev_yury@mail.ru>
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation, version 3.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#ifndef BYTEORDER_H
18#define BYTEORDER_H
19
20#include <cstdint>
21#include <cstring>
22#include <vector>
23
24#ifdef USE_OPENMP
25#include <omp.h>
26#else
27#include <mutex>
28#endif
37{
38public:
43
47 virtual ~ByteOrder();
48
52 ByteOrder(const ByteOrder &other);
53
58 ByteOrder(uint64_t val);
59
64 ByteOrder(uint32_t val);
65
70 ByteOrder(uint16_t val);
71
76 ByteOrder(int64_t val);
77
82 ByteOrder(int32_t val);
83
88 ByteOrder(int16_t val);
89
94 ByteOrder(float val);
95
100 ByteOrder(double val);
101
105 ByteOrder &
106 operator=(const ByteOrder &other);
107
112 ByteOrder &
113 operator=(const uint64_t &val);
114
119 ByteOrder &
120 operator=(const uint32_t &val);
121
126 ByteOrder &
127 operator=(const uint16_t &val);
128
133 ByteOrder &
134 operator=(const int64_t &val);
135
140 ByteOrder &
141 operator=(const int32_t &val);
142
147 ByteOrder &
148 operator=(const int16_t &val);
149
154 ByteOrder &
155 operator=(const float &val);
156
161 ByteOrder &
162 operator=(const double &val);
163
167 operator uint64_t();
168
172 operator uint32_t();
173
177 operator uint16_t();
178
182 operator int64_t();
183
187 operator int32_t();
188
192 operator int16_t();
193
197 operator float();
198
202 operator double();
203
208 template <typename T>
209 void
210 get_native(T &result);
211
216 template <typename T>
217 void
218 get_big(T &result);
219
224 template <typename T>
225 void
226 get_little(T &result);
227
234 template <typename T>
235 void
236 set_big(T val);
237
244 template <typename T>
245 void
247
248private:
249 template <typename T>
250 void
251 form_native_order(T &control);
252
253 template <typename T>
254 void
255 form_inner(T &val);
256
257 std::vector<uint8_t> inner;
258 std::vector<size_t> native_order;
259#ifndef USE_OPENMP
260 std::mutex bomtx;
261#else
262 omp_lock_t bomtx;
263#endif
264};
265
266#endif // BYTEORDER_H
void get_big(T &result)
Returns "big endian" number.
ByteOrder()
ByteOrder constructor.
ByteOrder(int32_t val)
ByteOrder constructor.
ByteOrder & operator=(const float &val)
operator =
ByteOrder & operator=(const uint64_t &val)
operator =
ByteOrder(uint16_t val)
ByteOrder constructor.
ByteOrder(double val)
ByteOrder constructor.
ByteOrder & operator=(const uint16_t &val)
operator =
ByteOrder & operator=(const uint32_t &val)
operator =
void set_big(T val)
Sets inner value to val.
ByteOrder & operator=(const int16_t &val)
operator =
virtual ~ByteOrder()
ByteOrder destructor.
ByteOrder & operator=(const double &val)
operator =
void set_little(T val)
Sets inner value to val.
ByteOrder & operator=(const int32_t &val)
operator =
ByteOrder & operator=(const int64_t &val)
operator =
ByteOrder(float val)
ByteOrder constructor.
ByteOrder(uint32_t val)
ByteOrder constructor.
ByteOrder(const ByteOrder &other)
ByteOrder copy constructor.
ByteOrder(int64_t val)
ByteOrder constructor.
ByteOrder(uint64_t val)
ByteOrder constructor.
void get_little(T &result)
Returns "little endian" number.
void get_native(T &result)
Returns number in native byte order.
ByteOrder(int16_t val)
ByteOrder constructor.
ByteOrder & operator=(const ByteOrder &other)
operator =