RavEngine
Loading...
Searching...
No Matches
platform.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_BASE_PLATFORM_H_
29#define OZZ_OZZ_BASE_PLATFORM_H_
30
31// Ensures compiler supports c++11 language standards, to help user understand
32// compilation error in case it's not supported.
33// Unfortunately MSVC doesn't update __cplusplus, so test compiler version
34// instead.
35#if !((__cplusplus >= 201103L) || (_MSC_VER >= 1900))
36#error "ozz-animation requires c++11 language standards."
37#endif // __cplusplus
38
39#include <stdint.h>
40
41#include <cassert>
42#include <cstddef>
43
44#include "ozz/base/export.h"
45
46namespace ozz {
47
48// Defines a byte type, unsigned so right shift doesn't propagate sign bit.
49typedef uint8_t byte;
50
51// Finds the number of elements of a statically allocated array.
52#define OZZ_ARRAY_SIZE(_array) (sizeof(_array) / sizeof(_array[0]))
53
54// Instructs the compiler to try to inline a function, regardless cost/benefit
55// compiler analysis.
56// Syntax is: "OZZ_INLINE void function();"
57#if defined(_MSC_VER)
58#define OZZ_INLINE __forceinline
59#else
60#define OZZ_INLINE inline __attribute__((always_inline))
61#endif
62
63// Tells the compiler to never inline a function.
64// Syntax is: "OZZ_NO_INLINE void function();"
65#if defined(_MSC_VER)
66#define OZZ_NOINLINE __declspec(noinline)
67#else
68#define OZZ_NOINLINE __attribute__((noinline))
69#endif
70
71// Tells the compiler that the memory addressed by the restrict -qualified
72// pointer is not aliased, aka no other pointer will access that same memory.
73// Syntax is: void function(int* OZZ_RESTRICT _p);"
74#define OZZ_RESTRICT __restrict
75
76// Defines macro to help with DEBUG/NDEBUG syntax.
77#if defined(NDEBUG)
78#define OZZ_IF_DEBUG(...)
79#define OZZ_IF_NDEBUG(...) __VA_ARGS__
80#else // NDEBUG
81#define OZZ_IF_DEBUG(...) __VA_ARGS__
82#define OZZ_IF_NDEBUG(...)
83#endif // NDEBUG
84
85// Case sensitive wildcard string matching:
86// - a ? sign matches any character, except an empty string.
87// - a * sign matches any string, including an empty string.
88OZZ_BASE_DLL bool strmatch(const char* _str, const char* _pattern);
89
90// Tests whether _block is aligned to _alignment boundary.
91template <typename _Ty>
92OZZ_INLINE bool IsAligned(_Ty _value, size_t _alignment) {
93 return (_value & (_alignment - 1)) == 0;
94}
95template <typename _Ty>
96OZZ_INLINE bool IsAligned(_Ty* _address, size_t _alignment) {
97 return (reinterpret_cast<uintptr_t>(_address) & (_alignment - 1)) == 0;
98}
99
100// Aligns _block address to the first greater address that is aligned to
101// _alignment boundaries.
102template <typename _Ty>
103OZZ_INLINE _Ty Align(_Ty _value, size_t _alignment) {
104 return static_cast<_Ty>(_value + (_alignment - 1)) & (0 - _alignment);
105}
106template <typename _Ty>
107OZZ_INLINE _Ty* Align(_Ty* _address, size_t _alignment) {
108 return reinterpret_cast<_Ty*>(
109 (reinterpret_cast<uintptr_t>(_address) + (_alignment - 1)) &
110 (0 - _alignment));
111}
112
113// Offset a pointer from a given number of bytes.
114template <typename _Ty>
115_Ty* PointerStride(_Ty* _ty, size_t _stride) {
116 return reinterpret_cast<_Ty*>(reinterpret_cast<uintptr_t>(_ty) + _stride);
117}
118} // namespace ozz
119#endif // OZZ_OZZ_BASE_PLATFORM_H_
uint8 uint8_t
Definition fwd.hpp:103
detail::uint8 byte
Definition raw_data.hpp:34