1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
30 #include "vogl_core.h"
34 typedef uint8_t uint8;
36 typedef uint16_t uint16;
37 typedef int16_t int16;
38 typedef uint32_t uint32;
40 typedef int32_t int32;
42 const uint8 cUINT8_MIN = 0;
43 const uint8 cUINT8_MAX = 0xFFU;
44 const uint16 cUINT16_MIN = 0;
45 const uint16 cUINT16_MAX = 0xFFFFU;
46 const uint32 cUINT32_MIN = 0;
47 const uint32 cUINT32_MAX = 0xFFFFFFFFU;
48 const uint64_t cUINT64_MIN = 0;
49 const uint64_t cUINT64_MAX = 0xFFFFFFFFFFFFFFFFULL; //0xFFFFFFFFFFFFFFFFui64;
51 const int8 cINT8_MIN = -128;
52 const int8 cINT8_MAX = 127;
53 const int16 cINT16_MIN = -32768;
54 const int16 cINT16_MAX = 32767;
55 const int32 cINT32_MIN = (-2147483647 - 1);
56 const int32 cINT32_MAX = 2147483647;
57 const int64_t cINT64_MIN = (int64_t)0x8000000000000000ULL; //(-9223372036854775807i64 - 1);
58 const int64_t cINT64_MAX = (int64_t)0x7FFFFFFFFFFFFFFFULL; // 9223372036854775807i64;
60 typedef uintptr_t uint_ptr;
61 typedef uintptr_t uint32_ptr;
62 typedef std::ptrdiff_t signed_size_t;
63 typedef uintptr_t ptr_bits_t;
90 const uint cIntBits = 32;
92 template <bool condition, class Then, class Else>
97 template <class Then, class Else>
98 struct template_if<false, Then, Else>
105 inline bool operator==(const empty_type &rhs) const
107 VOGL_NOTE_UNUSED(rhs);
110 inline bool operator<(const empty_type &rhs) const
112 VOGL_NOTE_UNUSED(rhs);
119 inline bool json_serialize(const empty_type &, json_value &)
124 inline bool json_deserialize(empty_type &, const json_value &)
129 template <typename T>
139 struct is_empty_type<empty_type>
147 uint32 fast_hash(const void *p, int len);
149 // Bitwise hasher: Directly hashes key's bits
150 template <typename T>
153 inline size_t operator()(const T &key) const
155 return static_cast<size_t>(fast_hash(&key, sizeof(key)));
159 // Intrusive hasher: Requires object implement a get_hash() method
160 template <typename T>
161 struct intrusive_hasher
163 inline size_t operator()(const T &key) const
165 return static_cast<size_t>(key.get_hash());
169 // Default hasher: Casts object to size_t
170 template <typename T>
173 inline size_t operator()(const T &key) const
175 return static_cast<size_t>(key);
179 // Now define some common specializations of hasher<> because it's the default used by hash_map and some types can't be static_cast to size_t.
180 template <typename T>
181 struct hasher<T *> : bit_hasher<T *>
185 #define VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION(T) \
186 template <> struct hasher<T> : bit_hasher<T> \
189 VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION(float);
190 VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION(double);
191 VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION(long double);
192 VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION(int64_t);
193 VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION(uint64_t);
194 #undef VOGL_DEFINE_BITWISE_HASHER_SPECIALIZATION
196 template <typename T>
199 inline bool operator()(const T &a, const T &b) const
205 template <typename T>
206 struct equal_to_using_less_than
208 inline bool operator()(const T &a, const T &b) const
210 return !(a < b) && !(b < a);
214 template <typename T>
217 inline bool operator()(const T &a, const T &b) const