/************************************************************************************//*! \file Debug.hxx \author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu \date Oct 30, 2021 \brief Contains the definition of the Debug static class and the declaration of its functions. Note: This file is written in C++17/CLI. Copyright (C) 2021 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ #pragma once // Standard Library #include #include /*-------------------------------------------------------------------------------------*/ /* Macro Functions */ /*-------------------------------------------------------------------------------------*/ /// /// Macro expansion that is used together with SAFE_NATIVE_CALL_END or /// SAFE_NATIVE_CALL_END_N to wrap the body of a function with a try and catch that /// catches native and managed exceptions. This is needed to prevent crashes when calling /// managed code from native code. /// #define SAFE_NATIVE_CALL_BEGIN try { /// /// Macro expansion that is used together with SAFE_NATIVE_CALL_BEGIN or to wrap the body /// of a function with a try and catch that catches native and managed exceptions. This /// is needed to prevent crashes when calling managed code from native code. ///
/// Use this instead of SAFE_NATIVE_CALL_END_N if passing in managed types as the owner. ///
/// /// The managed object that owns the function that this macro encapsulates. /// #define SAFE_NATIVE_CALL_END(OWNER) \ } \ catch (System::Exception^ e) \ { \ Debug::LogException(e); \ } \ catch (const std::exception& e) \ { \ Debug::LogException(e, OWNER); \ } \ catch (...) \ { \ Debug::LogError("Unsupported native exception.", OWNER); \ } \ /// /// Macro expansion that is used together with SAFE_NATIVE_CALL_BEGIN or to wrap the body /// of a function with a try and catch that catches native and managed exceptions. This /// is needed to prevent crashes when calling managed code from native code. ///
/// Use this instead of SAFE_NATIVE_CALL_END if passing in a native string that specifies /// the owner. ///
/// /// The managed object that owns the function that this macro encapsulates. /// #define SAFE_NATIVE_CALL_END_N(OWNER) \ } \ catch (System::Exception^ e) \ { \ Debug::LogExceptionNative(e, OWNER); \ } \ catch (const std::exception& e) \ { \ Debug::LogExceptionNative(e, OWNER); \ } \ catch (...) \ { \ Debug::LogErrorNative("Unsupported native exception.", OWNER); \ } \ /*-------------------------------------------------------------------------------------*/ /* Type Definitions */ /*-------------------------------------------------------------------------------------*/ namespace SHADE { /// /// Static class that contains the functions for working with time. /// public ref class Debug abstract sealed { public: /*-----------------------------------------------------------------------------*/ /* Logging Functions */ /*-----------------------------------------------------------------------------*/ /// /// Logs a message to the output. /// /// The string to output. static void Log(const std::string& str); /// /// Logs a message to the output. /// /// The string to output. static void Log(System::String^ str); /// /// Logs a message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Object that sent the message to label the message. /// The name of the object will be used. /// static void Log(System::String^ str, Object^ owner); /// /// Logs a message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Name of the object that sent the message to label the message. /// The name of the object will be used. /// static void Log(System::String^ str, System::String^ throwerName); /// /// Logs a message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Name of the object that sent the message to label the message. /// The name of the object will be used. /// static void Log(System::String^ str, const std::string& throwerName); /// /// Logs a warning message to the output. /// /// The string to output. static void LogWarning(const std::string& str); /// /// Logs a warning message to the output. /// /// The string to output. static void LogWarning(System::String^ str); /// /// Logs a warning message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Object that threw the warning to label the warning message. /// The name of the object will be used. /// static void LogWarning(System::String^ str, Object^ thrower); /// /// Logs a warning message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Name of the object that threw the warning to label the warning message. /// The name of the object will be used. /// static void LogWarning(System::String^ str, System::String^ throwerName); /// /// Logs a warning message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Name of the object that threw the warning to label the warning message. /// The name of the object will be used. /// static void LogWarning(System::String^ str, const std::string& throwerName); /// /// Logs a error message to the output. /// /// The string to output. static void LogError(const std::string& str); /// /// Logs a error message to the output. /// /// The string to output. static void LogError(System::String^ str); /// /// Logs a error message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Object that threw the error to label the error message. /// The name of the object will be used. /// static void LogError(System::String^ str, Object^ thrower); /// /// Logs a error message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Name of the object that threw the error to label the error message. /// The name of the object will be used. /// static void LogErrorNative(System::String^ str, const std::string& throwerName); /// /// Logs a error message to the output with a label such that it looks like this: /// "[Label] Message" /// /// The string to output. /// /// Name of the object that threw the error to label the error message. /// The name of the object will be used. /// static void LogError(System::String^ str, System::String^ throwerName); /// /// Logs an exception that is formatted nicely to the output. /// /// Exception to log. static void LogException(System::Exception^ exception); /// /// Logs an exception that is formatted nicely to the output. /// /// Exception to log. /// /// Object that threw the exception to label the exception message. /// The name of the object will be used. /// static void LogException(System::Exception^ exception, Object^ thrower); /// /// Logs a native exception that is formatted nicely to the output. /// Equivalent to calling /// LogException(exception, Convert::ToNative(thrower->GetType()->Name)); /// /// Native exception to log. /// /// Object that threw the exception to label the exception message. /// The name of the object will be used. /// static void LogException(const std::exception& exception, Object^ thrower); /// /// Logs an exception that is formatted nicely to the output. /// /// Name of the one responsible for the exception. /// Exception to log. static void LogExceptionNative(System::Exception^ exception, const std::string& throwerName); /// /// Logs a native exception that is formatted nicely to the output. /// /// Native exception to log. /// Name of the one responsible for the exception. static void LogExceptionNative(const std::exception& exception, const std::string& throwerName); }; }