Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
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#else
25using native_char_t = char;
26
27using uint8_t = unsigned char;
28using uint16_t = unsigned short;
29using uint32_t = unsigned int;
30#if SC_PLATFORM_LINUX
31using uint64_t = unsigned long int;
32#else
33using uint64_t = unsigned long long;
34#endif
35using int8_t = signed char;
36using int16_t = short;
37using int32_t = int;
38#if SC_PLATFORM_LINUX
39using int64_t = signed long int;
40#else
41using int64_t = long long;
42#endif
43#endif
44
45using size_t = decltype(sizeof(0));
46using ssize_t = decltype(static_cast<char*>(nullptr) - static_cast<char*>(nullptr));
47
49struct TimeMs
50{
51 int64_t milliseconds = 0;
52};
54} // namespace SC
55
56// clang-format off
57namespace SC
58{
62struct PlacementNew {};
64} // namespace SC
67
69#if SC_COMPILER_MSVC
70inline void* operator new(size_t, void* p, SC::PlacementNew) noexcept { return p; }
71inline void* operator new[](size_t, void* p, SC::PlacementNew) noexcept { return p; }
72inline void operator delete(void*, void*, SC::PlacementNew) noexcept {}
73#else
74inline void* operator new(decltype(sizeof(0)), void* p, SC::PlacementNew) noexcept { return p; }
75inline void* operator new[](decltype(sizeof(0)), void* p, SC::PlacementNew) noexcept { return p; }
76#endif
77namespace SC
78{
80template<typename T, typename... Q> void placementNew(T& storage, Q&&... other) { new (&storage, PlacementNew()) T(SC::forward<Q>(other)...); }
81template<typename T> void placementNewArray(T* storage, size_t size) { new (storage, PlacementNew()) T[size]; }
82template<typename T> void dtor(T& t){ t.~T(); }
83}
85// clang-format on
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition PrimitiveTypes.h:28
constexpr T && forward(typename TypeTraits::RemoveReference< T >::type &value)
Forwards an lvalue or an rvalue as an rvalue reference.
Definition Compiler.h:276
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition PrimitiveTypes.h:27
decltype(sizeof(0)) size_t
Platform independent unsigned size type.
Definition PrimitiveTypes.h:45
decltype(static_cast< char * >(nullptr) - static_cast< char * >(nullptr)) ssize_t
Platform independent signed size type.
Definition PrimitiveTypes.h:46
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:33
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:29
short int16_t
Platform independent (2) bytes signed int.
Definition PrimitiveTypes.h:36
long long int64_t
Platform independent (8) bytes signed int.
Definition PrimitiveTypes.h:41
signed char int8_t
Platform independent (1) byte signed int.
Definition PrimitiveTypes.h:35
int int32_t
Platform independent (4) bytes signed int.
Definition PrimitiveTypes.h:37
char native_char_t
The native char for the platform (wchar_t (4 bytes) on Windows, char (1 byte) everywhere else )
Definition PrimitiveTypes.h:25
A vocabulary type representing a time interval in milliseconds since epoch.
Definition PrimitiveTypes.h:50