diff --git a/Include/Aurora/Locale/Encoding/Encoding.hpp b/Include/Aurora/Locale/Encoding/Encoding.hpp index d4f1e693..129ce6f1 100644 --- a/Include/Aurora/Locale/Encoding/Encoding.hpp +++ b/Include/Aurora/Locale/Encoding/Encoding.hpp @@ -9,17 +9,17 @@ namespace Aurora::Locale::Encoding { - AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const void *utf8, AuUInt32 ut8Length, void *binary, AuUInt32 binaryLength, ECodePage page = ECodePage::eUnsupported); - static inline AuStreamReadWrittenPair_t EncodeUTF8(const AuString &out, void *binary, AuUInt32 binaryLength, ECodePage page = ECodePage::eUnsupported) + AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(Aurora::Memory::MemoryViewRead utf8, Aurora::Memory::MemoryViewWrite binary, ECodePage page = ECodePage::eUnsupported); + static inline AuStreamReadWrittenPair_t EncodeUTF8(const AuString &utf8, Aurora::Memory::MemoryViewWrite binary, ECodePage page = ECodePage::eUnsupported) { - return EncodeUTF8(out.data(), static_cast(out.size()), binary, binaryLength, page); + return EncodeUTF8(Aurora::Memory::MemoryViewRead(utf8), binary, page); } - AUKN_SYM std::optional> DecodeBOM(const void *binary, AuUInt32 binaryLength); + AUKN_SYM std::optional> DecodeBOM(Aurora::Memory::MemoryViewRead binary); /// Translates a buffer, possibly a slice of a stream, to UTF-8 /// Returns a pair; bytes consumed, bytes written - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utf8Max, ECodePage page = ECodePage::eUnsupported); + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, Aurora::Memory::MemoryViewWrite utf8, ECodePage page = ECodePage::eUnsupported); - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page = ECodePage::eUnsupported); + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, AuString &out, ECodePage page = ECodePage::eUnsupported); } \ No newline at end of file diff --git a/Include/Aurora/Memory/MemoryView.hpp b/Include/Aurora/Memory/MemoryView.hpp index 96b9b231..096f5cd0 100644 --- a/Include/Aurora/Memory/MemoryView.hpp +++ b/Include/Aurora/Memory/MemoryView.hpp @@ -13,14 +13,45 @@ namespace Aurora::Memory struct MemoryView { using Void_t = std::conditional_t; + + /* + YadaYada(MemoryView(tempstring/array/etc)) should be legal, right? + + --------------------- + Temporary objects are destroyed as the last step in evaluating the full-expression that (lexically) contains the point where they were created. + --------------------- + A full-expression is: + [...] + * an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression. + --------------------- + */ - template - constexpr MemoryView(const AuList &list) + MemoryView() + { + this->ptr = nullptr; + this->length = 0; + } + + template::value>::type* = nullptr> + MemoryView(T &list) { this->ptr = list.data(); this->length = list.size() * sizeof(T); } + MemoryView(const AuString &str) + { + this->ptr = str.data(); + this->length = str.size(); + } + + template + constexpr MemoryView(T(&a)[Z]) + { + this->ptr = &a[0]; + this->length = Z * sizeof(T); + } + template constexpr MemoryView(T *start, T *end) { @@ -42,12 +73,6 @@ namespace Aurora::Memory this->length = length; } - MemoryView() - { - this->ptr = nullptr; - this->length = 0; - } - AuUInt ToPointer() { return reinterpret_cast(ptr); @@ -86,12 +111,17 @@ namespace Aurora::Memory template struct MemoryViewStream : MemoryView { - template - constexpr MemoryViewStream(const AuList &list, AuUInt &length) : MemoryView(list), outVariable(length) + template::value>::type* = nullptr> + constexpr MemoryViewStream(T &list, AuUInt &length) : MemoryView(list), outVariable(length) { outVariable = 0; } - + + constexpr MemoryViewStream(const AuString &str, AuUInt &length) : MemoryView(str), outVariable(length) + { + outVariable = 0; + } + template constexpr MemoryViewStream(T *start, T *end, AuUInt &length) : MemoryView(start, end), outVariable(length) { @@ -104,7 +134,31 @@ namespace Aurora::Memory outVariable = 0; } + template::value>::type* = nullptr> + constexpr MemoryViewStream(T &list) : MemoryView(list), outVariable(unused) + { + outVariable = 0; + } + + constexpr MemoryViewStream(const AuString &str) : MemoryView(str), outVariable(unused) + { + outVariable = 0; + } + + template + constexpr MemoryViewStream(T *start, T *end) : MemoryView(start, end), outVariable(unused) + { + outVariable = 0; + } + + template + constexpr MemoryViewStream(T(&a)[Z]) : MemoryView(a), outVariable(unused) + { + outVariable = 0; + } + AuUInt &outVariable; + AuUInt unused; }; using MemoryViewStreamRead = MemoryViewStream; diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index e7cfd116..22e8c864 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -25,6 +25,7 @@ #include #include "../AuroraTypedefs.hpp" +#include "../AuroraUtils.hpp" #if defined(_AUHAS_FMT) #include @@ -62,7 +63,6 @@ #include "Time/Time.hpp" #include "Loop/Loop.hpp" -#include "../AuroraUtils.hpp" namespace Aurora { diff --git a/Include/AuroraUtils.hpp b/Include/AuroraUtils.hpp index ef60033b..b2ee0a44 100644 --- a/Include/AuroraUtils.hpp +++ b/Include/AuroraUtils.hpp @@ -34,7 +34,7 @@ static inline auto AuMakePair(Args... args) return AURORA_RUNTIME_MAKE_PAIR(args...); } -#if defined(AURORA_PLATFORM_WIN32) +#if defined(AURORA_IS_MODERNNT_DERIVED) && defined(_WINDOWS_) static inline void AuWin32CloseHandle(HANDLE &handle) { HANDLE local; @@ -60,6 +60,9 @@ static constexpr int AuArraySize(const T(&array)[Z]) #if defined(DEBUG) || defined(STAGING) +template +static inline void __declspec(noreturn) SysPanic(T... args); + template static void inline SafeDelete(T *in) { @@ -419,6 +422,11 @@ static inline bool AuTryInsertNoEnd(Container *container, const Type &value) // } } +namespace Aurora::Memory +{ + struct ByteBuffer; +} + template static inline bool AuTryResize(T &list, AuUInt length) { diff --git a/Source/Compression/BlockDecompressor.cpp b/Source/Compression/BlockDecompressor.cpp index 16a69ca5..d01f0a7d 100644 --- a/Source/Compression/BlockDecompressor.cpp +++ b/Source/Compression/BlockDecompressor.cpp @@ -137,8 +137,8 @@ namespace Aurora::Compression while (read != input) { - AuUInt32 request = std::min(input, length); - if (this->reader_->Read(din_, request) != IO::EStreamError::eErrorNone) + AuUInt request = std::min(input, length); + if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone) { return AuMakePair(read, done); } @@ -218,8 +218,8 @@ namespace Aurora::Compression while (read < input) { - AuUInt32 request = std::min(input, AuUInt32(AuArraySize(din_))); - if (this->reader_->Read(din_, request) != IO::EStreamError::eErrorNone) + AuUInt request = std::min(input, AuUInt32(AuArraySize(din_))); + if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone) { return AuMakePair(read, done); } @@ -308,8 +308,8 @@ namespace Aurora::Compression AuUInt32 done{}, read{}; while (read < input) { - AuUInt32 request = std::min(input, AuUInt32(AuArraySize(din_))); - if (this->reader_->Read(din_, request) != IO::EStreamError::eErrorNone) + AuUInt request = std::min(input, AuUInt32(AuArraySize(din_))); + if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone) { return AuMakePair(read, done); } @@ -412,9 +412,9 @@ namespace Aurora::Compression if (frameSize) { - AuUInt32 request = frameSize; + AuUInt request = frameSize; if ((input < (inputStat + request)) || - (this->reader_->Read(bufferIn.get(), request) != IO::EStreamError::eErrorNone) || + (this->reader_->Read(Memory::MemoryViewStreamWrite(bufferIn.get(), request)) != IO::EStreamError::eErrorNone) || (request != frameSize)) { ret = request == 0 && inputStat; diff --git a/Source/Console/ConsoleFIO/ConsoleFIO.cpp b/Source/Console/ConsoleFIO/ConsoleFIO.cpp index af48eb0c..e688f09c 100644 --- a/Source/Console/ConsoleFIO/ConsoleFIO.cpp +++ b/Source/Console/ConsoleFIO/ConsoleFIO.cpp @@ -104,7 +104,8 @@ namespace Aurora::Console::ConsoleFIO if (gFileHandle) { - gFileHandle->Write(gLogBuffer.data(), gLogBuffer.size()); + AuUInt idc; + gFileHandle->Write(Aurora::Memory::MemoryViewStreamRead(gLogBuffer)); } gLogBuffer.clear(); diff --git a/Source/IO/FS/FS.cpp b/Source/IO/FS/FS.cpp index c6779513..e75c1039 100644 --- a/Source/IO/FS/FS.cpp +++ b/Source/IO/FS/FS.cpp @@ -230,8 +230,8 @@ namespace Aurora::IO::FS } bool ok {}; - ok = stream->Write(bom, 3); - ok &= stream->Write(str.data(), str.size()) == str.size(); + ok = stream->Write(Memory::MemoryViewStreamRead{bom}); + ok &= stream->Write(Memory::MemoryViewStreamRead{str}); stream->Flush(); return ok; diff --git a/Source/Locale/Encoding/EncoderAdapter.cpp b/Source/Locale/Encoding/EncoderAdapter.cpp index 4502ac4c..db848101 100644 --- a/Source/Locale/Encoding/EncoderAdapter.cpp +++ b/Source/Locale/Encoding/EncoderAdapter.cpp @@ -44,7 +44,6 @@ namespace Aurora::Locale::Encoding { return {}; } - if (((page == ECodePage::eSysUnk) && (GetInternalCodePage() == ECodePage::eUTF8)) || diff --git a/Source/Locale/Encoding/Encoding.cpp b/Source/Locale/Encoding/Encoding.cpp index bad39fae..f0d8b1cf 100644 --- a/Source/Locale/Encoding/Encoding.cpp +++ b/Source/Locale/Encoding/Encoding.cpp @@ -11,7 +11,7 @@ namespace Aurora::Locale::Encoding { - AUKN_SYM AuOptional> DecodeBOM(const void *binary, AuUInt32 binaryLength) + AUKN_SYM AuOptional> DecodeBOM(Aurora::Memory::MemoryViewRead binary) { #define ADD_PATTERN(str, code) {str, AuArraySize(str) - 1, ECodePage::code} AuList> bows = @@ -32,8 +32,8 @@ namespace Aurora::Locale::Encoding for (const auto &[string, length, category] : bows) { - if (binaryLength < length) continue; - if (std::memcmp(binary, string, length) != 0) continue; + if (binary.length < length) continue; + if (std::memcmp(binary.ptr, string, length) != 0) continue; return AuMakePair(category, length); } @@ -41,32 +41,32 @@ namespace Aurora::Locale::Encoding return {}; } - AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const void *utf8, AuUInt32 utf8Length, void *binary, AuUInt32 binaryLength, ECodePage page) + AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(Aurora::Memory::MemoryViewRead utf8, Aurora::Memory::MemoryViewWrite binary, ECodePage page) { TextStreamEncoder re(page); - return re.DecodeUTF8(utf8, utf8Length, binary, binaryLength); + return re.DecodeUTF8(utf8.ptr, utf8.length, binary.ptr, binary.length); } - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utf8Max, ECodePage page) + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, Aurora::Memory::MemoryViewWrite utf8, ECodePage page) { TextStreamProcessor re(page); - return re.EncodeUTF8(binary, binaryLength, utf8, utf8Max); + return re.EncodeUTF8(binary.ptr, binary.length, utf8.ptr, utf8.length); } - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page) + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, AuString &out, ECodePage page) { - auto aaa = DecodeUTF8(binary, binaryLength, nullptr, 0, page); + auto aaa = DecodeUTF8(binary, {}, page); out.resize(aaa.second); - auto ret = DecodeUTF8(binary, binaryLength, out.data(), out.size(), page); + auto ret = DecodeUTF8(binary, Memory::MemoryViewWrite(out.data(), out.size()), page); out.resize(ret.second); return ret; } AuStreamReadWrittenPair_t DecodeUTF8(void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page) { - auto aaa = DecodeUTF8(binary, binaryLength, nullptr, 0, page); + auto aaa = DecodeUTF8(Aurora::Memory::MemoryViewRead(binary, binaryLength), {}, page); out.resize(aaa.second); - auto ret = DecodeUTF8(binary, binaryLength, out.data(), out.size(), page); + auto ret = DecodeUTF8(Aurora::Memory::MemoryViewRead(binary, binaryLength), Aurora::Memory::MemoryViewWrite(out.data(), out.size()), page); out.resize(ret.second); return ret; } diff --git a/Source/Locale/Encoding/Encoding.hpp b/Source/Locale/Encoding/Encoding.hpp index 8060743c..e98b3a13 100644 --- a/Source/Locale/Encoding/Encoding.hpp +++ b/Source/Locale/Encoding/Encoding.hpp @@ -128,7 +128,7 @@ namespace Aurora::Locale::Encoding { if (page == ECodePage::eUnsupported) { - auto header = DecodeBOM(binary, binaryLength); + auto header = DecodeBOM(Aurora::Memory::MemoryViewRead(binary, binaryLength)); if (header) { page = header->first;