Welcome to mirror list, hosted at ThFree Co, Russian Federation.

macros.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 573cae3bab6e320ac5bbca2fe41e7fed2a182a5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include "base.hpp"

namespace my
{
    namespace impl
    {
        // http://rsdn.ru/Forum/?mid=1025325
        template <typename T, unsigned int N> char(&ArraySize(T(&)[N]))[N];
    }
}

// Number of elements in array. Compilation error if the type passed is not an array.
#define ARRAY_SIZE(X) sizeof(::my::impl::ArraySize(X))

// Make class noncopyable.
#define NONCOPYABLE(class_name)								\
private:													\
    class_name const & operator = (class_name const &);		\
    class_name(class_name const &);
/////////////////////////////////////////////////////////////

#define TO_STRING_IMPL(x) #x
#define TO_STRING(x) TO_STRING_IMPL(x)

#define UNUSED_VALUE(x) static_cast<void>(x)

namespace my
{
  namespace impl
  {
    template <typename T> inline void ForceUseValue(T const & t)
    {
       volatile T dummy = t;
       UNUSED_VALUE(dummy);
    }
  }
}

// Prevent compiler optimization.
#define FORCE_USE_VALUE(x) ::my::impl::ForceUseValue(x)

#ifdef __GNUC__
#define PREDICT(x, prediction) __builtin_expect(x, prediction)
#define PREDICT_TRUE(x) __builtin_expect((x) != 0, 1)
#define PREDICT_FALSE(x) __builtin_expect((x) != 0, 0)
#else
#define PREDICT(x, prediction) (x)
#define PREDICT_TRUE(x) (x)
#define PREDICT_FALSE(x) (x)
#endif

#define UINT16_FROM_UINT8(hi, lo) ((static_cast<uint16_t>(hi) << 8) | lo)
#define UINT32_FROM_UINT16(hi, lo) ((static_cast<uint32_t>(hi) << 16) | lo)
#define UINT64_FROM_UINT32(hi, lo) ((static_cast<uint64_t>(hi) << 32) | lo)

#define UINT32_FROM_UINT8(u3, u2, u1, u0) \
  UINT32_FROM_UINT16(UINT16_FROM_UINT8(u3, u2), UINT16_FROM_UINT8(u1, u0))
#define UINT64_FROM_UINT8(u7, u6, u5, u4, u3, u2, u1, u0) \
  UINT64_FROM_UINT32(UINT32_FROM_UINT8(u7, u6, u5, u4), UINT32_FROM_UINT8(u3, u2, u1, u0))

#define UINT16_LO(x) (static_cast<uint8_t>(x & 0xFF))
#define UINT16_HI(x) (static_cast<uint8_t>(x >> 8))
#define UINT32_LO(x) (static_cast<uint16_t>(x & 0xFFFF))
#define UINT32_HI(x) (static_cast<uint16_t>(x >> 16))
#define UINT64_LO(x) (static_cast<uint32_t>(x & 0xFFFFFFFF))
#define UINT64_HI(x) (static_cast<uint32_t>(x >> 32))