Browse Source

Move primitive types to Urho3D namespace, add byte type

1vanK 3 years ago
parent
commit
76dadb9a14

+ 2 - 0
Source/Samples/99_Benchmark/Benchmark03_MoleculeLogic.h

@@ -4,8 +4,10 @@
 #pragma once
 #pragma once
 
 
 #include <Urho3D/Scene/LogicComponent.h>
 #include <Urho3D/Scene/LogicComponent.h>
+#include <Urho3D/Base/PrimitiveTypes.h>
 
 
 namespace U3D = Urho3D;
 namespace U3D = Urho3D;
+using namespace Urho3D::PrimitiveTypes;
 
 
 class Benchmark03_MoleculeLogic : public U3D::LogicComponent
 class Benchmark03_MoleculeLogic : public U3D::LogicComponent
 {
 {

+ 4 - 0
Source/Samples/99_Benchmark/FpsCounter.h

@@ -3,6 +3,10 @@
 
 
 #pragma once
 #pragma once
 
 
+#include <Urho3D/Base/PrimitiveTypes.h>
+
+using namespace Urho3D::PrimitiveTypes;
+
 class FpsCounter
 class FpsCounter
 {
 {
 private:
 private:

+ 1 - 1
Source/Tools/OgreImporter/OgreImporter.cpp

@@ -12,7 +12,7 @@
 #include "OgreImporterUtils.h"
 #include "OgreImporterUtils.h"
 
 
 #ifdef WIN32
 #ifdef WIN32
-#include <windows.h>
+#include <Urho3D/Engine/WinWrapped.h>
 #endif
 #endif
 
 
 #include <Urho3D/DebugNew.h>
 #include <Urho3D/DebugNew.h>

+ 35 - 16
Source/Urho3D/Base/PrimitiveTypes.h

@@ -3,36 +3,55 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <climits>
-#include <cstdint>
-#include <stddef.h>
+#include <cstddef> // std::byte, std::ptrdiff_t
+#include <cstdint> // std::intptr_t, std::int8_t, ...
+#include <limits> // std::numeric_limits
+
 
 
 // https://en.cppreference.com/w/cpp/language/types
 // https://en.cppreference.com/w/cpp/language/types
-static_assert(CHAR_BIT == 8);
+static_assert(std::numeric_limits<unsigned char>::digits == 8);
 static_assert(sizeof(short) == 2);
 static_assert(sizeof(short) == 2);
 static_assert(sizeof(int) == 4);
 static_assert(sizeof(int) == 4);
 static_assert(sizeof(long) == 4 || sizeof(long) == 8); // (Win32, Win64, Unix32) || Unix64
 static_assert(sizeof(long) == 4 || sizeof(long) == 8); // (Win32, Win64, Unix32) || Unix64
 static_assert(sizeof(long long) == 8);
 static_assert(sizeof(long long) == 8);
+static_assert(sizeof(char32_t) == 4);
+
+// Pointer arithmetics
+static_assert(sizeof(void*) == sizeof(std::ptrdiff_t));
+static_assert(sizeof(void*) == sizeof(std::intptr_t));
+
+
+// User can inject Urho3D::PrimitiveTypes into other namespace
+namespace Urho3D::PrimitiveTypes
+{
 
 
 // https://en.cppreference.com/w/cpp/types/integer
 // https://en.cppreference.com/w/cpp/types/integer
-using i8 = int8_t;
-using u8 = uint8_t;
-using i16 = int16_t;
-using u16 = uint16_t;
-using i32 = int32_t;
-using u32 = uint32_t;
-using i64 = int64_t;
-using u64 = uint64_t;
+using i8 = std::int8_t;
+using u8 = std::uint8_t;
+using i16 = std::int16_t;
+using u16 = std::uint16_t;
+using i32 = std::int32_t;
+using u32 = std::uint32_t;
+using i64 = std::int64_t;
+using u64 = std::uint64_t;
 
 
 // Unicode code point (UTF-32 code unit)
 // Unicode code point (UTF-32 code unit)
-static_assert(sizeof(char32_t) == 4);
 using c32 = char32_t;
 using c32 = char32_t;
 
 
-// Pointer arithmetics
-static_assert(sizeof(void*) == sizeof(ptrdiff_t));
-static_assert(sizeof(void*) == sizeof(intptr_t));
+// For raw data
+using std::byte;
 
 
 // Some hash value (checksum for example)
 // Some hash value (checksum for example)
 using hash16 = u16;
 using hash16 = u16;
 using hash32 = u32;
 using hash32 = u32;
 using hash64 = u64;
 using hash64 = u64;
+
+} // namespace Urho3D::PrimitiveTypes
+
+
+namespace Urho3D
+{
+
+using namespace Urho3D::PrimitiveTypes;
+
+} // namespace Urho3D

+ 1 - 1
Source/Urho3D/Core/Main.h

@@ -7,7 +7,7 @@
 
 
 #if defined(_WIN32) && !defined(URHO3D_WIN32_CONSOLE)
 #if defined(_WIN32) && !defined(URHO3D_WIN32_CONSOLE)
 #include "../Core/MiniDump.h"
 #include "../Core/MiniDump.h"
-#include <windows.h>
+#include "../Engine/WinWrapped.h"
 #ifdef _MSC_VER
 #ifdef _MSC_VER
 #include <crtdbg.h>
 #include <crtdbg.h>
 #endif
 #endif

+ 13 - 0
Source/Urho3D/Engine/WinWrapped.h

@@ -0,0 +1,13 @@
+// Copyright (c) 2008-2022 the Urho3D project
+// License: MIT
+
+#pragma once
+
+#ifdef _WIN32
+
+// Avoid using byte in rpcndr.h
+#define byte BYTE
+#include <windows.h>
+#undef byte
+
+#endif // def _WIN32