LibUDB  1.0.1
ByteOrder.h
1 /*
2  * Copyright (C) 2023 Yury Bobylev <bobilev_yury@mail.ru>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDE_BYTEORDER_H_
19 #define INCLUDE_BYTEORDER_H_
20 
21 #include <cstdint>
22 #include <stddef.h>
23 #include <vector>
24 
33 class ByteOrder
34 {
35 public:
36  ByteOrder();
37 
38  virtual ~ByteOrder();
39 
45  ByteOrder(const ByteOrder &other);
46 
53  ByteOrder(uint64_t val);
54 
60  ByteOrder(uint32_t val);
61 
67  ByteOrder(uint16_t val);
68 
74  ByteOrder(int64_t val);
75 
81  ByteOrder(int32_t val);
82 
88  ByteOrder(int16_t val);
89 
95  ByteOrder(float val);
96 
102  ByteOrder(double val);
103 
109  ByteOrder &
110  operator=(const ByteOrder &other);
111 
117  ByteOrder &
118  operator=(const uint64_t &val);
119 
125  ByteOrder &
126  operator=(const uint32_t &val);
127 
133  ByteOrder &
134  operator=(const uint16_t &val);
135 
141  ByteOrder &
142  operator=(const int64_t &val);
143 
149  ByteOrder &
150  operator=(const int32_t &val);
151 
157  ByteOrder &
158  operator=(const int16_t &val);
159 
165  ByteOrder &
166  operator=(const float &val);
167 
173  ByteOrder &
174  operator=(const double &val);
175 
181  operator uint64_t();
182 
188  operator uint32_t();
189 
195  operator uint16_t();
196 
202  operator int64_t();
203 
209  operator int32_t();
210 
216  operator int16_t();
217 
223  operator float();
224 
230  operator double();
231 
237  template <typename T>
238  void
239  getNative(T &result);
240 
246  template <typename T>
247  void
248  getBig(T &result);
249 
256  template <typename T>
257  void
258  getLittle(T &result);
259 
265  template <typename T>
266  void
267  setBig(T val);
268 
274  template <typename T>
275  void
276  setLittle(T val);
277 
278 private:
279  template <typename T>
280  void
281  formNativeOrder(T &control);
282 
283  template <typename T>
284  void
285  formInner(T &val);
286 
287  std::vector<uint8_t> inner;
288  std::vector<size_t> native_order;
289 };
290 
291 #endif /* INCLUDE_BYTEORDER_H_ */
void setLittle(T val)
void getLittle(T &result)
ByteOrder & operator=(const ByteOrder &other)
operator =
The ByteOrder class.
Definition: ByteOrder.h:33
void getBig(T &result)
void getNative(T &result)
void setBig(T val)