From d8ea8afef5f157c21673171c7da7fa93f9546601 Mon Sep 17 00:00:00 2001 From: Danilo Borges Santos Date: Mon, 2 Dec 2024 19:02:51 -0300 Subject: [PATCH] =?UTF-8?q?Utiliza=20csharp::Exception=20em=20exce=C3=A7?= =?UTF-8?q?=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/csharp/exception.hpp | 290 ++++++++++----------- includes/pipeline/graphics.hpp | 8 +- includes/pipeline/pipeline.hpp | 10 +- includes/pipeline/serialization.hpp | 2 +- includes/pipeline/serializers.hpp | 4 +- includes/pipeline/writer.hpp | 12 +- includes/xna/content/reader.hpp | 4 +- includes/xna/content/readers/default.hpp | 2 +- includes/xna/csharp/stream.hpp | 4 +- includes/xna/csharp/type.hpp | 4 +- includes/xna/default.hpp | 2 +- includes/xna/exception.hpp | 39 --- includes/xna/framework.hpp | 2 +- sources/framework-dx/adapter.cpp | 4 +- sources/framework-dx/blendstate.cpp | 6 +- sources/framework-dx/depthstencilstate.cpp | 6 +- sources/framework-dx/device.cpp | 10 +- sources/framework-dx/effect.cpp | 2 +- sources/framework-dx/game.cpp | 5 +- sources/framework-dx/gdevicemanager.cpp | 12 +- sources/framework-dx/rasterizerstate.cpp | 8 +- sources/framework-dx/rendertarget.cpp | 6 +- sources/framework-dx/samplerstate.cpp | 12 +- sources/framework-dx/sprite.cpp | 10 +- sources/framework-dx/swapchain.cpp | 2 +- sources/framework-dx/texture.cpp | 28 +- sources/framework/CMakeLists.txt | 4 +- sources/framework/csharp/binary.cpp | 11 +- sources/framework/csharp/stream.cpp | 14 +- sources/framework/exception.cpp | 37 --- sources/pipeline/graphics.cpp | 6 +- sources/pipeline/writer.cpp | 4 +- 32 files changed, 248 insertions(+), 322 deletions(-) delete mode 100644 includes/xna/exception.hpp delete mode 100644 sources/framework/exception.cpp diff --git a/includes/csharp/exception.hpp b/includes/csharp/exception.hpp index f6e08a0..8fbb62e 100644 --- a/includes/csharp/exception.hpp +++ b/includes/csharp/exception.hpp @@ -9,123 +9,123 @@ namespace csharp { struct HResults { - inline static constexpr size_t HR_S_OK = 0x00000000; - inline static constexpr size_t HR_S_FALSE = 0x1; - inline static constexpr size_t COR_E_ABANDONEDMUTEX = 0x8013152D; - inline static constexpr size_t COR_E_AMBIGUOUSIMPLEMENTATION = 0x8013106A; - inline static constexpr size_t COR_E_AMBIGUOUSMATCH = 0x8000211D; - inline static constexpr size_t COR_E_APPDOMAINUNLOADED = 0x80131014; - inline static constexpr size_t COR_E_APPLICATION = 0x80131600; - inline static constexpr size_t COR_E_ARGUMENT = 0x80070057; - inline static constexpr size_t COR_E_ARGUMENTOUTOFRANGE = 0x80131502; - inline static constexpr size_t COR_E_ARITHMETIC = 0x80070216; - inline static constexpr size_t COR_E_ARRAYTYPEMISMATCH = 0x80131503; - inline static constexpr size_t COR_E_BADEXEFORMAT = 0x800700C1; - inline static constexpr size_t COR_E_BADIMAGEFORMAT = 0x8007000B; - inline static constexpr size_t COR_E_CANNOTUNLOADAPPDOMAIN = 0x80131015; - inline static constexpr size_t COR_E_CODECONTRACTFAILED = 0x80131542; - inline static constexpr size_t COR_E_CONTEXTMARSHAL = 0x80131504; - inline static constexpr size_t COR_E_CUSTOMATTRIBUTEFORMAT = 0x80131605; - inline static constexpr size_t COR_E_DATAMISALIGNED = 0x80131541; - inline static constexpr size_t COR_E_DIRECTORYNOTFOUND = 0x80070003; - inline static constexpr size_t COR_E_DIVIDEBYZERO = 0x80020012; - inline static constexpr size_t COR_E_DLLNOTFOUND = 0x80131524; - inline static constexpr size_t COR_E_DUPLICATEWAITOBJECT = 0x80131529; - inline static constexpr size_t COR_E_ENDOFSTREAM = 0x80070026; - inline static constexpr size_t COR_E_ENTRYPOINTNOTFOUND = 0x80131523; - inline static constexpr size_t COR_E_EXCEPTION = 0x80131500; - inline static constexpr size_t COR_E_EXECUTIONENGINE = 0x80131506; - inline static constexpr size_t COR_E_FAILFAST = 0x80131623; - inline static constexpr size_t COR_E_FIELDACCESS = 0x80131507; - inline static constexpr size_t COR_E_FILELOAD = 0x80131621; - inline static constexpr size_t COR_E_FILENOTFOUND = 0x80070002; - inline static constexpr size_t COR_E_FORMAT = 0x80131537; - inline static constexpr size_t COR_E_INDEXOUTOFRANGE = 0x80131508; - inline static constexpr size_t COR_E_INSUFFICIENTEXECUTIONSTACK = 0x80131578; - inline static constexpr size_t COR_E_INSUFFICIENTMEMORY = 0x8013153D; - inline static constexpr size_t COR_E_INVALIDCAST = 0x80004002; - inline static constexpr size_t COR_E_INVALIDCOMOBJECT = 0x80131527; - inline static constexpr size_t COR_E_INVALIDFILTERCRITERIA = 0x80131601; - inline static constexpr size_t COR_E_INVALIDOLEVARIANTTYPE = 0x80131531; - inline static constexpr size_t COR_E_INVALIDOPERATION = 0x80131509; - inline static constexpr size_t COR_E_INVALIDPROGRAM = 0x8013153A; - inline static constexpr size_t COR_E_IO = 0x80131620; - inline static constexpr size_t COR_E_KEYNOTFOUND = 0x80131577; - inline static constexpr size_t COR_E_MARSHALDIRECTIVE = 0x80131535; - inline static constexpr size_t COR_E_MEMBERACCESS = 0x8013151A; - inline static constexpr size_t COR_E_METHODACCESS = 0x80131510; - inline static constexpr size_t COR_E_MISSINGFIELD = 0x80131511; - inline static constexpr size_t COR_E_MISSINGMANIFESTRESOURCE = 0x80131532; - inline static constexpr size_t COR_E_MISSINGMEMBER = 0x80131512; - inline static constexpr size_t COR_E_MISSINGMETHOD = 0x80131513; - inline static constexpr size_t COR_E_MISSINGSATELLITEASSEMBLY = 0x80131536; - inline static constexpr size_t COR_E_MULTICASTNOTSUPPORTED = 0x80131514; - inline static constexpr size_t COR_E_NOTFINITENUMBER = 0x80131528; - inline static constexpr size_t COR_E_NOTSUPPORTED = 0x80131515; - inline static constexpr size_t COR_E_OBJECTDISPOSED = 0x80131622; - inline static constexpr size_t COR_E_OPERATIONCANCELED = 0x8013153B; - inline static constexpr size_t COR_E_OUTOFMEMORY = 0x8007000E; - inline static constexpr size_t COR_E_OVERFLOW = 0x80131516; - inline static constexpr size_t COR_E_PATHTOOLONG = 0x800700CE; - inline static constexpr size_t COR_E_PLATFORMNOTSUPPORTED = 0x80131539; - inline static constexpr size_t COR_E_RANK = 0x80131517; - inline static constexpr size_t COR_E_REFLECTIONTYPELOAD = 0x80131602; - inline static constexpr size_t COR_E_RUNTIMEWRAPPED = 0x8013153E; - inline static constexpr size_t COR_E_SAFEARRAYRANKMISMATCH = 0x80131538; - inline static constexpr size_t COR_E_SAFEARRAYTYPEMISMATCH = 0x80131533; - inline static constexpr size_t COR_E_SECURITY = 0x8013150A; - inline static constexpr size_t COR_E_SERIALIZATION = 0x8013150C; - inline static constexpr size_t COR_E_STACKOVERFLOW = 0x800703E9; - inline static constexpr size_t COR_E_SYNCHRONIZATIONLOCK = 0x80131518; - inline static constexpr size_t COR_E_SYSTEM = 0x80131501; - inline static constexpr size_t COR_E_TARGET = 0x80131603; - inline static constexpr size_t COR_E_TARGETINVOCATION = 0x80131604; - inline static constexpr size_t COR_E_TARGETPARAMCOUNT = 0x8002000E; - inline static constexpr size_t COR_E_THREADABORTED = 0x80131530; - inline static constexpr size_t COR_E_THREADINTERRUPTED = 0x80131519; - inline static constexpr size_t COR_E_THREADSTART = 0x80131525; - inline static constexpr size_t COR_E_THREADSTATE = 0x80131520; - inline static constexpr size_t COR_E_TIMEOUT = 0x80131505; - inline static constexpr size_t COR_E_TYPEACCESS = 0x80131543; - inline static constexpr size_t COR_E_TYPEINITIALIZATION = 0x80131534; - inline static constexpr size_t COR_E_TYPELOAD = 0x80131522; - inline static constexpr size_t COR_E_TYPEUNLOADED = 0x80131013; - inline static constexpr size_t COR_E_UNAUTHORIZEDACCESS = 0x80070005; - inline static constexpr size_t COR_E_VERIFICATION = 0x8013150D; - inline static constexpr size_t COR_E_WAITHANDLECANNOTBEOPENED = 0x8013152C; - inline static constexpr size_t CO_E_NOTINITIALIZED = 0x800401F0; - inline static constexpr size_t DISP_E_PARAMNOTFOUND = 0x80020004; - inline static constexpr size_t DISP_E_TYPEMISMATCH = 0x80020005; - inline static constexpr size_t DISP_E_BADVARTYPE = 0x80020008; - inline static constexpr size_t DISP_E_OVERFLOW = 0x8002000A; - inline static constexpr size_t DISP_E_DIVBYZERO = 0x80020012; - inline static constexpr size_t E_BOUNDS = 0x8000000B; - inline static constexpr size_t E_CHANGED_STATE = 0x8000000C; - inline static constexpr size_t E_FILENOTFOUND = 0x80070002; - inline static constexpr size_t E_FAIL = 0x80004005; - inline static constexpr size_t E_HANDLE = 0x80070006; - inline static constexpr size_t E_INVALIDARG = 0x80070057; - inline static constexpr size_t E_NOTIMPL = 0x80004001; - inline static constexpr size_t E_POINTER = 0x80004003; - inline static constexpr size_t ERROR_MRM_MAP_NOT_FOUND = 0x80073B1F; - inline static constexpr size_t ERROR_TIMEOUT = 0x800705B4; - inline static constexpr size_t RO_E_CLOSED = 0x80000013; - inline static constexpr size_t RPC_E_CHANGED_MODE = 0x80010106; - inline static constexpr size_t TYPE_E_TYPEMISMATCH = 0x80028CA0; - inline static constexpr size_t STG_E_PATHNOTFOUND = 0x80030003; - inline static constexpr size_t CTL_E_PATHNOTFOUND = 0x800A004C; - inline static constexpr size_t CTL_E_FILENOTFOUND = 0x800A0035; - inline static constexpr size_t FUSION_E_INVALID_NAME = 0x80131047; - inline static constexpr size_t FUSION_E_REF_DEF_MISMATCH = 0x80131040; - inline static constexpr size_t ERROR_TOO_MANY_OPEN_FILES = 0x80070004; - inline static constexpr size_t ERROR_SHARING_VIOLATION = 0x80070020; - inline static constexpr size_t ERROR_LOCK_VIOLATION = 0x80070021; - inline static constexpr size_t ERROR_OPEN_FAILED = 0x8007006E; - inline static constexpr size_t ERROR_DISK_CORRUPT = 0x80070571; - inline static constexpr size_t ERROR_UNRECOGNIZED_VOLUME = 0x800703ED; - inline static constexpr size_t ERROR_DLL_INIT_FAILED = 0x8007045A; - inline static constexpr size_t MSEE_E_ASSEMBLYLOADINPROGRESS = 0x80131016; - inline static constexpr size_t ERROR_FILE_INVALID = 0x800703EE; + static constexpr size_t HR_S_OK = 0x00000000; + static constexpr size_t HR_S_FALSE = 0x1; + static constexpr size_t HR_COR_E_ABANDONEDMUTEX = 0x8013152D; + static constexpr size_t HR_COR_E_AMBIGUOUSIMPLEMENTATION = 0x8013106A; + static constexpr size_t HR_COR_E_AMBIGUOUSMATCH = 0x8000211D; + static constexpr size_t HR_COR_E_APPDOMAINUNLOADED = 0x80131014; + static constexpr size_t HR_COR_E_APPLICATION = 0x80131600; + static constexpr size_t HR_COR_E_ARGUMENT = 0x80070057; + static constexpr size_t HR_COR_E_ARGUMENTOUTOFRANGE = 0x80131502; + static constexpr size_t HR_COR_E_ARITHMETIC = 0x80070216; + static constexpr size_t HR_COR_E_ARRAYTYPEMISMATCH = 0x80131503; + static constexpr size_t HR_COR_E_BADEXEFORMAT = 0x800700C1; + static constexpr size_t HR_COR_E_BADIMAGEFORMAT = 0x8007000B; + static constexpr size_t HR_COR_E_CANNOTUNLOADAPPDOMAIN = 0x80131015; + static constexpr size_t HR_COR_E_CODECONTRACTFAILED = 0x80131542; + static constexpr size_t HR_COR_E_CONTEXTMARSHAL = 0x80131504; + static constexpr size_t HR_COR_E_CUSTOMATTRIBUTEFORMAT = 0x80131605; + static constexpr size_t HR_COR_E_DATAMISALIGNED = 0x80131541; + static constexpr size_t HR_COR_E_DIRECTORYNOTFOUND = 0x80070003; + static constexpr size_t HR_COR_E_DIVIDEBYZERO = 0x80020012; + static constexpr size_t HR_COR_E_DLLNOTFOUND = 0x80131524; + static constexpr size_t HR_COR_E_DUPLICATEWAITOBJECT = 0x80131529; + static constexpr size_t HR_COR_E_ENDOFSTREAM = 0x80070026; + static constexpr size_t HR_COR_E_ENTRYPOINTNOTFOUND = 0x80131523; + static constexpr size_t HR_COR_E_EXCEPTION = 0x80131500; + static constexpr size_t HR_COR_E_EXECUTIONENGINE = 0x80131506; + static constexpr size_t HR_COR_E_FAILFAST = 0x80131623; + static constexpr size_t HR_COR_E_FIELDACCESS = 0x80131507; + static constexpr size_t HR_COR_E_FILELOAD = 0x80131621; + static constexpr size_t HR_COR_E_FILENOTFOUND = 0x80070002; + static constexpr size_t HR_COR_E_FORMAT = 0x80131537; + static constexpr size_t HR_COR_E_INDEXOUTOFRANGE = 0x80131508; + static constexpr size_t HR_COR_E_INSUFFICIENTEXECUTIONSTACK = 0x80131578; + static constexpr size_t HR_COR_E_INSUFFICIENTMEMORY = 0x8013153D; + static constexpr size_t HR_COR_E_INVALIDCAST = 0x80004002; + static constexpr size_t HR_COR_E_INVALIDCOMOBJECT = 0x80131527; + static constexpr size_t HR_COR_E_INVALIDFILTERCRITERIA = 0x80131601; + static constexpr size_t HR_COR_E_INVALIDOLEVARIANTTYPE = 0x80131531; + static constexpr size_t HR_COR_E_INVALIDOPERATION = 0x80131509; + static constexpr size_t HR_COR_E_INVALIDPROGRAM = 0x8013153A; + static constexpr size_t HR_COR_E_IO = 0x80131620; + static constexpr size_t HR_COR_E_KEYNOTFOUND = 0x80131577; + static constexpr size_t HR_COR_E_MARSHALDIRECTIVE = 0x80131535; + static constexpr size_t HR_COR_E_MEMBERACCESS = 0x8013151A; + static constexpr size_t HR_COR_E_METHODACCESS = 0x80131510; + static constexpr size_t HR_COR_E_MISSINGFIELD = 0x80131511; + static constexpr size_t HR_COR_E_MISSINGMANIFESTRESOURCE = 0x80131532; + static constexpr size_t HR_COR_E_MISSINGMEMBER = 0x80131512; + static constexpr size_t HR_COR_E_MISSINGMETHOD = 0x80131513; + static constexpr size_t HR_COR_E_MISSINGSATELLITEASSEMBLY = 0x80131536; + static constexpr size_t HR_COR_E_MULTICASTNOTSUPPORTED = 0x80131514; + static constexpr size_t HR_COR_E_NOTFINITENUMBER = 0x80131528; + static constexpr size_t HR_COR_E_NOTSUPPORTED = 0x80131515; + static constexpr size_t HR_COR_E_OBJECTDISPOSED = 0x80131622; + static constexpr size_t HR_COR_E_OPERATIONCANCELED = 0x8013153B; + static constexpr size_t HR_COR_E_OUTOFMEMORY = 0x8007000E; + static constexpr size_t HR_COR_E_OVERFLOW = 0x80131516; + static constexpr size_t HR_COR_E_PATHTOOLONG = 0x800700CE; + static constexpr size_t HR_COR_E_PLATFORMNOTSUPPORTED = 0x80131539; + static constexpr size_t HR_COR_E_RANK = 0x80131517; + static constexpr size_t HR_COR_E_REFLECTIONTYPELOAD = 0x80131602; + static constexpr size_t HR_COR_E_RUNTIMEWRAPPED = 0x8013153E; + static constexpr size_t HR_COR_E_SAFEARRAYRANKMISMATCH = 0x80131538; + static constexpr size_t HR_COR_E_SAFEARRAYTYPEMISMATCH = 0x80131533; + static constexpr size_t HR_COR_E_SECURITY = 0x8013150A; + static constexpr size_t HR_COR_E_SERIALIZATION = 0x8013150C; + static constexpr size_t HR_COR_E_STACKOVERFLOW = 0x800703E9; + static constexpr size_t HR_COR_E_SYNCHRONIZATIONLOCK = 0x80131518; + static constexpr size_t HR_COR_E_SYSTEM = 0x80131501; + static constexpr size_t HR_COR_E_TARGET = 0x80131603; + static constexpr size_t HR_COR_E_TARGETINVOCATION = 0x80131604; + static constexpr size_t HR_COR_E_TARGETPARAMCOUNT = 0x8002000E; + static constexpr size_t HR_COR_E_THREADABORTED = 0x80131530; + static constexpr size_t HR_COR_E_THREADINTERRUPTED = 0x80131519; + static constexpr size_t HR_COR_E_THREADSTART = 0x80131525; + static constexpr size_t HR_COR_E_THREADSTATE = 0x80131520; + static constexpr size_t HR_COR_E_TIMEOUT = 0x80131505; + static constexpr size_t HR_COR_E_TYPEACCESS = 0x80131543; + static constexpr size_t HR_COR_E_TYPEINITIALIZATION = 0x80131534; + static constexpr size_t HR_COR_E_TYPELOAD = 0x80131522; + static constexpr size_t HR_COR_E_TYPEUNLOADED = 0x80131013; + static constexpr size_t HR_COR_E_UNAUTHORIZEDACCESS = 0x80070005; + static constexpr size_t HR_COR_E_VERIFICATION = 0x8013150D; + static constexpr size_t HR_COR_E_WAITHANDLECANNOTBEOPENED = 0x8013152C; + static constexpr size_t HR_CO_E_NOTINITIALIZED = 0x800401F0; + static constexpr size_t HR_DISP_E_PARAMNOTFOUND = 0x80020004; + static constexpr size_t HR_DISP_E_TYPEMISMATCH = 0x80020005; + static constexpr size_t HR_DISP_E_BADVARTYPE = 0x80020008; + static constexpr size_t HR_DISP_E_OVERFLOW = 0x8002000A; + static constexpr size_t HR_DISP_E_DIVBYZERO = 0x80020012; + static constexpr size_t HR_E_BOUNDS = 0x8000000B; + static constexpr size_t HR_E_CHANGED_STATE = 0x8000000C; + static constexpr size_t HR_E_FILENOTFOUND = 0x80070002; + static constexpr size_t HR_E_FAIL = 0x80004005; + static constexpr size_t HR_E_HANDLE = 0x80070006; + static constexpr size_t HR_E_INVALIDARG = 0x80070057; + static constexpr size_t HR_E_NOTIMPL = 0x80004001; + static constexpr size_t HR_E_POINTER = 0x80004003; + static constexpr size_t HR_ERROR_MRM_MAP_NOT_FOUND = 0x80073B1F; + static constexpr size_t HR_ERROR_TIMEOUT = 0x800705B4; + static constexpr size_t HR_RO_E_CLOSED = 0x80000013; + static constexpr size_t HR_RPC_E_CHANGED_MODE = 0x80010106; + static constexpr size_t HR_TYPE_E_TYPEMISMATCH = 0x80028CA0; + static constexpr size_t HR_STG_E_PATHNOTFOUND = 0x80030003; + static constexpr size_t HR_CTL_E_PATHNOTFOUND = 0x800A004C; + static constexpr size_t HR_CTL_E_FILENOTFOUND = 0x800A0035; + static constexpr size_t HR_FUSION_E_INVALID_NAME = 0x80131047; + static constexpr size_t HR_FUSION_E_REF_DEF_MISMATCH = 0x80131040; + static constexpr size_t HR_ERROR_TOO_MANY_OPEN_FILES = 0x80070004; + static constexpr size_t HR_ERROR_SHARING_VIOLATION = 0x80070020; + static constexpr size_t HR_ERROR_LOCK_VIOLATION = 0x80070021; + static constexpr size_t HR_ERROR_OPEN_FAILED = 0x8007006E; + static constexpr size_t HR_ERROR_DISK_CORRUPT = 0x80070571; + static constexpr size_t HR_ERROR_UNRECOGNIZED_VOLUME = 0x800703ED; + static constexpr size_t HR_ERROR_DLL_INIT_FAILED = 0x8007045A; + static constexpr size_t HR_MSEE_E_ASSEMBLYLOADINPROGRESS = 0x80131016; + static constexpr size_t HR_ERROR_FILE_INVALID = 0x800703EE; }; class Exception : public std::runtime_error { @@ -147,7 +147,7 @@ namespace csharp { public: std::string HelpLink; std::source_location Source; - size_t HRresult{ HResults::COR_E_EXCEPTION }; + size_t HRresult{ HResults::HR_COR_E_EXCEPTION }; private: std::string message; @@ -159,28 +159,28 @@ namespace csharp { public: ArgumentException(std::source_location const& source = std::source_location::current()): Exception(SR::Arg_ArgumentException, source) { - HRresult = HResults::COR_E_ARGUMENT; + HRresult = HResults::HR_COR_E_ARGUMENT; } ArgumentException(std::string const& message, std::source_location const& source = std::source_location::current()) : Exception(!message.empty() ? message : SR::Arg_ArgumentException, source) { - HRresult = HResults::COR_E_ARGUMENT; + HRresult = HResults::HR_COR_E_ARGUMENT; }; ArgumentException(std::string const& message, std::string const& paramName, std::source_location const& source = std::source_location::current()) : paramName(paramName), Exception(!message.empty() ? message : SR::Arg_ArgumentException, source) { - HRresult = HResults::COR_E_ARGUMENT; + HRresult = HResults::HR_COR_E_ARGUMENT; }; ArgumentException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : Exception(!message.empty() ? message : SR::Arg_ArgumentException, innerException, source) { - HRresult = HResults::COR_E_ARGUMENT; + HRresult = HResults::HR_COR_E_ARGUMENT; } ArgumentException(std::string const& message, std::string const& paramName, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : paramName(paramName), Exception(!message.empty() ? message : SR::Arg_ArgumentException, innerException, source) { - HRresult = HResults::COR_E_ARGUMENT; + HRresult = HResults::HR_COR_E_ARGUMENT; } constexpr std::string Message() const override { @@ -196,28 +196,28 @@ namespace csharp { public: ArgumentNullException(std::source_location const& source = std::source_location::current()) : ArgumentException(SR::ArgumentNull_Generic, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; } ArgumentNullException(std::string const& message, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::ArgumentNull_Generic, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; }; ArgumentNullException(std::string const& message, std::string const& paramName, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::ArgumentNull_Generic, paramName, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; }; ArgumentNullException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::ArgumentNull_Generic, innerException, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; } ArgumentNullException(std::string const& message, std::string const& paramName, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::ArgumentNull_Generic, paramName, innerException, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; } }; @@ -226,28 +226,28 @@ namespace csharp { public: ArgumentOutOfRangeException(std::source_location const& source = std::source_location::current()) : ArgumentException(SR::Arg_ArgumentOutOfRangeException, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; } ArgumentOutOfRangeException(std::string const& message, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::Arg_ArgumentOutOfRangeException, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; }; ArgumentOutOfRangeException(std::string const& message, std::string const& paramName, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::Arg_ArgumentOutOfRangeException, paramName, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; }; ArgumentOutOfRangeException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::Arg_ArgumentOutOfRangeException, innerException, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; } ArgumentOutOfRangeException(std::string const& message, std::string const& paramName, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : ArgumentException(!message.empty() ? message : SR::Arg_ArgumentOutOfRangeException, paramName, innerException, source) { - HRresult = HResults::E_POINTER; + HRresult = HResults::HR_E_POINTER; } }; @@ -255,19 +255,19 @@ namespace csharp { public: SystemException(std::source_location const& source = std::source_location::current()) : Exception(SR::Arg_SystemException, source) { - HRresult = HResults::COR_E_SYSTEM; + HRresult = HResults::HR_COR_E_SYSTEM; } SystemException(std::string const& message, std::source_location const& source = std::source_location::current()) : Exception(!message.empty() ? message : SR::Arg_SystemException, source) { - HRresult = HResults::COR_E_SYSTEM; + HRresult = HResults::HR_COR_E_SYSTEM; } SystemException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : Exception(!message.empty() ? message : SR::Arg_ArgumentException, innerException, source) { - HRresult = HResults::COR_E_SYSTEM; + HRresult = HResults::HR_COR_E_SYSTEM; } }; @@ -277,19 +277,19 @@ namespace csharp { InvalidOperationException(std::source_location const& source = std::source_location::current()) : SystemException(SR::Arg_SystemException, source) { - HRresult = HResults::COR_E_INVALIDOPERATION; + HRresult = HResults::HR_COR_E_INVALIDOPERATION; } InvalidOperationException(std::string const& message, std::source_location const& source = std::source_location::current()) : SystemException(!message.empty() ? message : SR::Arg_InvalidOperationException, source) { - HRresult = HResults::COR_E_INVALIDOPERATION; + HRresult = HResults::HR_COR_E_INVALIDOPERATION; } InvalidOperationException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : SystemException(!message.empty() ? message : SR::Arg_InvalidOperationException, innerException, source) { - HRresult = HResults::COR_E_INVALIDOPERATION; + HRresult = HResults::HR_COR_E_INVALIDOPERATION; } }; @@ -300,19 +300,19 @@ namespace csharp { NotSupportedException(std::source_location const& source = std::source_location::current()) : SystemException(SR::Arg_NotSupportedException, source) { - HRresult = HResults::COR_E_INVALIDOPERATION; + HRresult = HResults::HR_COR_E_INVALIDOPERATION; } NotSupportedException(std::string const& message, std::source_location const& source = std::source_location::current()) : SystemException(!message.empty() ? message : SR::Arg_NotSupportedException, source) { - HRresult = HResults::COR_E_INVALIDOPERATION; + HRresult = HResults::HR_COR_E_INVALIDOPERATION; } NotSupportedException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : SystemException(!message.empty() ? message : SR::Arg_NotSupportedException, innerException, source) { - HRresult = HResults::COR_E_INVALIDOPERATION; + HRresult = HResults::HR_COR_E_INVALIDOPERATION; } }; @@ -322,19 +322,19 @@ namespace csharp { UnauthorizedAccessException(std::source_location const& source = std::source_location::current()) : SystemException(SR::Arg_UnauthorizedAccessException, source) { - HRresult = HResults::COR_E_UNAUTHORIZEDACCESS; + HRresult = HResults::HR_COR_E_UNAUTHORIZEDACCESS; } UnauthorizedAccessException(std::string const& message, std::source_location const& source = std::source_location::current()) : SystemException(!message.empty() ? message : SR::Arg_UnauthorizedAccessException, source) { - HRresult = HResults::COR_E_UNAUTHORIZEDACCESS; + HRresult = HResults::HR_COR_E_UNAUTHORIZEDACCESS; } UnauthorizedAccessException(std::string const& message, std::shared_ptr& innerException, std::source_location const& source = std::source_location::current()) : SystemException(!message.empty() ? message : SR::Arg_UnauthorizedAccessException, innerException, source) { - HRresult = HResults::COR_E_UNAUTHORIZEDACCESS; + HRresult = HResults::HR_COR_E_UNAUTHORIZEDACCESS; } }; } diff --git a/includes/pipeline/graphics.hpp b/includes/pipeline/graphics.hpp index cd38419..9cfeb3d 100644 --- a/includes/pipeline/graphics.hpp +++ b/includes/pipeline/graphics.hpp @@ -4,7 +4,7 @@ #include "pipeline.hpp" #include #include -#include "xna/exception.hpp" +#include "csharp/exception.hpp" #include "xna/common/numerics.hpp" #include "xna/graphics/shared.hpp" @@ -14,7 +14,7 @@ namespace xna { public: BitmapContent(int32_t width, int32_t height) { if (width <= 0 || height <= 0) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); this->width = width; this->height = height; @@ -26,7 +26,7 @@ namespace xna { //Gets or sets the width of the bitmap, in pixels. constexpr void Width(int32_t value) { if(value <= 0) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); width = value; } @@ -37,7 +37,7 @@ namespace xna { //Gets or sets the height of the bitmap, in pixels. constexpr void Height(int32_t value) { if (value <= 0) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); height = value; } diff --git a/includes/pipeline/pipeline.hpp b/includes/pipeline/pipeline.hpp index 5dd2b18..373d2d4 100644 --- a/includes/pipeline/pipeline.hpp +++ b/includes/pipeline/pipeline.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "xna/exception.hpp" +#include "csharp/exception.hpp" #include "xna/helpers.hpp" #include "serialization.hpp" @@ -56,12 +56,12 @@ namespace xna { protected: virtual void AddItem(std::string const& key, T const& value) { if (key.empty()) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } if constexpr (XnaHelper::IsSmartPoint()) { if (value == nullptr) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } items.insert({ key, value }); @@ -88,12 +88,12 @@ namespace xna { virtual void SetItem(std::string const& key, T const& value) { if (key.empty()) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } if constexpr (XnaHelper::IsSmartPoint()) { if (value == nullptr) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } items[key] = value; diff --git a/includes/pipeline/serialization.hpp b/includes/pipeline/serialization.hpp index 8078b55..f3a6e03 100644 --- a/includes/pipeline/serialization.hpp +++ b/includes/pipeline/serialization.hpp @@ -159,7 +159,7 @@ namespace xna { return std::any_cast(value); } catch (std::exception& ex) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } } }; diff --git a/includes/pipeline/serializers.hpp b/includes/pipeline/serializers.hpp index 274ed3c..61a69a5 100644 --- a/includes/pipeline/serializers.hpp +++ b/includes/pipeline/serializers.hpp @@ -2,7 +2,7 @@ #define XNA_PIPELINE_SERIALIZERS_HPP #include "serialization.hpp" -#include "xna/exception.hpp" +#include "csharp/exception.hpp" #include #include #include @@ -13,7 +13,7 @@ namespace xna { public: XmlListReader(std::shared_ptr const& reader) : reader(reader) { if (this->reader == nullptr) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); //this.enumerator = ((IEnumerable) reader.Xml.ReadContentAsString().Split(XmlListReader.listSeparators, StringSplitOptions.RemoveEmptyEntries)).GetEnumerator(); } diff --git a/includes/pipeline/writer.hpp b/includes/pipeline/writer.hpp index d297375..a56617e 100644 --- a/includes/pipeline/writer.hpp +++ b/includes/pipeline/writer.hpp @@ -175,7 +175,7 @@ namespace xna { void ContentWriter::WriteObject(T& value) { if constexpr (XnaHelper::IsSmartPoint()) { if (value == nullptr) { - Exception::Throw(Exception::ARGUMENT_IS_NULL); + throw csharp::InvalidOperationException(Exception::ARGUMENT_IS_NULL); } } @@ -203,7 +203,7 @@ namespace xna { void ContentWriter::WriteRawObject(T& value) { if constexpr (XnaHelper::IsSmartPoint()) { if (value == nullptr) { - Exception::Throw(Exception::ARGUMENT_IS_NULL); + throw csharp::InvalidOperationException(Exception::ARGUMENT_IS_NULL); } } @@ -216,7 +216,7 @@ namespace xna { template void ContentWriter::WriteRawObject(T& value, ContentTypeWriter& typeWriter) { - Exception::ThrowTIsNull(value); + throw csharp::InvalidOperationExceptionTIsNull(value); InvokeWriter(value, typeWriter); } @@ -259,13 +259,13 @@ namespace xna { if (filename1.ends_with(FilenameExt)) filename2 = filename1.substr(0, filename1.size() - FilenameExt.size()); else - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); if (!filename2.starts_with(rootDirectory)) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); } } diff --git a/includes/xna/content/reader.hpp b/includes/xna/content/reader.hpp index 76d85b8..2b8a782 100644 --- a/includes/xna/content/reader.hpp +++ b/includes/xna/content/reader.hpp @@ -110,7 +110,7 @@ namespace xna { const auto index = num - 1; if (index >= typeReaders.size()) { - Exception::Throw(Exception::BAD_XNB); + throw csharp::InvalidOperationException("Bad Xnb"); } auto& reader = typeReaders[index]; @@ -130,7 +130,7 @@ namespace xna { return objB; } else { - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); } return misc::ReturnDefaultOrNull(); diff --git a/includes/xna/content/readers/default.hpp b/includes/xna/content/readers/default.hpp index 7f5c5fa..6d05e32 100644 --- a/includes/xna/content/readers/default.hpp +++ b/includes/xna/content/readers/default.hpp @@ -13,7 +13,7 @@ namespace xna { ObjectReader() : ContentTypeReader(typeof()) {} virtual Object Read(ContentReader& input, Object& existingInstance) override { - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); return Object(); } diff --git a/includes/xna/csharp/stream.hpp b/includes/xna/csharp/stream.hpp index 3bd7ef9..450cb1f 100644 --- a/includes/xna/csharp/stream.hpp +++ b/includes/xna/csharp/stream.hpp @@ -5,7 +5,7 @@ #include #include #include -#include "../exception.hpp" +#include "csharp/exception.hpp" namespace xna { // Provides seek reference points. @@ -162,7 +162,7 @@ namespace xna { virtual int64_t Position() override; virtual void SetLength(int64_t value) override { - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); } inline virtual void Close() override { diff --git a/includes/xna/csharp/type.hpp b/includes/xna/csharp/type.hpp index 853b946..d73ff04 100644 --- a/includes/xna/csharp/type.hpp +++ b/includes/xna/csharp/type.hpp @@ -2,7 +2,7 @@ #define XNA_CSHARP_TYPE_HPP #include "misc.hpp" -#include "../exception.hpp" +#include "csharp/exception.hpp" #include #include #include @@ -81,7 +81,7 @@ namespace xna { } else { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } return type; diff --git a/includes/xna/default.hpp b/includes/xna/default.hpp index 77dba3d..1add575 100644 --- a/includes/xna/default.hpp +++ b/includes/xna/default.hpp @@ -15,7 +15,7 @@ #include #include "enumerations.hpp" -#include "exception.hpp" +#include "csharp/exception.hpp" #include "misc.hpp" namespace xna { diff --git a/includes/xna/exception.hpp b/includes/xna/exception.hpp deleted file mode 100644 index 4dffea3..0000000 --- a/includes/xna/exception.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef XNA_EXCEPTION_HPP -#define XNA_EXCEPTION_HPP - -#include -#include -#include -#include - -namespace xna { - //Structure for throwing exceptions with a message and information from the source file - struct Exception { - //Raises an exception with a message. Source file information is automatically captured. - static void Throw(std::string const& message = "", std::source_location const& location = std::source_location::current()); - - inline static void ThrowIfNull(std::shared_ptr const& argument, std::string const& argumentName, std::source_location const& location = std::source_location::current()) { - ThrowIfNull(&argument, argumentName, location); - } - - inline static void ThrowIfNull(std::unique_ptr const& argument, std::string const& argumentName, std::source_location const& location = std::source_location::current()) { - ThrowIfNull(&argument, argumentName, location); - } - - static void ThrowIfNull(void const* argument, std::string const& argumentName, std::source_location const& location = std::source_location::current()); - - inline static const std::string FAILED_TO_CREATE = "Failed to create component."; - inline static const std::string FAILED_TO_APPLY = "Failed to apply component."; - inline static const std::string FAILED_TO_MAKE_WINDOW_ASSOCIATION = "Failed to create association with window."; - inline static const std::string UNABLE_TO_INITIALIZE = "Unable to initialize component."; - inline static const std::string UNABLE_TO_BUILD_OBJECT = "Unable to build object."; - inline static const std::string NOT_IMPLEMENTED = "Not Implemented."; - inline static const std::string ARGUMENT_IS_NULL = "The argument is null or one of its values."; - inline static const std::string INVALID_OPERATION = "An invalid operation occurred."; - inline static const std::string BAD_XNB = "Bad xnb file"; - inline static const std::string OUT_OF_BOUNDS = "Out of bounds."; - inline static const std::string END_OF_FILE = "End of file."; - }; -} - -#endif \ No newline at end of file diff --git a/includes/xna/framework.hpp b/includes/xna/framework.hpp index eacb4d0..1458237 100644 --- a/includes/xna/framework.hpp +++ b/includes/xna/framework.hpp @@ -25,7 +25,7 @@ #include "csharp/type.hpp" #include "csharp/screen.hpp" #include "csharp/eventhandler.hpp" -#include "exception.hpp" +#include "csharp/exception.hpp" #include "game/component.hpp" #include "game/game.hpp" #include "game/gdeviceinfo.hpp" diff --git a/sources/framework-dx/adapter.cpp b/sources/framework-dx/adapter.cpp index 630ec8d..56b76ba 100644 --- a/sources/framework-dx/adapter.cpp +++ b/sources/framework-dx/adapter.cpp @@ -15,7 +15,7 @@ namespace xna { comptr pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)pFactory.GetAddressOf())) - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); comptr pAdapter = nullptr; @@ -55,7 +55,7 @@ namespace xna { comptr pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)pFactory.GetAddressOf())) - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); comptr pAdapter = nullptr; diff --git a/sources/framework-dx/blendstate.cpp b/sources/framework-dx/blendstate.cpp index 5f2d2c5..bcb9007 100644 --- a/sources/framework-dx/blendstate.cpp +++ b/sources/framework-dx/blendstate.cpp @@ -98,7 +98,7 @@ namespace xna { bool BlendState::Initialize() { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } if (Implementation->BlendState) { @@ -110,7 +110,7 @@ namespace xna { Implementation->BlendState.GetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } return true; @@ -118,7 +118,7 @@ namespace xna { bool BlendState::Apply() { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::FAILED_TO_APPLY); + throw csharp::InvalidOperationException(); } if (!Implementation->BlendState) { diff --git a/sources/framework-dx/depthstencilstate.cpp b/sources/framework-dx/depthstencilstate.cpp index d4667b5..4c32d8d 100644 --- a/sources/framework-dx/depthstencilstate.cpp +++ b/sources/framework-dx/depthstencilstate.cpp @@ -38,7 +38,7 @@ namespace xna { bool DepthStencilState::Initialize() { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } if (Implementation->DepthStencil) { @@ -50,7 +50,7 @@ namespace xna { Implementation->DepthStencil.GetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } return true; @@ -59,7 +59,7 @@ namespace xna { bool DepthStencilState::Apply() { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } if (!Implementation->DepthStencil) { diff --git a/sources/framework-dx/device.cpp b/sources/framework-dx/device.cpp index 865b063..39345ef 100644 --- a/sources/framework-dx/device.cpp +++ b/sources/framework-dx/device.cpp @@ -49,7 +49,7 @@ namespace xna { Context.GetAddressOf()); if FAILED(hr) - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } void GraphicsDeviceImplementation::Reset() { @@ -113,13 +113,13 @@ namespace xna { auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&Implementation->Factory); if FAILED(hr) - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); auto hwnd = reinterpret_cast(presentationParameters->DeviceWindowHandle); hr = Implementation->Factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); if (FAILED(hr)) - Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION); + throw csharp::InvalidOperationException(); // // Viewport @@ -211,10 +211,10 @@ namespace xna { switch (options) { case xna::ClearOptions::DepthBuffer: - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); break; case xna::ClearOptions::Stencil: - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); break; case xna::ClearOptions::Target: Clear(color); diff --git a/sources/framework-dx/effect.cpp b/sources/framework-dx/effect.cpp index 4657aa2..97b2fc1 100644 --- a/sources/framework-dx/effect.cpp +++ b/sources/framework-dx/effect.cpp @@ -100,7 +100,7 @@ namespace xna { void BasicEffect::Texture(sptr const& value) { if (!value || !value->Implementation || !value->Implementation->ShaderResource) - Exception::Throw(Exception::ARGUMENT_IS_NULL); + throw csharp::InvalidOperationException(); impl->dxBasicEffect->SetTexture(value->Implementation->ShaderResource.Get()); } diff --git a/sources/framework-dx/game.cpp b/sources/framework-dx/game.cpp index 80295bf..317fb85 100644 --- a/sources/framework-dx/game.cpp +++ b/sources/framework-dx/game.cpp @@ -70,7 +70,7 @@ namespace xna { try { if (!gameWindow->impl->Create()) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); return false; } @@ -85,8 +85,9 @@ namespace xna { BeginRun(); return StartGameLoop(); } - catch (std::exception& e) { + catch (std::exception& e) { MessageBox(nullptr, e.what(), "XN65", MB_OK); + return EXIT_FAILURE; } } diff --git a/sources/framework-dx/gdevicemanager.cpp b/sources/framework-dx/gdevicemanager.cpp index 32573ce..56c327c 100644 --- a/sources/framework-dx/gdevicemanager.cpp +++ b/sources/framework-dx/gdevicemanager.cpp @@ -46,7 +46,7 @@ namespace xna { void GraphicsDeviceManager::ChangeDevice(bool forceCreate) { if (!game) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); inDeviceTransition = true; auto screenDeviceName = game->Window()->ScreenDeviceName(); @@ -208,13 +208,13 @@ namespace xna { } if (foundDevices.size() == 0) { - Exception::Throw("No Suitable Graphics Device"); + throw csharp::InvalidOperationException("No Suitable Graphics Device"); } RankDevices(foundDevices); if (foundDevices.size() == 0) - Exception::Throw("No Suitable Graphics Device"); + throw csharp::InvalidOperationException("No Suitable Graphics Device"); return foundDevices[0]; } @@ -323,7 +323,7 @@ namespace xna { if (hWnd == 0) { if (!game) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); hWnd = game->Window()->Handle(); } @@ -345,7 +345,7 @@ namespace xna { return; if (presentationParameters->BackBufferWidth == 0 || presentationParameters->BackBufferHeight == 0) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); bool flag = true; @@ -369,7 +369,7 @@ namespace xna { } } if (!flag) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } bool IsWindowOnAdapter(intptr_t windowHandle, GraphicsAdapter const& adapter) { diff --git a/sources/framework-dx/rasterizerstate.cpp b/sources/framework-dx/rasterizerstate.cpp index 26a05b8..9313c68 100644 --- a/sources/framework-dx/rasterizerstate.cpp +++ b/sources/framework-dx/rasterizerstate.cpp @@ -18,7 +18,7 @@ namespace xna { bool RasterizerState::Initialize() { if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } if (Implementation->RasterizerState) { @@ -30,7 +30,7 @@ namespace xna { Implementation->RasterizerState.GetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } return true; @@ -39,11 +39,11 @@ namespace xna { bool RasterizerState::Apply() { if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } if (!Implementation->RasterizerState) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } BaseGraphicsDevice->Implementation->Context->RSSetState(Implementation->RasterizerState.Get()); diff --git a/sources/framework-dx/rendertarget.cpp b/sources/framework-dx/rendertarget.cpp index b4d5fc2..fe5fbd5 100644 --- a/sources/framework-dx/rendertarget.cpp +++ b/sources/framework-dx/rendertarget.cpp @@ -17,7 +17,7 @@ namespace xna { if (!swapChain->impl->GetBackBuffer(implementation->Texture2D)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } rt->Initialize(); @@ -27,7 +27,7 @@ namespace xna { void RenderTarget2D::Initialize() { if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } if (Implementation2->RenderTargetView) @@ -47,7 +47,7 @@ namespace xna { Implementation2->RenderTargetView.ReleaseAndGetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } Implementation2->RenderTargetView->GetDesc(&Implementation2->Description); diff --git a/sources/framework-dx/samplerstate.cpp b/sources/framework-dx/samplerstate.cpp index c90fbd3..ed9d3b3 100644 --- a/sources/framework-dx/samplerstate.cpp +++ b/sources/framework-dx/samplerstate.cpp @@ -12,7 +12,7 @@ namespace xna { bool SamplerState::Initialize() { if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } if (Implementation->SamplerState) { @@ -24,7 +24,7 @@ namespace xna { Implementation->SamplerState.GetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } return true; @@ -33,11 +33,11 @@ namespace xna { bool SamplerState::Apply() { if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } if (!Implementation->SamplerState) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } BaseGraphicsDevice->Implementation->Context->PSSetSamplers(0, 1, Implementation->SamplerState.GetAddressOf()); @@ -50,7 +50,7 @@ namespace xna { return; if (!device.Implementation || !device.Implementation->Device || !device.Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } std::vector states(samplers.size()); @@ -59,7 +59,7 @@ namespace xna { const auto& current = samplers[0]; if (!current || !current->Implementation || !current->Implementation->SamplerState) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); states[i] = current->Implementation->SamplerState.Get(); states[i]->AddRef(); diff --git a/sources/framework-dx/sprite.cpp b/sources/framework-dx/sprite.cpp index 1a0ac1d..b5dd9ed 100644 --- a/sources/framework-dx/sprite.cpp +++ b/sources/framework-dx/sprite.cpp @@ -22,11 +22,11 @@ namespace xna { std::vector const& kerning, std::optional const& defaultCharacter) { - Exception::ThrowIfNull(texture, nameof(texture)); - Exception::ThrowIfNull(texture->Implementation->ShaderResource.Get(), nameof(texture->Implementation->ShaderResource)); + if (!texture || !texture->Implementation->ShaderResource.Get()) + throw csharp::ArgumentNullException(); if(cropping.size() != glyphs.size() || charMap.size() != glyphs.size() || (!kerning.empty() && kerning.size() != glyphs.size())) - Exception::Throw("Cropping, charmap and kerning (if not empty) must all be the same size."); + throw csharp::InvalidOperationException("Cropping, charmap and kerning (if not empty) must all be the same size."); std::vector dxGlyps(glyphs.size()); @@ -108,8 +108,8 @@ namespace xna { } SpriteBatch::SpriteBatch(sptr const& device) : GraphicsResource(device) { - Exception::ThrowIfNull(device, nameof(device)); - Exception::ThrowIfNull(device->Implementation->Context.Get(), nameof(device->Implementation->Context)); + if (!device || !device->Implementation->Context.Get()) + throw csharp::ArgumentNullException("device"); Implementation = unew(); Implementation->SpriteBatch = snew( diff --git a/sources/framework-dx/swapchain.cpp b/sources/framework-dx/swapchain.cpp index e3d366a..92236bc 100644 --- a/sources/framework-dx/swapchain.cpp +++ b/sources/framework-dx/swapchain.cpp @@ -45,7 +45,7 @@ namespace xna { bool SwapChain::Initialize() { if (!impl || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } const auto parameters = BaseGraphicsDevice->PresentParameters(); diff --git a/sources/framework-dx/texture.cpp b/sources/framework-dx/texture.cpp index 7fde8d3..28123c1 100644 --- a/sources/framework-dx/texture.cpp +++ b/sources/framework-dx/texture.cpp @@ -58,7 +58,7 @@ namespace xna { void Texture2D::Initialize() { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) { - Exception::Throw(Exception::UNABLE_TO_INITIALIZE); + throw csharp::InvalidOperationException(); } auto& deviceImpl = BaseGraphicsDevice->Implementation; @@ -72,7 +72,7 @@ namespace xna { Implementation->Texture2D.ReleaseAndGetAddressOf()); if FAILED(hr) - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } else { //Updates description if texture is not null @@ -83,7 +83,7 @@ namespace xna { hr = Implementation->Texture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf()); if FAILED(hr) - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); //Only initializes if it is a ShaderResource if (Implementation->Description.BindFlags & D3D11_BIND_SHADER_RESOURCE) { @@ -93,7 +93,7 @@ namespace xna { Implementation->ShaderResource.ReleaseAndGetAddressOf()); if FAILED(hr) - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } @@ -106,19 +106,19 @@ namespace xna { void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } auto hr = Implementation->SetData(*BaseGraphicsDevice, data.data()); if (FAILED(hr)) - Exception::Throw(Exception::FAILED_TO_APPLY); + throw csharp::InvalidOperationException(); } void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } std::vector finalData(elementCount / 4); @@ -136,13 +136,13 @@ namespace xna { auto hr = Implementation->SetData(*BaseGraphicsDevice, finalData.data()); if (FAILED(hr)) - Exception::Throw(Exception::FAILED_TO_APPLY); + throw csharp::InvalidOperationException(); } void Texture2D::SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount) { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } std::vector finalData(elementCount / 4); @@ -161,7 +161,7 @@ namespace xna { auto hr = BaseGraphicsDevice->Implementation->Device->CreateTexture2D(&Implementation->Description, nullptr, Implementation->Texture2D.GetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } } @@ -169,7 +169,7 @@ namespace xna { auto hr = Implementation->Texture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } D3D11_BOX box{}; @@ -191,7 +191,7 @@ namespace xna { hr = BaseGraphicsDevice->Implementation->Device->CreateShaderResourceView(resource.Get(), &Implementation->ShaderDescription, Implementation->ShaderResource.ReleaseAndGetAddressOf()); if (FAILED(hr)) { - Exception::Throw(Exception::FAILED_TO_CREATE); + throw csharp::InvalidOperationException(); } Implementation->Texture2D->GetDesc(&Implementation->Description); @@ -200,7 +200,7 @@ namespace xna { void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device || !BaseGraphicsDevice->Implementation->Context) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } std::vector finalData(elementCount); @@ -214,7 +214,7 @@ namespace xna { auto hr = Implementation->SetData(*BaseGraphicsDevice, finalData.data()); if (FAILED(hr)) - Exception::Throw(Exception::FAILED_TO_APPLY); + throw csharp::InvalidOperationException(); } P_Texture2D Texture2D::FromStream(GraphicsDevice& device, P_Stream const& stream) diff --git a/sources/framework/CMakeLists.txt b/sources/framework/CMakeLists.txt index b6b5d83..6778e87 100644 --- a/sources/framework/CMakeLists.txt +++ b/sources/framework/CMakeLists.txt @@ -18,7 +18,7 @@ add_library (Xn65 STATIC "common/numerics.cpp" "common/packedvalue.cpp" "graphics/displaymode.cpp" -"exception.cpp") +) if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20) @@ -26,4 +26,4 @@ endif() #find_package(tinyxml2 CONFIG REQUIRED) -target_link_libraries(Xn65 "${PROJECT_VCPKG_DIRECTORY}/installed/x64-windows/lib/tinyxml2.lib") +target_link_libraries(Xn65 CSharp++ "${PROJECT_VCPKG_DIRECTORY}/installed/x64-windows/lib/tinyxml2.lib") diff --git a/sources/framework/csharp/binary.cpp b/sources/framework/csharp/binary.cpp index dba28e0..7b936e9 100644 --- a/sources/framework/csharp/binary.cpp +++ b/sources/framework/csharp/binary.cpp @@ -3,7 +3,8 @@ namespace xna { BinaryReader::BinaryReader(sptr const& input) { - Exception::ThrowIfNull(input, nameof(input)); + if(!input) + throw csharp::ArgumentNullException("input"); stream = input; buffer = std::vector(bufferLength); @@ -263,7 +264,7 @@ namespace xna { void BinaryReader::FillBuffer(Int numBytes) { if (numBytes < 0 || numBytes > buffer.size()) { - Exception::Throw(Exception::OUT_OF_BOUNDS); + throw csharp::InvalidOperationException(); } Int bytesRead = 0; @@ -273,7 +274,7 @@ namespace xna { n = stream->ReadByte(); if (n == -1){ - Exception::Throw(Exception::END_OF_FILE); + throw csharp::InvalidOperationException(); } buffer[0] = static_cast(n); @@ -284,7 +285,7 @@ namespace xna { n = stream->Read(buffer, bytesRead, numBytes - bytesRead); if (n == 0) { - Exception::Throw(Exception::END_OF_FILE); + throw csharp::InvalidOperationException(); } bytesRead += n; @@ -440,7 +441,7 @@ namespace xna { //Binary Writer BinaryWriter::BinaryWriter(sptr const& stream) { - Exception::ThrowIfNull(stream, nameof(stream)); + throw csharp::ArgumentNullException("stream"); OutStream = stream; _buffer = std::vector(16); diff --git a/sources/framework/csharp/stream.cpp b/sources/framework/csharp/stream.cpp index 4f35821..401aae9 100644 --- a/sources/framework/csharp/stream.cpp +++ b/sources/framework/csharp/stream.cpp @@ -1,6 +1,6 @@ #include "xna/csharp/stream.hpp" #include "xna/csharp/buffer.hpp" -#include "xna/exception.hpp" +#include "csharp/exception.hpp" #include namespace xna { @@ -88,7 +88,7 @@ namespace xna { auto i = _position + count; if (i < 0 || i > _length) { - Exception::Throw("i < 0 || i > _length"); + throw csharp::InvalidOperationException("i < 0 || i > _length"); } if (count <= 8) { @@ -129,7 +129,7 @@ namespace xna { //Especifica se deve abrir um arquivo existente. case FileMode::Open: if (!exists) - Exception::Throw("The specified file does not exist."); + throw csharp::InvalidOperationException("The specified file does not exist."); break; //Especifica que se deve abrir um arquivo, se existir; // caso contrário, um novo arquivo deverá ser criado. @@ -144,7 +144,7 @@ namespace xna { if (!exists) flags |= std::fstream::trunc; else - Exception::Throw("The specified file already exists."); + throw csharp::InvalidOperationException("The specified file already exists."); break; //Abre o arquivo, se existir, e busca o final do arquivo ou cria um novo arquivo. case FileMode::Append: @@ -159,7 +159,7 @@ namespace xna { //Tentativa de ler um arquivo truncado retornará 0; case FileMode::Truncate: if(!exists) - Exception::Throw("The specified file does not exist."); + throw csharp::InvalidOperationException("The specified file does not exist."); flags |= std::fstream::trunc; _truncated = true; @@ -171,7 +171,7 @@ namespace xna { _fstream.open(path.c_str(), flags); if (!_fstream.good()) - Exception::Throw("Failed to open file: " + path); + throw csharp::InvalidOperationException("Failed to open file: " + path); } FileStream::FileStream(std::string const& path) { @@ -187,7 +187,7 @@ namespace xna { _fstream.open(path.c_str(), flags); if (!_fstream.good()) - Exception::Throw("Failed to open file: " + path); + throw csharp::InvalidOperationException("Failed to open file: " + path); } int64_t FileStream::Length() { diff --git a/sources/framework/exception.cpp b/sources/framework/exception.cpp deleted file mode 100644 index 9fca374..0000000 --- a/sources/framework/exception.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "xna/exception.hpp" - -namespace xna { - void Exception::Throw(std::string const& message, std::source_location const& location) { - std::string error; - - error.append("Exception in: "); -#if _DEBUG - error.append(location.file_name()); - error.append("("); - error.append(std::to_string(location.line())); - error.append(":"); - error.append(std::to_string(location.column())); - error.append(") "); -#endif - error.append("': "); - error.append(location.function_name()); - error.append("': "); - error.append(message); - error.append("\n"); - - throw std::runtime_error(error); - } - - void Exception::ThrowIfNull(void const* argument, std::string const& argumentName, std::source_location const& location) { - if (argument) - return; - - std::string error; - - error.append("The value of "); - error.append(argumentName); - error.append(" is null."); - - Throw(error); - } -} \ No newline at end of file diff --git a/sources/pipeline/graphics.cpp b/sources/pipeline/graphics.cpp index 52892f2..7daf993 100644 --- a/sources/pipeline/graphics.cpp +++ b/sources/pipeline/graphics.cpp @@ -26,7 +26,7 @@ namespace xna { if (!sourceBitmap.TryCopyTo(*bitmapContent2, rectangle2, rectangle2) || !destinationBitmap.TryCopyTo(*bitmapContent3, rectangle3, rectangle3) || !bitmapContent3->TryCopyFrom(*bitmapContent2, sourceRegion, destinationRegion) || !destinationBitmap.TryCopyFrom(*bitmapContent3, rectangle3, rectangle3)) { - Exception::Throw(Exception::INVALID_OPERATION); + throw csharp::InvalidOperationException(); } } @@ -73,9 +73,9 @@ namespace xna { BitmapContent const& destinationBitmap, Rectangle const& destinationRegion) { if (sourceRegion.Left() < 0 || sourceRegion.Top() < 0 || sourceRegion.Width < 0 || sourceRegion.Height < 0 || sourceRegion.Right() > sourceBitmap.Width() || sourceRegion.Bottom() > sourceBitmap.Height()) - Exception::Throw(Exception::OUT_OF_BOUNDS); + throw csharp::InvalidOperationException(); if (destinationRegion.Left() < 0 || destinationRegion.Top() < 0 || destinationRegion.Width < 0 || destinationRegion.Height < 0 || destinationRegion.Right() > destinationBitmap.Width() || destinationRegion.Bottom() > destinationBitmap.Height()) - Exception::Throw(Exception::OUT_OF_BOUNDS); + throw csharp::InvalidOperationException(); } } \ No newline at end of file diff --git a/sources/pipeline/writer.cpp b/sources/pipeline/writer.cpp index 1c52a5b..6619d16 100644 --- a/sources/pipeline/writer.cpp +++ b/sources/pipeline/writer.cpp @@ -88,7 +88,7 @@ namespace xna { if (targetPlatform == TargetPlatform::Windows) Write((Byte)119); else - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); if (compressContent) WriteCompressedOutput(); @@ -109,7 +109,7 @@ namespace xna { } void ContentWriter::WriteCompressedOutput() { - Exception::Throw(Exception::NOT_IMPLEMENTED); + throw csharp::InvalidOperationException(); } void ContentWriter::WriteVersionNumber(Ushort version) {