1 | // LAF Base Library |
2 | // Copyright (c) 2001-2016 David Capello |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifndef BASE_24BITS_H_INCLUDED |
8 | #define BASE_24BITS_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "base/config.h" |
12 | #include "base/ints.h" |
13 | |
14 | namespace base { |
15 | |
16 | #ifdef LAF_LITTLE_ENDIAN |
17 | |
18 | template<typename PTR, typename VALUE> |
19 | inline void write24bits(PTR* ptr, VALUE value) { |
20 | ((uint8_t*)ptr)[0] = value; |
21 | ((uint8_t*)ptr)[1] = value >> 8; |
22 | ((uint8_t*)ptr)[2] = value >> 16; |
23 | } |
24 | |
25 | #elif defined(LAF_BIG_ENDIAN) |
26 | |
27 | template<typename PTR, typename VALUE> |
28 | inline void write24bits(PTR* ptr, VALUE value) { |
29 | ((uint8_t*)ptr)[0] = value >> 16; |
30 | ((uint8_t*)ptr)[1] = value >> 8; |
31 | ((uint8_t*)ptr)[2] = value; |
32 | } |
33 | |
34 | #endif |
35 | |
36 | } // namespace base |
37 | |
38 | #endif |
39 | |