diff --git a/Include/auROXTL/MemoryModel/auMemoryAllocate.hpp b/Include/auROXTL/MemoryModel/auMemoryAllocate.hpp index d0451e6..34948bd 100755 --- a/Include/auROXTL/MemoryModel/auMemoryAllocate.hpp +++ b/Include/auROXTL/MemoryModel/auMemoryAllocate.hpp @@ -1,3 +1,11 @@ +/*** + Copyright (C) 2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auMemoryAllocate.hpp + Date: 2024-09-13 + Date: 2024-02-13 + Author: Reece +***/ #pragma once #if defined(AURORA_ROXTL_HAS_RUNTIME) && AURORA_ROXTL_HAS_RUNTIME @@ -57,13 +65,13 @@ using AuHUPOf_t = AuUPtr; template auto AuNullHeapPointer() { - return AuHeapNullUniquePointer(); + return AuUPtr(); } template auto AuNullPointer() { - return AuHeapNullUniquePointer(); + return AuUPtr(); } template @@ -146,5 +154,5 @@ template AuHUPOf_t AuCastPointer(AuHUPOf_t &&pInPointer) { // TODO: we can do better with this memory model update - return AuHeapCastPointer(AuMove(pInPointer)); + return AuHeap::CastPointer(AuMove(pInPointer)); } \ No newline at end of file diff --git a/Include/auROXTL/MemoryModel/auMemoryView.hpp b/Include/auROXTL/MemoryModel/auMemoryView.hpp index 4d496fb..c375301 100755 --- a/Include/auROXTL/MemoryModel/auMemoryView.hpp +++ b/Include/auROXTL/MemoryModel/auMemoryView.hpp @@ -143,12 +143,7 @@ public: AuUInt CopyInto(const AuMemoryView &write) const; template - AuUInt CopyFrom(const AuMemoryView &read) const - { - auto uLength = AuMin(this->uLength, read.uLength); - AuMemcpy(this->pBase, read.pBase, uLength); - return uLength; - } + AuUInt CopyFrom(const AuMemoryView &read) const; bool HasControlBlock() const; @@ -280,30 +275,14 @@ struct AuMemoryViewStream : AuMemoryView outVariable = 0; } - constexpr bool HasMemory() const - { - return this->ptr && this->length; - } + constexpr bool HasMemory() const; - constexpr operator bool() const - { - return HasMemory(); - } + constexpr operator bool() const; - void CopyStreamInto(const AuMemoryView &write) const - { - auto uLength = AuMin(this->uLength, write.uLength); - AuMemcpy(write.pBase, this->pBase, uLength); - this->outVariable = uLength; - } + void CopyStreamInto(const AuMemoryView &write) const; template - void CopyStreamFrom(const AuMemoryView &read) const - { - auto uLength = AuMin(this->uLength, read.uLength); - AuMemcpy(this->pBase, read.pBase, uLength); - this->outVariable = uLength; - } + void CopyStreamFrom(const AuMemoryView &read) const; AuUInt &outVariable; private: diff --git a/Include/auROXTL/MemoryModel/auMemoryView.ipp b/Include/auROXTL/MemoryModel/auMemoryView.ipp index 3baff4e..9e75ec5 100755 --- a/Include/auROXTL/MemoryModel/auMemoryView.ipp +++ b/Include/auROXTL/MemoryModel/auMemoryView.ipp @@ -622,3 +622,40 @@ AuUInt AuMemoryView::CopyInto(const AuMemoryView &write) cons return uLength; } +template +template::type *> +inline AuUInt AuMemoryView::CopyFrom(const AuMemoryView &read) const +{ + auto uLength = AuMin(this->uLength, read.uLength); + AuMemcpy(this->pBase, read.pBase, uLength); + return uLength; +} + +template +constexpr bool AuMemoryViewStream::HasMemory() const +{ + return this->ptr && this->length; +} + +template +constexpr AuMemoryViewStream::operator bool() const +{ + return HasMemory(); +} + +template +inline void AuMemoryViewStream::CopyStreamInto(const AuMemoryView &write) const +{ + auto uLength = AuMin(this->uLength, write.uLength); + AuMemcpy(write.pBase, this->pBase, uLength); + this->outVariable = uLength; +} + +template +template::type *> +inline void AuMemoryViewStream::CopyStreamFrom(const AuMemoryView &read) const +{ + auto uLength = AuMin(this->uLength, read.uLength); + AuMemcpy(this->pBase, read.pBase, uLength); + this->outVariable = uLength; +} diff --git a/Include/auROXTL/Objects/SOO.hpp b/Include/auROXTL/Objects/SOO.hpp index 5fb6e02..a2a5aa2 100644 --- a/Include/auROXTL/Objects/SOO.hpp +++ b/Include/auROXTL/Objects/SOO.hpp @@ -110,7 +110,32 @@ struct AU_ALIGN(sizeof(AuUInt)) Type ## SOO }; \ \ using Type ## SOO_t = Type ## SOO; \ -using Type = Type ## SOO; +using Type = Type ## SOO; \ + \ + template \ + AuUPtr Type ## UniqueOnHeap(AuHeap *pHeap, T &&... args) \ + { \ + auto pThat = pHeap->NewClassUnique(AuForward(args)...); \ + if (!pThat) \ + { \ + return AuUPtr {}; \ + } \ + return AuUPtr { \ + pThat.Release()->AsPointer(), \ + ((void (*)(extends *))pThat.GetDeleter()) \ + }; \ + } \ + \ + template \ + AuSPtr Type ## SharedOnHeap(AuHeap *pHeap, T &&... args) \ + { \ + auto pThat = pHeap->NewClass(AuForward(args)...); \ + if (!pThat) \ + { \ + return {}; \ + } \ + return { pThat, pThat->AsPointer() }; \ + } #define AU_SOO_MOVE_BASIC(Type) \ inline Type(Type &&that) \ @@ -172,19 +197,7 @@ using Type = Type ## SOO; AUROXTL_INTERFACE_SOO_HDR_EX2(vis, Type, extends, targetSize, (AU_NO_COPY_NO_MOVE(Type ## SOO)), ## __VA_ARGS__) #define AUROXTL_INTERFACE_SOO_HDR(Type, extends, targetSize, ...) \ - AUROXTL_INTERFACE_SOO_HDR_EX(, Type, extends, targetSize, ## __VA_ARGS__) \ - \ - template \ - extends ## Unique_t Type ## UniqueOnHeap(AuHeap *pHeap, T &&... args) \ - { \ - return pHeap->NewClassUnique(AuForward(args)...); \ - } \ - \ - template \ - extends ## Shared_t Type ## SharedOnHeap(AuHeap *pHeap, T &&... args) \ - { \ - return pHeap->NewClass(AuForward(args)...); \ - } + AUROXTL_INTERFACE_SOO_HDR_EX(, Type, extends, targetSize, ## __VA_ARGS__) #define AUROXTL_INTERFACE_SOO_SRC_EX(vis, Type, FullType, ...) \ vis Type ## SOO::Type ## SOO(AU_FOR_EACH_FIRST(_AUROXTL_INTERRFACE_SOO_EMITTER_0, _AUROXTL_INTERRFACE_SOO_EMITTER_1, ## __VA_ARGS__, (AuUInt32, uSize))) \