1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Adiciona pasta csharp e exception.hpp

This commit is contained in:
Danilo Borges Santos 2024-12-02 15:07:37 -03:00
parent e7e0781da5
commit 7b435a37c4
6 changed files with 433 additions and 23 deletions

View File

@ -0,0 +1,342 @@
#ifndef CSHARP_EXCEPTION_HPP
#define CSHARP_EXCEPTION_HPP
#include <stdexcept>
#include <string>
#include <source_location>
#include <memory>
#include "sr.hpp"
namespace csharp {
struct HResults {
inline static constexpr size_t S_OK = 0x00000000;
inline static constexpr size_t 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;
};
class Exception : public std::runtime_error {
public:
Exception(std::source_location const& source = std::source_location::current())
: Source(source), std::runtime_error("") {};
Exception(std::string const& message, std::source_location source = std::source_location::current())
: Source(source), message(message), std::runtime_error(message) {}
Exception(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: Source(source), message(message), innerException(innerException), std::runtime_error(message) {}
constexpr virtual std::string Message() const { return message; }
const std::shared_ptr<Exception>& InnerException() const { return innerException; }
// Retrieves the lowest exception (inner most) for the given Exception.
// This will traverse exceptions using the innerException property.
virtual Exception& GetBaseException();
public:
std::string HelpLink;
std::source_location Source;
size_t HRresult{ HResults::COR_E_EXCEPTION };
private:
std::string message;
std::shared_ptr<Exception> innerException;
};
//The exception that is thrown when one of the arguments provided to a method is not valid.
class ArgumentException : public Exception {
public:
ArgumentException(std::source_location const& source = std::source_location::current()): Exception(SR::Arg_ArgumentException, source)
{
HRresult = HResults::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;
};
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;
};
ArgumentException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: Exception(!message.empty() ? message : SR::Arg_ArgumentException, innerException, source)
{
HRresult = HResults::COR_E_ARGUMENT;
}
ArgumentException(std::string const& message, std::string const& paramName, std::shared_ptr<Exception>& 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;
}
constexpr std::string Message() const override {
return Exception::Message().append(" Parameter: " + paramName + ".");
}
private:
std::string paramName;
};
//The exception that is thrown when one of the arguments provided to a method is null.
class ArgumentNullException : public ArgumentException {
public:
ArgumentNullException(std::source_location const& source = std::source_location::current()) : ArgumentException(SR::ArgumentNull_Generic, source)
{
HRresult = HResults::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;
};
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;
};
ArgumentNullException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: ArgumentException(!message.empty() ? message : SR::ArgumentNull_Generic, innerException, source)
{
HRresult = HResults::E_POINTER;
}
ArgumentNullException(std::string const& message, std::string const& paramName, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: ArgumentException(!message.empty() ? message : SR::ArgumentNull_Generic, paramName, innerException, source)
{
HRresult = HResults::E_POINTER;
}
};
//The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method.
class ArgumentOutOfRangeException : public ArgumentException {
public:
ArgumentOutOfRangeException(std::source_location const& source = std::source_location::current()) : ArgumentException(SR::Arg_ArgumentOutOfRangeException, source)
{
HRresult = HResults::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;
};
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;
};
ArgumentOutOfRangeException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: ArgumentException(!message.empty() ? message : SR::Arg_ArgumentOutOfRangeException, innerException, source)
{
HRresult = HResults::E_POINTER;
}
ArgumentOutOfRangeException(std::string const& message, std::string const& paramName, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: ArgumentException(!message.empty() ? message : SR::Arg_ArgumentOutOfRangeException, paramName, innerException, source)
{
HRresult = HResults::E_POINTER;
}
};
class SystemException : public Exception {
public:
SystemException(std::source_location const& source = std::source_location::current()) : Exception(SR::Arg_SystemException, source)
{
HRresult = HResults::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;
}
SystemException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: Exception(!message.empty() ? message : SR::Arg_ArgumentException, innerException, source)
{
HRresult = HResults::COR_E_SYSTEM;
}
};
//The exception that is thrown when a method call is invalid for the object's current state.
class InvalidOperationException : public SystemException {
public:
InvalidOperationException(std::source_location const& source = std::source_location::current())
: SystemException(SR::Arg_SystemException, source)
{
HRresult = HResults::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;
}
InvalidOperationException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: SystemException(!message.empty() ? message : SR::Arg_InvalidOperationException, innerException, source)
{
HRresult = HResults::COR_E_INVALIDOPERATION;
}
};
//The exception that is thrown when an invoked method is not supported,
//typically because it should have been implemented on a subclass.
class NotSupportedException : public SystemException {
public:
NotSupportedException(std::source_location const& source = std::source_location::current())
: SystemException(SR::Arg_NotSupportedException, source)
{
HRresult = HResults::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;
}
NotSupportedException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: SystemException(!message.empty() ? message : SR::Arg_NotSupportedException, innerException, source)
{
HRresult = HResults::COR_E_INVALIDOPERATION;
}
};
//The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.
class UnauthorizedAccessException : public SystemException {
public:
UnauthorizedAccessException(std::source_location const& source = std::source_location::current())
: SystemException(SR::Arg_UnauthorizedAccessException, source)
{
HRresult = HResults::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;
}
UnauthorizedAccessException(std::string const& message, std::shared_ptr<Exception>& innerException, std::source_location const& source = std::source_location::current())
: SystemException(!message.empty() ? message : SR::Arg_UnauthorizedAccessException, innerException, source)
{
HRresult = HResults::COR_E_UNAUTHORIZEDACCESS;
}
};
}
#endif

57
includes/csharp/sr.hpp Normal file
View File

@ -0,0 +1,57 @@
#ifndef CSHARP_STRING_RESOURCE_HPP
#define CSHARP_STRING_RESOURCE_HPP
#include <string>
namespace csharp {
struct SR {
inline static const std::string Arg_ArgumentException
= "Value does not fall within the expected range.";
inline static const std::string ArgumentNull_Generic
= "Value cannot be null.";
inline static const std::string Arg_ArgumentOutOfRangeException
= "Specified argument was out of the range of valid values.";
inline static const std::string Arg_SystemException
= "System error.";
inline static const std::string Arg_InvalidOperationException
= "Operation is not valid due to the current state of the object.";
inline static const std::string InvalidOperation_TimeoutsNotSupported
= "Timeouts are not supported on this stream.";
inline static const std::string Arg_NotSupportedException
= "Specified method is not supported.";
inline static const std::string NotSupported_UnreadableStream
= "Stream does not support reading.";
inline static const std::string ObjectDisposed_StreamClosed
= "Cannot access a closed Stream.";
inline static const std::string Arg_IOException
= "I/O error occurred.";
inline static const std::string Arg_EndOfStreamException
= "Attempted to read past the end of the stream.";
inline static const std::string IO_EOF_ReadBeyondEOF
= "Unable to read beyond the end of the stream.";
inline static const std::string IO_StreamTooLong
= "Stream was too long.";
inline static const std::string Argument_InvalidOffLen
= "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.";
inline static const std::string NotSupported_UnwritableStream
= "Stream does not support writing.";
inline static const std::string Arg_UnauthorizedAccessException
= "Attempted to perform an unauthorized operation.";
inline static const std::string UnauthorizedAccess_MemStreamBuffer
= "MemoryStream's internal buffer cannot be accessed.";
inline static const std::string ArgumentOutOfRange_SmallCapacity
= "Capacity was less than the current size.";
inline static const std::string NotSupported_MemStreamNotExpandable
= "Memory stream is not expandable.";
inline static const std::string Argument_InvalidSeekOrigin
= "Invalid seek origin.";
inline static const std::string IO_SeekBeforeBegin
= "An attempt was made to move the position before the beginning of the stream.";
inline static const std::string ArgumentOutOfRange_StreamLength
= "Stream length must be non-negative and less than 2^31 - 1 - origin.";
inline static const std::string net_uri_NotAbsolute
= "This operation is not supported for a relative URI.";
};
};
#endif

View File

@ -1,23 +0,0 @@
#ifndef XNA_FORWARD_HPP
#define XNA_FORWARD_HPP
#include <memory>
struct RationalNumber;
struct Point;
struct Vector2;
struct Vector3;
struct Vector4;
struct Matrix;
struct Quaternion;
using P_RationalNumber = std::shared_ptr<RationalNumber>;
using P_Pointer = std::shared_ptr<Point>;
using P_Vector2 = std::shared_ptr<Vector2>;
using P_Vector3 = std::shared_ptr<Vector3>;
using P_Vector4 = std::shared_ptr<Vector4>;
using P_Quaternion = std::shared_ptr<Quaternion>;
#endif

View File

@ -1,3 +1,4 @@
add_subdirectory ("framework")
add_subdirectory ("framework-dx")
add_subdirectory ("csharp")
#add_subdirectory ("pipeline")

View File

@ -0,0 +1,16 @@
# CMakeList.txt : CMake project for xna, include source and define
# project specific logic here.
#
# Add source to this project's executable.
add_library (CSharp++ STATIC
"exception.cpp"
)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET CSharp++ PROPERTY CXX_STANDARD 20)
endif()
#find_package(tinyxml2 CONFIG REQUIRED)
target_link_libraries(CSharp++ "${PROJECT_VCPKG_DIRECTORY}/installed/x64-windows/lib/tinyxml2.lib")

View File

@ -0,0 +1,17 @@
#include "csharp/exception.hpp"
namespace csharp {
Exception& Exception::GetBaseException() {
auto inner = innerException.get();
auto back = this;
while (inner != nullptr) {
back = inner;
inner = inner->innerException.get();
}
return *back;
}
}