Sane C++ Libraries
C++ Platform Abstraction Libraries
PrimitiveTypes.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/Compiler.h"
5#include "../Foundation/Platform.h"
6
7namespace SC
8{
9// clang-format off
12#if SC_PLATFORM_WINDOWS
13using native_char_t = wchar_t;
14
15using uint8_t = unsigned char;
16using uint16_t = unsigned short;
17using uint32_t = unsigned int;
18using uint64_t = unsigned long long;
19
20using int8_t = signed char;
21using int16_t = short;
22using int32_t = int;
23using int64_t = long long;
24
25#if SC_PLATFORM_64_BIT
26using size_t = unsigned __int64;
27using ssize_t = signed __int64;
28#else
29
30using size_t = unsigned int;
31using ssize_t = long;
32#endif
33#else
34using native_char_t = char;
35
36using uint8_t = unsigned char;
37using uint16_t = unsigned short;
38using uint32_t = unsigned int;
39#if SC_PLATFORM_LINUX
40using uint64_t = unsigned long int;
41#else
42using uint64_t = unsigned long long;
43#endif
44using int8_t = signed char;
45using int16_t = short;
46using int32_t = int;
47#if SC_PLATFORM_LINUX
48using int64_t = signed long int;
49#else
50using int64_t = long long;
51#endif
52#if SC_PLATFORM_EMSCRIPTEN
53using size_t = unsigned __PTRDIFF_TYPE__;
54using ssize_t = signed __PTRDIFF_TYPE__;
55#else
56using size_t = unsigned long;
57using ssize_t = signed long;
58#endif
59#endif
61} // namespace SC
62
63// clang-format off
64namespace SC
65{
69struct PlacementNew {};
71} // namespace SC
74
76#if SC_COMPILER_MSVC
77inline void* operator new(size_t, void* p, SC::PlacementNew) noexcept { return p; }
78inline void operator delete(void*, void*, SC::PlacementNew) noexcept {}
79#else
80inline void* operator new(SC::size_t, void* p, SC::PlacementNew) noexcept { return p; }
81#endif
82namespace SC
83{
85template<typename T, typename... Q> void placementNew(T& storage, Q&&... other) { new (&storage, PlacementNew()) T(forward<Q>(other)...); }
86}
88// clang-format on
int int32_t
Platform independent (4) bytes signed int.
Definition: PrimitiveTypes.h:46
char native_char_t
The native char for the platform (wchar_t (4 bytes) on Windows, char (1 byte) everywhere else )
Definition: PrimitiveTypes.h:34
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition: PrimitiveTypes.h:36
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition: PrimitiveTypes.h:42
signed char int8_t
Platform independent (1) byte signed int.
Definition: PrimitiveTypes.h:44
long long int64_t
Platform independent (8) bytes signed int.
Definition: PrimitiveTypes.h:50
unsigned long size_t
Platform independent unsigned size type.
Definition: PrimitiveTypes.h:56
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition: PrimitiveTypes.h:38
short int16_t
Platform independent (2) bytes signed int.
Definition: PrimitiveTypes.h:45
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition: PrimitiveTypes.h:37
signed long ssize_t
Platform independent signed size type.
Definition: PrimitiveTypes.h:57