Haka: include/haka/types.h Source File

Haka

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

types.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
10 #ifndef HAKA_TYPES_H
11 #define HAKA_TYPES_H
12
13 #include <haka/config.h>
14 #include <byteswap.h>
15
16
17 typedef unsigned char bool;
19 #define true 1
20 #define false 0
22 typedef char int8;
23 typedef HAKA_16BIT_TYPE int16;
24 typedef HAKA_32BIT_TYPE int32;
25 typedef HAKA_64BIT_TYPE int64;
27 typedef unsigned char uint8;
28 typedef unsigned HAKA_16BIT_TYPE uint16;
29 typedef unsigned HAKA_32BIT_TYPE uint32;
30 typedef unsigned HAKA_64BIT_TYPE uint64;
33 #define SWAP_int8(x) (x)
34 #define SWAP_int16(x) bswap_16(x)
35 #define SWAP_int32(x) bswap_32(x)
36 #define SWAP_int64(x) bswap_64(x)
37
38 #define SWAP_uint8(x) (x)
39 #define SWAP_uint16(x) SWAP_int16(x)
40 #define SWAP_uint32(x) SWAP_int32(x)
41 #define SWAP_uint64(x) SWAP_int64(x)
42
50 #define SWAP(type, x) SWAP_##type(x)
51
52 #ifdef HAKA_BIGENDIAN
53 #define SWAP_TO_BE(type, x) (x)
54 #define SWAP_FROM_BE(type, x) (x)
55 #define SWAP_TO_LE(type, x) SWAP(type, (x))
56 #define SWAP_FROM_LE(type, x) SWAP(type, (x))
57 #else
58 #define SWAP_TO_LE(type, x) (x)
59 #define SWAP_FROM_LE(type, x) (x)
60 #define SWAP_TO_BE(type, x) SWAP(type, (x))
61 #define SWAP_FROM_BE(type, x) SWAP(type, (x))
62 #endif
63
64
104 #define GET_BIT(v, i) ((((v) & (1 << (i))) != 0))
105
109 #define SET_BIT(v, i, x) ((x) ? ((v) | (1 << (i))) : ((v) & ~(1 << (i))))
110
112 #define GET_BITS_MASK(i, j) (((1<<((j)-(i)))-1)<<(i))
113
118 #define GET_BITS(v, i, j) (((v) & GET_BITS_MASK(i, j)) >> (i))
119
123 #define SET_BITS(v, i, j, x) (((v) & ~(GET_BITS_MASK(i, j))) | (((x) << (i)) & GET_BITS_MASK(i, j)))
124
125 #endif /* HAKA_TYPES_H */
bool
unsigned char bool
Definition: types.h:17