Plasma Engine  2.0
Loading...
Searching...
No Matches
Common.h
1#pragma once
2
3// On MSVC 2008 in 64 Bit <cmath> generates a lot of warnings (actually it is math.h, which is included by cmath)
4PL_WARNING_PUSH()
5PL_WARNING_DISABLE_MSVC(4985)
6
7// include std header
8#include <cmath>
9#include <cstdio>
10#include <cstdlib>
11#include <cstring>
12#include <cwchar>
13#include <cwctype>
14#include <new>
15
16PL_WARNING_POP()
17
18// redefine NULL to nullptr
19#undef NULL
20#define NULL nullptr
21
22// include c++11 specific header
23#include <type_traits>
24#include <utility>
25
27#define PL_DISALLOW_COPY_AND_ASSIGN(type) \
28 type(const type&) = delete; \
29 void operator=(const type&) = delete
30
31#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT)
33# define PL_CHECK_ALIGNMENT(ptr, alignment) PL_ASSERT_DEV(((size_t)ptr & ((alignment) - 1)) == 0, "Wrong alignment.")
34#else
36# define PL_CHECK_ALIGNMENT(ptr, alignment)
37#endif
38
39#define PL_WINCHECK_1 1 // PL_INCLUDED_WINDOWS_H defined to 1, _WINDOWS_ defined (stringyfied to nothing)
40#define PL_WINCHECK_1_WINDOWS_ 1 // PL_INCLUDED_WINDOWS_H defined to 1, _WINDOWS_ undefined (stringyfied to "_WINDOWS_")
41#define PL_WINCHECK_PL_INCLUDED_WINDOWS_H \
42 0 // PL_INCLUDED_WINDOWS_H undefined (stringyfied to "PL_INCLUDED_WINDOWS_H", _WINDOWS_ defined (stringyfied to nothing)
43#define PL_WINCHECK_PL_INCLUDED_WINDOWS_H_WINDOWS_ \
44 1 // PL_INCLUDED_WINDOWS_H undefined (stringyfied to "PL_INCLUDED_WINDOWS_H", _WINDOWS_ undefined (stringyfied to "_WINDOWS_")
45
49#define PL_CHECK_WINDOWS_INCLUDE(PL_WINH_INCLUDED, WINH_INCLUDED) \
50 static_assert(PL_PP_CONCAT(PL_WINCHECK_, PL_PP_CONCAT(PL_WINH_INCLUDED, WINH_INCLUDED)) == 1, \
51 "Windows.h has been included but not through pl. #include <Foundation/Basics/Platform/Win/IncludeWindows.h> instead of Windows.h");
52
53#if PL_ENABLED(PL_COMPILE_ENGINE_AS_DLL)
54
60# define PL_STATICLINK_FILE(LibraryName, UniqueName) PL_CHECK_WINDOWS_INCLUDE(PL_INCLUDED_WINDOWS_H, _WINDOWS_)
61
64# define PL_STATICLINK_REFERENCE(UniqueName)
65
67# define PL_STATICLINK_LIBRARY(LibraryName) void plReferenceFunction_##LibraryName(bool bReturn = true)
68
69#else
70
72{
73 using Func = void (*)(bool);
74 plStaticLinkHelper(Func f) { f(true); }
75};
76
80struct PL_FOUNDATION_DLL plPluginRegister
81{
82 plPluginRegister(const char* szName);
83};
84
90# define PL_STATICLINK_FILE(LibraryName, UniqueName) \
91 extern "C" \
92 { \
93 void plReferenceFunction_##UniqueName(bool bReturn) {} \
94 void plReferenceFunction_##LibraryName(bool bReturn); \
95 } \
96 static plStaticLinkHelper StaticLinkHelper_##UniqueName(plReferenceFunction_##LibraryName);
97
100# define PL_STATICLINK_REFERENCE(UniqueName) \
101 void plReferenceFunction_##UniqueName(bool bReturn = true); \
102 plReferenceFunction_##UniqueName()
103
105# define PL_STATICLINK_LIBRARY(LibraryName) \
106 plPluginRegister plPluginRegister_##LibraryName(PL_PP_STRINGIFY(PL_PP_CONCAT(pl, LibraryName))); \
107 extern "C" void plReferenceFunction_##LibraryName(bool bReturn = true)
108
109#endif
110
111namespace plInternal
112{
113 template <typename T, size_t N>
114 char (*ArraySizeHelper(T (&)[N]))[N];
115}
116
118#define PL_ARRAY_SIZE(a) (sizeof(*plInternal::ArraySizeHelper(a)) + 0)
119
121template <class T>
122void PL_IGNORE_UNUSED(const T&)
123{
124}
125
126#if (__cplusplus >= 202002L || _MSVC_LANG >= 202002L)
127# undef PL_USE_CPP20_OPERATORS
128# define PL_USE_CPP20_OPERATORS PL_ON
129#endif
130
131#if PL_ENABLED(PL_USE_CPP20_OPERATORS)
132// in C++ 20 we don't need to declare an operator!=, it is automatically generated from operator==
133# define PL_ADD_DEFAULT_OPERATOR_NOTEQUAL(...) /*empty*/
134#else
135# define PL_ADD_DEFAULT_OPERATOR_NOTEQUAL(...) \
136 PL_ALWAYS_INLINE bool operator!=(PL_EXPAND_ARGS_COMMA(__VA_ARGS__) rhs) const \
137 { \
138 return !(*this == rhs); \
139 }
140#endif
Helper struct to register the existence of statically linked plugins. The macro PL_STATICLINK_LIBRARY...
Definition Common.h:81