GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
macros.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_CORE_MACROS_H_
16#define DRACO_CORE_MACROS_H_
17
18#include <cassert>
19
21
22#ifdef ANDROID_LOGGING
23#include <android/log.h>
24#define LOG_TAG "draco"
25#define DRACO_LOGI(...) \
26 __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
27#define DRACO_LOGE(...) \
28 __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
29#else
30#define DRACO_LOGI printf
31#define DRACO_LOGE printf
32#endif
33
34#include <iostream>
35namespace draco {
36
37#ifndef DISALLOW_COPY_AND_ASSIGN
38#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
39 TypeName(const TypeName &) = delete; \
40 void operator=(const TypeName &) = delete;
41#endif // DISALLOW_COPY_AND_ASSIGN
42
43#ifndef FALLTHROUGH_INTENDED
44#if defined(__clang__) && defined(__has_warning)
45#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
46#define FALLTHROUGH_INTENDED [[clang::fallthrough]]
47#endif
48#elif defined(__GNUC__) && __GNUC__ >= 7
49#define FALLTHROUGH_INTENDED [[gnu::fallthrough]]
50#endif // FALLTHROUGH_INTENDED
51
52// If FALLTHROUGH_INTENDED is still not defined, define it.
53#ifndef FALLTHROUGH_INTENDED
54#define FALLTHROUGH_INTENDED \
55 do { \
56 } while (0)
57#endif
58#endif // FALLTHROUGH_INTENDED
59
60#ifndef LOG
61#define LOG(...) std::cout
62#endif
63
64#ifndef VLOG
65#define VLOG(...) std::cout
66#endif
67
68} // namespace draco
69
70#ifdef DRACO_DEBUG
71#define DRACO_DCHECK(x) (assert(x));
72#define DRACO_DCHECK_EQ(a, b) assert((a) == (b));
73#define DRACO_DCHECK_NE(a, b) assert((a) != (b));
74#define DRACO_DCHECK_GE(a, b) assert((a) >= (b));
75#define DRACO_DCHECK_GT(a, b) assert((a) > (b));
76#define DRACO_DCHECK_LE(a, b) assert((a) <= (b));
77#define DRACO_DCHECK_LT(a, b) assert((a) < (b));
78#define DRACO_DCHECK_NOTNULL(x) assert((x) != NULL);
79#else
80#define DRACO_DCHECK(x)
81#define DRACO_DCHECK_EQ(a, b)
82#define DRACO_DCHECK_NE(a, b)
83#define DRACO_DCHECK_GE(a, b)
84#define DRACO_DCHECK_GT(a, b)
85#define DRACO_DCHECK_LE(a, b)
86#define DRACO_DCHECK_LT(a, b)
87#define DRACO_DCHECK_NOTNULL(x)
88#endif // DRACO_DEBUG
89
90// Helper macros for concatenating macro values.
91#define DRACO_MACROS_IMPL_CONCAT_INNER_(x, y) x##y
92#define DRACO_MACROS_IMPL_CONCAT_(x, y) DRACO_MACROS_IMPL_CONCAT_INNER_(x, y)
93
94#define DRACO_MACROS_IMPL_CONCAT_INNER_3_(x, y, z) x##y##z
95#define DRACO_MACROS_IMPL_CONCAT_3_(x, y, z) \
96 DRACO_MACROS_IMPL_CONCAT_INNER_3_(x, y, z)
97
98// Expand the n-th argument of the macro. Used to select an argument based on
99// the number of entries in a variadic macro argument. Example usage:
100//
101// #define FUNC_1(x) x
102// #define FUNC_2(x, y) x + y
103// #define FUNC_3(x, y, z) x + y + z
104//
105// #define VARIADIC_MACRO(...)
106// DRACO_SELECT_NTH_FROM_3(__VA_ARGS__, FUNC_3, FUNC_2, FUNC_1) __VA_ARGS__
107//
108#define DRACO_SELECT_NTH_FROM_2(_1, _2, NAME, ...) NAME
109#define DRACO_SELECT_NTH_FROM_3(_1, _2, _3, NAME, ...) NAME
110#define DRACO_SELECT_NTH_FROM_4(_1, _2, _3, _4, NAME, ...) NAME
111
112// Macro that converts the Draco bit-stream into one uint16_t number.
113// Useful mostly when checking version numbers.
114#define DRACO_BITSTREAM_VERSION(MAJOR, MINOR) \
115 ((static_cast<uint16_t>(MAJOR) << 8) | MINOR)
116
117// Macro that converts the uint16_t Draco bit-stream number into the major
118// and minor components respectively.
119#define DRACO_BISTREAM_VERSION_MAJOR(VERSION) \
120 (static_cast<uint8_t>(VERSION >> 8))
121#define DRACO_BISTREAM_VERSION_MINOR(VERSION) \
122 (static_cast<uint8_t>(VERSION & 0xFF))
123
124#endif // DRACO_CORE_MACROS_H_
Definition attribute_octahedron_transform.cc:21