[+] AuMemoryView::MemoryStartsWith
[+] AuMemoryView::MemoryEndsWith [+] AuMemoryView::MemoryEquals [+] AuMemoryView::MemoryCompare [+] AuMemoryView::MemoryIsSupersetOf [+] AuMemoryView::MemoryIsSubsetOf [+] AuMemoryView::MemoryFindNeedle [*] AuMemoryView cleanup
This commit is contained in:
parent
a649d82fd0
commit
d8d2474ff9
@ -20,12 +20,11 @@ struct AuMemoryViewControlBlock
|
||||
// Mitgation: SysAssert(!pObject->uInUse)
|
||||
AuAUInt32 *pInUseCounter {};
|
||||
|
||||
// Mitigation (cont) and reducing code reuse:
|
||||
// -> Allow for [shared!] memory views to have a shared freestanding owner
|
||||
// Mitigation (cont) and QOL feature:
|
||||
// -> Allow for memory views to have a shared owner / hold on parent
|
||||
// -> Ensure reference counters or other forms of memory management don't free the owner before us
|
||||
// (Consider inverse construction order, for instance, we'd have to always call AuMemoryView::ResetControlBlock()
|
||||
// in a derived subclass, in order release the pInUseCounter reference before the derived shared members get released)
|
||||
AuSSPtr<void> pPinner; // WARNING: as usual, std types don't validate their allocator, and our shared ptrs can be different between binaries!
|
||||
// -> Keeps pInUseCounter and pCallbackHandle alive
|
||||
AuSSPtr<void> pPinner;
|
||||
|
||||
void *pCallbackHandle {};
|
||||
|
||||
@ -36,7 +35,8 @@ struct AuMemoryViewControlBlock
|
||||
inline void Release();
|
||||
};
|
||||
|
||||
// A memory view that can be reinterpret cast to any type. May contain shared pointer control blocks for persistency.
|
||||
// A memory view that can be reinterpret cast to any type.
|
||||
// May contain shared pointer control blocks for out of scope memory persistency pinning.
|
||||
template<bool Readonly_b>
|
||||
struct AuMemoryView
|
||||
{
|
||||
@ -45,7 +45,7 @@ struct AuMemoryView
|
||||
|
||||
constexpr AuMemoryView();
|
||||
|
||||
template<typename T, AU_TEMPLATE_ENABLE_WHEN(AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value)>
|
||||
template <typename T, AU_TEMPLATE_ENABLE_WHEN(AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value)>
|
||||
constexpr AuMemoryView(T &list)
|
||||
{
|
||||
this->ptr = list.data();
|
||||
@ -60,6 +60,10 @@ struct AuMemoryView
|
||||
|
||||
AuMemoryView(const AuMemoryView &view);
|
||||
|
||||
/// See: DemoteFromSharedView
|
||||
AuMemoryView(const AuSPtr<AuMemoryView> &pCopy);
|
||||
|
||||
/// Expand existing AuMemoryView with a shared pointer (+ other optional parameters)
|
||||
AuMemoryView(const AuMemoryView &view,
|
||||
const AuSPtr<void> &pThat,
|
||||
void *pCallbackHandle = nullptr,
|
||||
@ -67,33 +71,33 @@ struct AuMemoryView
|
||||
|
||||
constexpr AuMemoryView(AuMemoryView &&view);
|
||||
|
||||
template<typename T, int Z>
|
||||
template <typename T, int Z>
|
||||
constexpr AuMemoryView(T(&a)[Z]);
|
||||
|
||||
template<typename T, int Z>
|
||||
template <typename T, int Z>
|
||||
constexpr AuMemoryView(AuArray<T, Z> &view);
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView(T *start, T *end);
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView(T *start, T *end, AuAUInt32 *pInUseCounter, void *pCallbackHandle = nullptr, void (*pfCallbackOnZero)(void *) = nullptr);
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView(T *start, T *end, AuAUInt32 *pInUseCounter, const AuSPtr<void> &pRAIIOwner, void *pCallbackHandle = nullptr, void (*pfCallbackOnZero)(void *) = nullptr);
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView(T *start, AuUInt length); // WARNING: length != count
|
||||
// where T = whogivesafuck
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView(T *start, AuUInt length, AuAUInt32 *pInUseCounter, void *pCallbackHandle = nullptr, void (*pfCallbackOnZero)(void *) = nullptr); // WARNING: length != count
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView(T *start, AuUInt length, AuAUInt32 *pInUseCounter, const AuSPtr<void> &pRAIIOwner, void *pCallbackHandle = nullptr, void (*pfCallbackOnZero)(void *) = nullptr); // WARNING: length != count
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
AuMemoryView(T *start, AuUInt length, const AuMemoryViewControlBlock ©Block);
|
||||
|
||||
public:
|
||||
@ -104,33 +108,47 @@ public:
|
||||
constexpr AuUInt ToPointerValue() const;
|
||||
|
||||
constexpr AuUInt ToLength() const;
|
||||
constexpr AuUInt Length() const;
|
||||
constexpr AuUInt Length() const;
|
||||
|
||||
constexpr AuUInt ToSize() const;
|
||||
constexpr AuUInt Size() const;
|
||||
constexpr AuUInt size() const;
|
||||
constexpr AuUInt ToSize() const;
|
||||
constexpr AuUInt Size() const;
|
||||
constexpr AuUInt size() const;
|
||||
|
||||
template<typename T = AuUInt8>
|
||||
constexpr AuUInt ToCount() const;
|
||||
template<typename T = AuUInt8>
|
||||
constexpr AuUInt Count() const;
|
||||
template <typename T = AuUInt8>
|
||||
constexpr AuUInt ToCount() const;
|
||||
template <typename T = AuUInt8>
|
||||
constexpr AuUInt Count() const;
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> Begin() const;
|
||||
|
||||
template<typename T>
|
||||
AuConditional_t<Readonly_b, const T*, T*> End() const;
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> End() const;
|
||||
|
||||
constexpr bool HasMemory() const;
|
||||
constexpr U8_t Begin() const;
|
||||
constexpr U8_t End() const;
|
||||
|
||||
constexpr operator bool() const;
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> begin() const;
|
||||
|
||||
constexpr U8_t ToPointer() const;
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> end() const;
|
||||
|
||||
constexpr U8_t begin() const;
|
||||
constexpr U8_t end() const;
|
||||
constexpr U8_t Begin() const;
|
||||
constexpr U8_t End() const;
|
||||
constexpr U8_t begin() const;
|
||||
constexpr U8_t end() const;
|
||||
|
||||
constexpr bool HasMemory() const;
|
||||
constexpr operator bool() const;
|
||||
|
||||
constexpr U8_t ToPointer() const;
|
||||
|
||||
bool MemoryStartsWith(const AuMemoryView<true> &in) const;
|
||||
bool MemoryEndsWith(const AuMemoryView<true> &in) const;
|
||||
bool MemoryEquals(const AuMemoryView<true> &in) const;
|
||||
AuSInt MemoryCompare(const AuMemoryView<true> &in) const;
|
||||
bool MemoryIsSupersetOf(const AuMemoryView<true> &in) const; // `*this` range contains `in` address
|
||||
bool MemoryIsSubsetOf(const AuMemoryView<true> &in) const; // `in` range contains `*this`
|
||||
AuMemoryView MemoryFindNeedle(const AuMemoryView<true> &in, bool bTakeUntilEnd = true) const;
|
||||
|
||||
AuMemoryView AtOffset(AuUInt uOffset) const;
|
||||
AuMemoryView Take(AuUInt uLength) const;
|
||||
@ -138,34 +156,44 @@ public:
|
||||
AuMemoryView Clone() const;
|
||||
AuMemoryView Clone(AuHeap *pHeap, AuUInt32 uAlignment = alignof(double)) const;
|
||||
|
||||
bool TryCloneSelf(bool bResetOnFailure = true);
|
||||
bool TryCloneSelf(bool bResetOnFailure = true);
|
||||
|
||||
AuUInt CopyInto(const AuMemoryView<false> &write) const;
|
||||
|
||||
template<bool bThat = Readonly_b, AU_TEMPLATE_ENABLE_WHEN(!bThat)>
|
||||
AuUInt CopyFrom(const AuMemoryView<true> &read) const;
|
||||
|
||||
bool HasControlBlock() const;
|
||||
bool HasControlBlock() const;
|
||||
|
||||
/// Creates a shader pointer of the view with an optional parent
|
||||
/// Creates (alloc) a shader pointer of the view with an optional parent to capture.
|
||||
/// If the lifetime of the span cannot be extended beyond the *this container, we fail (return default/nullptr).
|
||||
/// If we cannot allocate the shared pointer, we fail (return default/nullptr).
|
||||
AuSPtr<AuMemoryView> TryPromoteToSharedView(AuSPtr<void> pParent = {}) const;
|
||||
|
||||
/// Creates a shader pointer of the view with an optional parent
|
||||
/// If *this already contains a shared parent, will return nullptr
|
||||
/// Creates (alloc) a shader pointer of the view with an optional parent we'd prefer not to capture.
|
||||
/// If *this already contains a shared parent, pParent is ignored.
|
||||
/// If we cannot allocate the shared pointer, we fail (return default/nullptr).
|
||||
/// If the lifetime of the span cannot be extended beyond the *this container, we fail (return default/nullptr).
|
||||
AuSPtr<AuMemoryView> TryPromoteToSharedViewNoParentNesting(AuSPtr<void> pParent = {}) const;
|
||||
|
||||
/// Shares ownership of pCopy, returning false if there is no shared parent.
|
||||
/// (noalloc) Returns AuSharedPointerFromShared(this, pParent)
|
||||
AuSPtr<AuMemoryView> SharedOfThisFromSharedParent(AuSPtr<void> pParent) const;
|
||||
|
||||
/// (noalloc) Shares ownership of pCopy, returning false if there is no shared parent.
|
||||
/// (not recommended)
|
||||
bool TryDemoteFromSharedView(const AuSPtr<AuMemoryView> &pCopy);
|
||||
|
||||
/// Shares ownership of pCopy, returning false if there is no shared parent.
|
||||
/// (noalloc) Shares ownership of pCopy, returning false if there is no shared parent.
|
||||
/// (by const ref version of TryDemoteFromSharedView)
|
||||
bool TryDemoteFromReference(const AuMemoryView &refCopy);
|
||||
|
||||
/// Copies the memory view of a shared memory view.
|
||||
/// If the memory view has a shared parent, the memory view and its parent shared pointer is copied into *this.
|
||||
/// If the memory view does not have a shared parent, the memory view and its control block is copied into *this.
|
||||
/// (noalloc) Copies pCopy memory view into *this.
|
||||
///
|
||||
/// If pCopy memory view has a shared parent, the memory view and its parent shared pointer is copied into *this.
|
||||
/// If pCopy memory view does not have a shared parent, the memory view and its shared pointer control block is copied into *this.
|
||||
void DemoteFromSharedView(const AuSPtr<AuMemoryView> &pCopy);
|
||||
|
||||
/// Interop for other APIs that allow for pinning shared pointers (std::shared_ptr)
|
||||
/// (usually-no-alloc) Interop for other APIs that allow for pinning shared pointers (std::shared_ptr)
|
||||
AuSPtr<void> ToSharedControlBlock(bool *pbFailed = nullptr);
|
||||
|
||||
union
|
||||
@ -183,6 +211,18 @@ public:
|
||||
|
||||
private:
|
||||
AuMemoryViewControlBlock controlBlock;
|
||||
#if defined(AU_LANG_CPP_17_)
|
||||
char padding[
|
||||
#if defined(AURORA_IS_64BIT)
|
||||
64
|
||||
#else
|
||||
32
|
||||
#endif
|
||||
- sizeof(AuMemoryViewControlBlock)
|
||||
- sizeof(AuUInt)
|
||||
- sizeof(AuUInt)
|
||||
] { };
|
||||
#endif
|
||||
};
|
||||
|
||||
using AuMemoryViewRead = AuMemoryView<true>;
|
||||
@ -194,7 +234,7 @@ using AuMemoryViewWrite = AuMemoryView<false>;
|
||||
template<bool Readonly_b>
|
||||
struct AuMemoryViewStream : AuMemoryView<Readonly_b>
|
||||
{
|
||||
template<typename T, AU_TEMPLATE_ENABLE_WHEN(AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value)>
|
||||
template <typename T, AU_TEMPLATE_ENABLE_WHEN(AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value)>
|
||||
constexpr AuMemoryViewStream(T &list, AuUInt &length) : AuMemoryView<Readonly_b>(list), outVariable(length)
|
||||
{
|
||||
outVariable = 0;
|
||||
@ -205,19 +245,19 @@ struct AuMemoryViewStream : AuMemoryView<Readonly_b>
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryViewStream(T *start, T *end, AuUInt &length) : AuMemoryView<Readonly_b>(start, end), outVariable(length)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
constexpr AuMemoryViewStream(T *start, AuUInt &length) : AuMemoryView<Readonly_b>(start, length), outVariable(length)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T, int Z>
|
||||
template <typename T, int Z>
|
||||
constexpr AuMemoryViewStream(AuArray<T, Z> &view,
|
||||
AuUInt &length) :
|
||||
AuMemoryView<Readonly_b>(view),
|
||||
@ -226,7 +266,7 @@ struct AuMemoryViewStream : AuMemoryView<Readonly_b>
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T, typename AuEnableIf<AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value>::type* = nullptr>
|
||||
template <typename T, typename AuEnableIf<AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value>::type* = nullptr>
|
||||
constexpr AuMemoryViewStream(T &list) : AuMemoryView<Readonly_b>(list), outVariable(unused)
|
||||
{
|
||||
outVariable = 0;
|
||||
@ -253,24 +293,31 @@ struct AuMemoryViewStream : AuMemoryView<Readonly_b>
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr AuMemoryViewStream(T *start, T *end) : AuMemoryView<Readonly_b>(start, end), outVariable(unused)
|
||||
template <typename T>
|
||||
constexpr AuMemoryViewStream(T *start, T *end) :
|
||||
AuMemoryView<Readonly_b>(start, end),
|
||||
outVariable(unused)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
constexpr AuMemoryViewStream(AuMemoryView<Readonly_b> in) : AuMemoryView<Readonly_b>(in.ptr, in.length), outVariable(unused)
|
||||
constexpr AuMemoryViewStream(AuMemoryView<Readonly_b> in) :
|
||||
AuMemoryView<Readonly_b>(in.ptr, in.length),
|
||||
outVariable(unused)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
constexpr AuMemoryViewStream(AuMemoryView<Readonly_b> in, AuUInt &len) : AuMemoryView<Readonly_b>(in.ptr, in.length), outVariable(len)
|
||||
constexpr AuMemoryViewStream(AuMemoryView<Readonly_b> in, AuUInt &len) :
|
||||
AuMemoryView<Readonly_b>(in.ptr, in.length),
|
||||
outVariable(len)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T, int Z>
|
||||
constexpr AuMemoryViewStream(T(&a)[Z]) : AuMemoryView<Readonly_b>(a), outVariable(unused)
|
||||
template <typename T, int Z>
|
||||
constexpr AuMemoryViewStream(T(&a)[Z]) : AuMemoryView<Readonly_b>(a),
|
||||
outVariable(unused)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
@ -286,6 +333,10 @@ struct AuMemoryViewStream : AuMemoryView<Readonly_b>
|
||||
|
||||
AuUInt &outVariable;
|
||||
private:
|
||||
#if defined(AU_LANG_CPP_17_)
|
||||
// dont embed a dummy address in the struct itself
|
||||
cstatic
|
||||
#endif
|
||||
AuUInt unused;
|
||||
};
|
||||
|
||||
|
@ -38,14 +38,14 @@ void AuMemoryViewControlBlock::Release()
|
||||
AuResetMember(this->pfCallbackOnZero);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView()
|
||||
{
|
||||
this->ptr = nullptr;
|
||||
this->length = 0;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(const AuROString &str)
|
||||
{
|
||||
static_assert(Readonly_b, "ReadOnly string view must not be placed in a writable memory view");
|
||||
@ -53,7 +53,7 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(const AuROString &str)
|
||||
this->length = str.size();
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(const AuRONString &str)
|
||||
{
|
||||
static_assert(Readonly_b, "ReadOnly string view must not be placed in a writable memory view");
|
||||
@ -61,14 +61,14 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(const AuRONString &str)
|
||||
this->length = str.size();
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(const AuString &str)
|
||||
{
|
||||
this->ptr = str.data();
|
||||
this->length = str.size();
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b>::AuMemoryView(const AuMemoryView &view)
|
||||
{
|
||||
this->ptr = view.ptr;
|
||||
@ -80,7 +80,13 @@ AuMemoryView<Readonly_b>::AuMemoryView(const AuMemoryView &view)
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b>::AuMemoryView(const AuSPtr<AuMemoryView> &pCopy)
|
||||
{
|
||||
this->DemoteFromSharedView(pCopy);
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b>::AuMemoryView(const AuMemoryView &view,
|
||||
const AuSPtr<void> &pThat,
|
||||
void *pCallbackHandle,
|
||||
@ -122,7 +128,7 @@ AuMemoryView<Readonly_b>::AuMemoryView(const AuMemoryView &view,
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(AuMemoryView &&view)
|
||||
{
|
||||
this->ptr = view.ptr;
|
||||
@ -135,24 +141,24 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(AuMemoryView &&view)
|
||||
view.controlBlock.pfCallbackOnZero = nullptr;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T, int Z>
|
||||
template <bool Readonly_b>
|
||||
template <typename T, int Z>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T(&a)[Z])
|
||||
{
|
||||
this->ptr = &a[0];
|
||||
this->length = Z * sizeof(T);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T, int Z>
|
||||
template <bool Readonly_b>
|
||||
template <typename T, int Z>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(AuArray<T, Z> &view)
|
||||
{
|
||||
this->ptr = view.begin();
|
||||
this->length = Z * sizeof(T);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, T *end)
|
||||
{
|
||||
this->ptr = start;
|
||||
@ -166,8 +172,8 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, T *end)
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, T *end, AuAUInt32 *pInUseCounter, void *pCallbackHandle, void (*pfCallbackOnZero)(void *))
|
||||
{
|
||||
this->ptr = start;
|
||||
@ -186,8 +192,8 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, T *end, AuAUInt32 *pI
|
||||
this->controlBlock.pfCallbackOnZero = pfCallbackOnZero;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, T *end, AuAUInt32 *pInUseCounter, const AuSPtr<void> &pRAIIOwner, void *pCallbackHandle, void (*pfCallbackOnZero)(void *))
|
||||
{
|
||||
this->ptr = start;
|
||||
@ -207,8 +213,8 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, T *end, AuAUInt32 *pI
|
||||
this->controlBlock.pfCallbackOnZero = pfCallbackOnZero;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length) // WARNING: length != count
|
||||
// where T = whogivesafuck
|
||||
{
|
||||
@ -216,8 +222,8 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length) // WAR
|
||||
this->length = length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length, AuAUInt32 *pInUseCounter, void *pCallbackHandle, void (*pfCallbackOnZero)(void *)) // WARNING: length != count
|
||||
{
|
||||
this->ptr = start;
|
||||
@ -228,8 +234,8 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length, AuAUIn
|
||||
this->controlBlock.pfCallbackOnZero = pfCallbackOnZero;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length, AuAUInt32 *pInUseCounter, const AuSPtr<void> &pRAIIOwner, void *pCallbackHandle, void (*pfCallbackOnZero)(void *)) // WARNING: length != count
|
||||
{
|
||||
this->ptr = start;
|
||||
@ -241,8 +247,8 @@ constexpr AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length, AuAUIn
|
||||
this->controlBlock.pfCallbackOnZero = pfCallbackOnZero;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length, const AuMemoryViewControlBlock ©Block)
|
||||
{
|
||||
this->ptr = start;
|
||||
@ -254,7 +260,7 @@ AuMemoryView<Readonly_b>::AuMemoryView(T *start, AuUInt length, const AuMemoryVi
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> &AuMemoryView<Readonly_b>::operator =(AuMemoryView &&view)
|
||||
{
|
||||
this->ptr = view.ptr;
|
||||
@ -268,7 +274,7 @@ AuMemoryView<Readonly_b> &AuMemoryView<Readonly_b>::operator =(AuMemoryView &&vi
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> &AuMemoryView<Readonly_b>::operator =(const AuMemoryView &view)
|
||||
{
|
||||
this->ptr = view.ptr;
|
||||
@ -284,113 +290,127 @@ AuMemoryView<Readonly_b> &AuMemoryView<Readonly_b>::operator =(const AuMemoryVie
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::ToPointerValue() const
|
||||
{
|
||||
return this->uPtr;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::ToLength() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::Length() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::ToSize() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::Size() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::ToCount() const
|
||||
{
|
||||
return this->length / sizeof(T);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::Count() const
|
||||
{
|
||||
return this->length / sizeof(T);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> AuMemoryView<Readonly_b>::Begin() const
|
||||
{
|
||||
return reinterpret_cast<AuConditional_t<Readonly_b, const T *, T *>>(ptr);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<typename T>
|
||||
AuConditional_t<Readonly_b, const T*, T*> AuMemoryView<Readonly_b>::End() const
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> AuMemoryView<Readonly_b>::End() const
|
||||
{
|
||||
return Begin<T>() + ToCount<T>();
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> AuMemoryView<Readonly_b>::begin() const
|
||||
{
|
||||
return reinterpret_cast<AuConditional_t<Readonly_b, const T *, T *>>(ptr);
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
template <typename T>
|
||||
AuConditional_t<Readonly_b, const T *, T *> AuMemoryView<Readonly_b>::end() const
|
||||
{
|
||||
return Begin<T>() + ToCount<T>();
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
constexpr bool AuMemoryView<Readonly_b>::HasMemory() const
|
||||
{
|
||||
return this->ptr && this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryView<Readonly_b>::operator bool() const
|
||||
{
|
||||
return this->HasMemory();
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr typename AuMemoryView<Readonly_b>::U8_t AuMemoryView<Readonly_b>::ToPointer() const
|
||||
{
|
||||
return this->ptrU8;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr typename AuMemoryView<Readonly_b>::U8_t AuMemoryView<Readonly_b>::begin() const
|
||||
{
|
||||
return this->ptrU8;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr typename AuMemoryView<Readonly_b>::U8_t AuMemoryView<Readonly_b>::end() const
|
||||
{
|
||||
return this->ptrU8 + this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr typename AuMemoryView<Readonly_b>::U8_t AuMemoryView<Readonly_b>::Begin() const
|
||||
{
|
||||
return this->ptrU8;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr typename AuMemoryView<Readonly_b>::U8_t AuMemoryView<Readonly_b>::End() const
|
||||
{
|
||||
return this->ptrU8 + this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuUInt AuMemoryView<Readonly_b>::size() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::AtOffset(AuUInt uOffset) const
|
||||
{
|
||||
if (uOffset < this->uLength)
|
||||
@ -405,7 +425,7 @@ AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::AtOffset(AuUInt uOffset) cons
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::Take(AuUInt uLength) const
|
||||
{
|
||||
if (uLength <= this->uLength)
|
||||
@ -420,7 +440,120 @@ AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::Take(AuUInt uLength) const
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::MemoryEndsWith(const AuMemoryView<true> &in) const
|
||||
{
|
||||
if (this->Size() < in.Size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AuMemcmp(this->Begin() + this->Size() - in.Size(),
|
||||
in.Begin(),
|
||||
in.Size()) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::MemoryStartsWith(const AuMemoryView<true> &in) const
|
||||
{
|
||||
if (this->Size() < in.Size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AuMemcmp(this->Begin(), in.Begin(), in.Size()) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::MemoryEquals(const AuMemoryView<true> &in) const
|
||||
{
|
||||
if (this->Size() != in.Size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AuMemcmp(this->Begin(), in.Begin(), in.Size()) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
AuSInt AuMemoryView<Readonly_b>::MemoryCompare(const AuMemoryView<true> &in) const
|
||||
{
|
||||
if (this->Size() < in.Size())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto iRet = AuMemcmp(this->Begin(), in.Begin(), in.Size());
|
||||
|
||||
if (this->Size() > in.Size() &&
|
||||
iRet == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return iRet;
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::MemoryIsSupersetOf(const AuMemoryView<true> &in) const
|
||||
{
|
||||
if (!in)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in.uPtr < this->uPtr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in.uPtr + in.uLength > this->uPtr + this->uLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::MemoryIsSubsetOf(const AuMemoryView<true> &in) const
|
||||
{
|
||||
return in.MemoryIsSupersetOf(*this);
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::MemoryFindNeedle(const AuMemoryView<true> &in, bool bTakeUntilEnd) const
|
||||
{
|
||||
auto pOffset = AuMemmem(this->pBase, this->uLength,
|
||||
in.pBase, in.uLength);
|
||||
if (!pOffset)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (bTakeUntilEnd)
|
||||
{
|
||||
auto uOffset = (AuUInt8 *)pOffset - this->ptrU8;
|
||||
|
||||
return AuMemoryView(pOffset,
|
||||
this->uLength - uOffset,
|
||||
this->controlBlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
return AuMemoryView(pOffset,
|
||||
in.uLength,
|
||||
this->controlBlock);
|
||||
}
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::Clone() const
|
||||
{
|
||||
auto uLength = this->uLength;
|
||||
@ -434,7 +567,7 @@ AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::Clone() const
|
||||
return AuMemoryView(AuMemoryView(pData.get(), uLength), pData);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::Clone(AuHeap *pHeap, AuUInt32 uAlignment) const
|
||||
{
|
||||
auto uLength = this->uLength;
|
||||
@ -448,7 +581,7 @@ AuMemoryView<Readonly_b> AuMemoryView<Readonly_b>::Clone(AuHeap *pHeap, AuUInt32
|
||||
return AuMemoryView(AuMemoryView(pData.get(), uLength), pData);
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::TryCloneSelf(bool bResetOnFailure)
|
||||
{
|
||||
auto replacement = Clone();
|
||||
@ -464,7 +597,7 @@ bool AuMemoryView<Readonly_b>::TryCloneSelf(bool bResetOnFailure)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::HasControlBlock() const
|
||||
{
|
||||
return this->controlBlock.pInUseCounter ||
|
||||
@ -472,7 +605,7 @@ bool AuMemoryView<Readonly_b>::HasControlBlock() const
|
||||
this->controlBlock.pfCallbackOnZero;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuSPtr<AuMemoryView<Readonly_b>> AuMemoryView<Readonly_b>::TryPromoteToSharedView(AuSPtr<void> pParent) const
|
||||
{
|
||||
#if 0
|
||||
@ -515,7 +648,7 @@ AuSPtr<AuMemoryView<Readonly_b>> AuMemoryView<Readonly_b>::TryPromoteToSharedVie
|
||||
#endif
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuSPtr<AuMemoryView<Readonly_b>> AuMemoryView<Readonly_b>::TryPromoteToSharedViewNoParentNesting(AuSPtr<void> pParent) const
|
||||
{
|
||||
if (this->HasControlBlock())
|
||||
@ -531,7 +664,13 @@ AuSPtr<AuMemoryView<Readonly_b>> AuMemoryView<Readonly_b>::TryPromoteToSharedVie
|
||||
return {};
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuSPtr<AuMemoryView<Readonly_b>> AuMemoryView<Readonly_b>::SharedOfThisFromSharedParent(AuSPtr<void> pParent) const
|
||||
{
|
||||
return AuSharedPointerFromShared(this, pParent);
|
||||
}
|
||||
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::TryDemoteFromSharedView(const AuSPtr<AuMemoryView<Readonly_b>> &pCopy)
|
||||
{
|
||||
if (pCopy && pCopy->HasControlBlock())
|
||||
@ -545,7 +684,7 @@ bool AuMemoryView<Readonly_b>::TryDemoteFromSharedView(const AuSPtr<AuMemoryView
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
bool AuMemoryView<Readonly_b>::TryDemoteFromReference(const AuMemoryView &refCopy)
|
||||
{
|
||||
if (refCopy.HasControlBlock())
|
||||
@ -559,7 +698,7 @@ bool AuMemoryView<Readonly_b>::TryDemoteFromReference(const AuMemoryView &refCop
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
void AuMemoryView<Readonly_b>::DemoteFromSharedView(const AuSPtr<AuMemoryView<Readonly_b>> &pCopy)
|
||||
{
|
||||
if (!pCopy)
|
||||
@ -578,7 +717,7 @@ void AuMemoryView<Readonly_b>::DemoteFromSharedView(const AuSPtr<AuMemoryView<Re
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuSPtr<void> AuMemoryView<Readonly_b>::ToSharedControlBlock(bool *pbFailed)
|
||||
{
|
||||
if (pbFailed)
|
||||
@ -614,7 +753,7 @@ AuSPtr<void> AuMemoryView<Readonly_b>::ToSharedControlBlock(bool *pbFailed)
|
||||
return {};
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
AuUInt AuMemoryView<Readonly_b>::CopyInto(const AuMemoryView<false> &write) const
|
||||
{
|
||||
auto uLength = AuMin(this->uLength, write.uLength);
|
||||
@ -622,8 +761,8 @@ AuUInt AuMemoryView<Readonly_b>::CopyInto(const AuMemoryView<false> &write) cons
|
||||
return uLength;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<bool bThat, typename AuEnableIf<!bThat>::type *>
|
||||
template <bool Readonly_b>
|
||||
template <bool bThat, typename AuEnableIf<!bThat>::type *>
|
||||
inline AuUInt AuMemoryView<Readonly_b>::CopyFrom(const AuMemoryView<true> &read) const
|
||||
{
|
||||
auto uLength = AuMin(this->uLength, read.uLength);
|
||||
@ -631,19 +770,19 @@ inline AuUInt AuMemoryView<Readonly_b>::CopyFrom(const AuMemoryView<true> &read)
|
||||
return uLength;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr bool AuMemoryViewStream<Readonly_b>::HasMemory() const
|
||||
{
|
||||
return this->ptr && this->length;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
constexpr AuMemoryViewStream<Readonly_b>::operator bool() const
|
||||
{
|
||||
return HasMemory();
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template <bool Readonly_b>
|
||||
inline void AuMemoryViewStream<Readonly_b>::CopyStreamInto(const AuMemoryView<false> &write) const
|
||||
{
|
||||
auto uLength = AuMin(this->uLength, write.uLength);
|
||||
@ -651,8 +790,8 @@ inline void AuMemoryViewStream<Readonly_b>::CopyStreamInto(const AuMemoryView<fa
|
||||
this->outVariable = uLength;
|
||||
}
|
||||
|
||||
template<bool Readonly_b>
|
||||
template<bool bThat, typename AuEnableIf<!bThat>::type *>
|
||||
template <bool Readonly_b>
|
||||
template <bool bThat, typename AuEnableIf<!bThat>::type *>
|
||||
inline void AuMemoryViewStream<Readonly_b>::CopyStreamFrom(const AuMemoryView<true> &read) const
|
||||
{
|
||||
auto uLength = AuMin(this->uLength, read.uLength);
|
||||
|
Loading…
Reference in New Issue
Block a user