1 |
|
|
#ifndef ZSERIO_BUILTIN_BUILT_IN_OPERATORS_H_INC |
2 |
|
|
#define ZSERIO_BUILTIN_BUILT_IN_OPERATORS_H_INC |
3 |
|
|
|
4 |
|
|
#include "zserio/Types.h" |
5 |
|
|
|
6 |
|
|
namespace zserio |
7 |
|
|
{ |
8 |
|
|
|
9 |
|
|
namespace builtin |
10 |
|
|
{ |
11 |
|
|
|
12 |
|
|
/** |
13 |
|
|
* Checks whether the requiredMask is set within the bitmaskValue. |
14 |
|
|
* |
15 |
|
|
* This method implements zserio built-in operator isset. |
16 |
|
|
* |
17 |
|
|
* \param bitmaskValue Bitmask value to check. |
18 |
|
|
* \param requiredMask Mask to use. |
19 |
|
|
* |
20 |
|
|
* \return True when the requiredMask is set within the bitmaskValue, false otherwise. |
21 |
|
|
*/ |
22 |
|
|
template <typename BITMASK1, typename BITMASK2> |
23 |
|
7 |
bool isSet(BITMASK1 bitmaskValue, BITMASK2 requiredMask) |
24 |
|
|
{ |
25 |
|
7 |
return (bitmaskValue & requiredMask) == requiredMask; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* Gets the minimum number of bits required to encode <tt>numValues</tt> different values. |
30 |
|
|
* |
31 |
|
|
* This method implements Zserio build-in operator <tt>numbits</tt>. |
32 |
|
|
* |
33 |
|
|
* <b>Note:</b> Please note that this method returns 0 if <tt>numValues</tt> is zero. |
34 |
|
|
* |
35 |
|
|
* Examples: |
36 |
|
|
* <tt>numbits(0) = 0</tt> |
37 |
|
|
* <tt>numbits(1) = 1</tt> |
38 |
|
|
* <tt>numbits(2) = 1</tt> |
39 |
|
|
* <tt>numbits(3) = 2</tt> |
40 |
|
|
* <tt>numbits(4) = 2</tt> |
41 |
|
|
* <tt>numbits(8) = 3</tt> |
42 |
|
|
* <tt>numbits(16) = 4</tt> |
43 |
|
|
* |
44 |
|
|
* \param numValues The number of different values from which to calculate number of bits. |
45 |
|
|
* |
46 |
|
|
* \return Number of bis required to encode <tt>numValues</tt> different values. |
47 |
|
|
*/ |
48 |
|
|
uint8_t numBits(uint64_t numValues); |
49 |
|
|
|
50 |
|
|
} // namespace builtin |
51 |
|
|
|
52 |
|
|
} // namespace zserio |
53 |
|
|
|
54 |
|
|
#endif // ifndef ZSERIO_BUILTIN_BUILT_IN_OPERATORS_H_INC |