Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
macro_helpers.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_core/macro_helpers.h
10
//! @brief Helper macros.
11
12
#ifndef ROC_CORE_MACRO_HELPERS_H_
13
#define ROC_CORE_MACRO_HELPERS_H_
14
15
#include "
roc_core/stddefs.h
"
16
17
//! Select minum value.
18
#define ROC_MIN(a, b) ((a) < (b) ? (a) : (b))
19
20
//! Select minum value.
21
#define ROC_MAX(a, b) ((a) > (b) ? (a) : (b))
22
23
//! Get number of elements in a static array.
24
#define ROC_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
25
26
//! Get minimum value of signed or unsigned integer type.
27
#define ROC_MIN_OF(type) \
28
((type)-1 > (type)0 ? (type)0 \
29
: (type)((~0ull) - ((1ull << ((sizeof(type) * 8) - 1)) - 1ull)))
30
31
//! Get maximum value of signed or unsigned integer type.
32
#define ROC_MAX_OF(type) \
33
((type)-1 > (type)0 ? (type)(~0ull) \
34
: (type)((1ull << ((sizeof(type) * 8) - 1)) - 1ull))
35
36
//! Cast a member of a structure out to the containing structure.
37
#define ROC_CONTAINER_OF(ptr, type, member) \
38
(reinterpret_cast<type*>((char*)(ptr)-offsetof(type, member)))
39
40
//! Stringize macro helper.
41
#define ROC_STRINGIZE_(s) #s
42
43
//! Stringize macro.
44
#define ROC_STRINGIZE(s) ROC_STRINGIZE_(s)
45
46
#endif
// ROC_CORE_MACRO_HELPERS_H_
stddefs.h
Commonly used types and functions.
roc_core
macro_helpers.h
Generated by
1.9.1