MRPT  1.9.9
reverse_bytes.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/core/Clock.h>
12 #include <cstdint>
13 
14 namespace mrpt
15 {
16 /** \addtogroup mrpt_core_grp
17  * @{ */
18 
19 /** Reverse the order of the bytes of a given type (useful for transforming btw
20  * little/big endian) */
21 void reverseBytesInPlace(bool& v_in_out);
22 void reverseBytesInPlace(uint8_t& v_in_out);
23 void reverseBytesInPlace(int8_t& v_in_out);
24 void reverseBytesInPlace(uint16_t& v_in_out);
25 void reverseBytesInPlace(int16_t& v_in_out);
26 void reverseBytesInPlace(uint32_t& v_in_out);
27 void reverseBytesInPlace(int32_t& v_in_out);
28 void reverseBytesInPlace(uint64_t& v_in_out);
29 void reverseBytesInPlace(int64_t& v_in_out);
30 void reverseBytesInPlace(float& v_in_out);
31 void reverseBytesInPlace(double& v_in_out);
32 void reverseBytesInPlace(long double& v_in_out);
33 void reverseBytesInPlace(std::chrono::time_point<mrpt::Clock>& v_in_out);
34 
35 /** Reverse the order of the bytes of a given type (useful for transforming btw
36  * little/big endian) */
37 template <class T>
38 inline void reverseBytes(const T& v_in, T& v_out)
39 {
40  v_out = v_in;
41  reverseBytesInPlace(v_out);
42 }
43 
44 template <class T>
45 inline T reverseBytes(const T& v_in)
46 {
47  T v_out = v_in;
48  reverseBytesInPlace(v_out);
49  return v_out;
50 }
51 
52 template <
53  typename enum_t,
54  typename underlying_t = typename std::underlying_type<enum_t>::type>
55 inline void reverseBytesInPlace_enum(enum_t& v)
56 {
57  underlying_t v_out = static_cast<underlying_t>(v);
58  reverseBytesInPlace(v_out);
59  v = static_cast<enum_t>(v_out);
60 }
61 
62 /** @} */
63 } // namespace mrpt
void reverseBytes(const T &v_in, T &v_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
Definition: reverse_bytes.h:38
void reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
__int32 int32_t
Definition: glext.h:3455
const GLdouble * v
Definition: glext.h:3684
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int64 uint64_t
Definition: glext.h:3457
void reverseBytesInPlace_enum(enum_t &v)
Definition: reverse_bytes.h:55
__int64 int64_t
Definition: glext.h:3456
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3532



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 0cbd40372 Sun Nov 17 09:43:05 2019 +0100 at dom nov 17 09:45:09 CET 2019