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 **************************************************************************/
27 // File: vogl_platform.h
30 #include "vogl_core.h"
32 bool vogl_is_debugger_present(bool force_check = false);
33 void vogl_debug_break(void);
34 void vogl_debug_break_if_debugging(void);
35 void vogl_output_debug_string(const char *p);
37 // actually in vogl_assert.cpp
38 void vogl_assert(const char *pExp, const char *pFile, unsigned line);
39 void vogl_fail(const char *pExp, const char *pFile, unsigned line);
41 #if VOGL_LITTLE_ENDIAN_CPU
42 const bool c_vogl_little_endian_platform = true;
44 const bool c_vogl_little_endian_platform = false;
47 const bool c_vogl_big_endian_platform = !c_vogl_little_endian_platform;
50 #define vogl_fopen(f, m) fopen64(f, m)
51 #define vogl_fopen_s(pDstFile, f, m) *(pDstFile) = fopen64(f, m)
52 #define vogl_fseek fseeko64
53 #define vogl_ftell ftello64
54 #elif defined(_MSC_VER)
55 inline FILE *vogl_fopen(const char *pFilename, const char *pMode)
58 fopen_s(&pFile, pFilename, pMode);
61 #define vogl_fopen_s(pDstFile, f, m) fopen_s(pDstFile, f, m)
62 #define vogl_fseek _fseeki64
63 #define vogl_ftell _ftelli64
65 #define vogl_fopen(f, m) fopen(f, m)
66 #define vogl_fopen_s(pDstFile, f, m) *(pDstFile) = fopen(f, m)
67 #define vogl_fseek(s, o, w) fseek(s, static_cast<long>(o), w)
68 #define vogl_ftell ftell
71 #define vogl_fread fread
72 #define vogl_fwrite fwrite
73 #define vogl_fputc fputc
74 #define vogl_fgetc fgetc
75 #define vogl_fputs fputs
76 #define vogl_fgets fgets
77 #define vogl_fprintf fprintf
78 #define vogl_feof feof
79 #define vogl_fflush fflush
80 #define vogl_fclose fclose
82 #ifdef VOGL_USE_WIN32_API
83 #define VOGL_BREAKPOINT DebugBreak();
84 #define VOGL_BUILTIN_EXPECT(c, v) c
85 #elif defined(__GNUC__)
86 #define VOGL_BREAKPOINT asm("int $3");
87 #define VOGL_BUILTIN_EXPECT(c, v) __builtin_expect(c, v)
89 #define VOGL_BREAKPOINT
90 #define VOGL_BUILTIN_EXPECT(c, v) c
94 #define VOGL_ALIGNED(x) __attribute__((aligned(x)))
95 #define VOGL_ALIGNED_BEGIN(x)
96 #define VOGL_ALIGNED_END(x) __attribute__((aligned(x)))
97 #define VOGL_NOINLINE __attribute__((noinline))
98 #elif defined(_MSC_VER)
99 #define VOGL_ALIGNED(x) __declspec(align(x))
100 #define VOGL_ALIGNED_BEGIN(x) __declspec(align(x))
101 #define VOGL_ALIGNED_END(x)
102 #define VOGL_NOINLINE __declspec(noinline)
104 #define VOGL_ALIGNED(x)
105 #define VOGL_NOINLINE
108 #define VOGL_GET_ALIGNMENT(v) ((!sizeof(v)) ? 1 : (__alignof(v) ? __alignof(v) : sizeof(uint32)))
110 inline bool vogl_is_little_endian()
112 return c_vogl_little_endian_platform;
114 inline bool vogl_is_big_endian()
116 return c_vogl_big_endian_platform;
119 inline bool vogl_is_pc()
121 #ifdef VOGL_PLATFORM_PC
128 inline bool vogl_is_x86()
130 #ifdef VOGL_PLATFORM_PC_X86
137 inline bool vogl_is_x64()
139 #ifdef VOGL_PLATFORM_PC_X64
146 inline bool vogl_is_debug_build()
148 #ifdef VOGL_BUILD_DEBUG
155 typedef void (*vogl_exception_callback_t)();
156 vogl_exception_callback_t vogl_set_exception_callback(vogl_exception_callback_t callback);
157 void vogl_reset_exception_callback();
161 class dynamic_string;
162 dynamic_string demangle(const char *pMangled);
166 // FIXME: Is there a better way on GCC to do this?
167 // Obviously this isn't fast, it's intended for warning/error messages and such.
168 #define VOGL_METHOD_NAME vogl::dynamic_string(vogl::cVarArg, "%s::%s (%u)", vogl::demangle(vogl::type_name(*this)).get_ptr(), VOGL_FUNCTION_NAME, __LINE__).get_ptr()
170 #define VOGL_METHOD_NAME VOGL_FUNCTION_NAME