From 4b2776f266aedd1aae75f6a0e68eb1560020986a Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 10 Apr 2016 17:01:16 +0100 Subject: [PATCH] move code from Diagnostics and Guard to cpp --- OpenRCT2.xcodeproj/project.pbxproj | 14 ++++++++++++++ openrct2.vcxproj | 4 +++- src/core/Diagnostics.cpp | 22 ++++++++++++++++++++++ src/core/Diagnostics.hpp | 15 +-------------- src/core/Guard.cpp | 24 ++++++++++++++++++++++++ src/core/Guard.hpp | 21 +-------------------- 6 files changed, 65 insertions(+), 35 deletions(-) create mode 100644 src/core/Diagnostics.cpp create mode 100644 src/core/Guard.cpp diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index 05303d303c..c907d2a7ab 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 1825236544844a508cff5cbc /* Diagnostics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81cf7519bf594fc784d5a8ff /* Diagnostics.cpp */; }; + 3825702bfcdb4591987ec9f6 /* Guard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6fe2e9d5655a47c3bb58aa07 /* Guard.cpp */; }; + 426da7e58564472ba1b7991f /* crash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = a9793fe06a4244938f5d4b61 /* crash.cpp */; }; 001085F01C90FD030075A2AD /* textinputbuffer.c in Sources */ = {isa = PBXBuildFile; fileRef = 001085EE1C90FD030075A2AD /* textinputbuffer.c */; }; 426da7e58564472ba1b7991f /* crash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = a9793fe06a4244938f5d4b61 /* crash.cpp */; }; C62A08D51C787C2A00F3AA76 /* drawing_fast.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C62A08D41C787C2A00F3AA76 /* drawing_fast.cpp */; }; @@ -223,6 +226,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 81cf7519bf594fc784d5a8ff /* Diagnostics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Diagnostics.cpp; path = src/core/Diagnostics.cpp; sourceTree = ""; }; + 6fe2e9d5655a47c3bb58aa07 /* Guard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Guard.cpp; path = src/core/Guard.cpp; sourceTree = ""; }; + a9793fe06a4244938f5d4b61 /* crash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = crash.cpp; path = src/platform/crash.cpp; sourceTree = ""; }; 001085EE1C90FD030075A2AD /* textinputbuffer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = textinputbuffer.c; sourceTree = ""; }; 001085EF1C90FD030075A2AD /* textinputbuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = textinputbuffer.h; sourceTree = ""; }; C62A08D41C787C2A00F3AA76 /* drawing_fast.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = drawing_fast.cpp; sourceTree = ""; }; @@ -659,6 +665,10 @@ D4163F671C2A044D00B83136 /* version.h */, a9793fe06a4244938f5d4b61 /* crash.cpp */, ); + a9793fe06a4244938f5d4b61 /* crash.cpp */, + 6fe2e9d5655a47c3bb58aa07 /* Guard.cpp */, + 81cf7519bf594fc784d5a8ff /* Diagnostics.cpp */, +); name = Sources; sourceTree = ""; }; @@ -1510,6 +1520,10 @@ D4EC48701C26342F0024B507 /* viewport.c in Sources */, 426da7e58564472ba1b7991f /* crash.cpp in Sources */, ); + 426da7e58564472ba1b7991f /* crash.cpp in Sources */, + 3825702bfcdb4591987ec9f6 /* Guard.cpp in Sources */, + 1825236544844a508cff5cbc /* Diagnostics.cpp in Sources */, +); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ diff --git a/openrct2.vcxproj b/openrct2.vcxproj index ffc532b2e5..78ee3a6adb 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -30,6 +30,8 @@ + + @@ -394,4 +396,4 @@ - \ No newline at end of file + diff --git a/src/core/Diagnostics.cpp b/src/core/Diagnostics.cpp new file mode 100644 index 0000000000..644cb59892 --- /dev/null +++ b/src/core/Diagnostics.cpp @@ -0,0 +1,22 @@ +#include + +#if defined(DEBUG) && defined(__WINDOWS__) + #define WIN32_LEAN_AND_MEAN + #include +#endif + +#include "Diagnostics.hpp" + +namespace Debug +{ + void Break() + { +#if DEBUG +#if __WINDOWS__ + if (IsDebuggerPresent()) { + DebugBreak(); + } +#endif +#endif + } +} diff --git a/src/core/Diagnostics.hpp b/src/core/Diagnostics.hpp index 5019b8c0d8..af5104819c 100644 --- a/src/core/Diagnostics.hpp +++ b/src/core/Diagnostics.hpp @@ -1,22 +1,9 @@ #pragma once -#if _WIN32 -#include -#endif - /** * Utility methods for asserting and logging. */ namespace Debug { - void Break() - { -#if DEBUG -#if _WIN32 - if (IsDebuggerPresent()) { - DebugBreak(); - } -#endif -#endif - } + void Break(); } diff --git a/src/core/Guard.cpp b/src/core/Guard.cpp new file mode 100644 index 0000000000..41b66ed19a --- /dev/null +++ b/src/core/Guard.cpp @@ -0,0 +1,24 @@ +#include +#include + +#include "Console.hpp" +#include "Diagnostics.hpp" +#include "Guard.hpp" + +namespace Guard +{ + void Assert(bool expression, const char * message) + { + if (expression) return; + + if (message != nullptr) + { + Console::Error::WriteLine(message); + } + +#if DEBUG + Debug::Break(); +#endif + assert(false); + } +} diff --git a/src/core/Guard.hpp b/src/core/Guard.hpp index 8556ce215a..48c89ae5c0 100644 --- a/src/core/Guard.hpp +++ b/src/core/Guard.hpp @@ -1,30 +1,11 @@ #pragma once -#include -#include - -#include "Console.hpp" -#include "Diagnostics.hpp" - /** * Utility methods for asserting function parameters. */ namespace Guard { - void Assert(bool expression, const char * message = nullptr) - { - if (expression) return; - - if (message != nullptr) - { - Console::Error::WriteLine(message); - } - -#if DEBUG - Debug::Break(); -#endif - assert(false); - } + void Assert(bool expression, const char * message = nullptr); template void ArgumentNotNull(T * argument, const char * message = nullptr)