From 444804d1a6bb82b240eb741d2835bb28dd43440b Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sun, 1 Sep 2024 19:43:22 +0100 Subject: [PATCH] [*] Remove redundant constructor from UTF8 iterator [+] Missing members on AuArray --- Include/auROXTL/Iterators/auRONString.hpp | 2 - Include/auROXTL/Iterators/auROString.hpp | 4 +- Include/auROXTL/Iterators/auUTF8Iterator.hpp | 2 - Include/auROXTL/Iterators/auUTF8Iterator.ipp | 12 +- Include/auROXTL/auArray.hpp | 186 ++++++++++++++++++- 5 files changed, 181 insertions(+), 25 deletions(-) diff --git a/Include/auROXTL/Iterators/auRONString.hpp b/Include/auROXTL/Iterators/auRONString.hpp index cab697f..3492c51 100644 --- a/Include/auROXTL/Iterators/auRONString.hpp +++ b/Include/auROXTL/Iterators/auRONString.hpp @@ -8,8 +8,6 @@ ***/ #pragma once - - /* read-only, null terminated, utf-8 *byte* view */ struct AuRONString { diff --git a/Include/auROXTL/Iterators/auROString.hpp b/Include/auROXTL/Iterators/auROString.hpp index 41f1421..8a4f432 100644 --- a/Include/auROXTL/Iterators/auROString.hpp +++ b/Include/auROXTL/Iterators/auROString.hpp @@ -23,8 +23,8 @@ struct AuROString using const_reference = const char &; using const_iterator = const char *; using iterator = char *; - using const_reverse_iterator = typename std::reverse_iterator; - using reverse_iterator = typename std::reverse_iterator; + using const_reverse_iterator = typename AuReverseIterator; + using reverse_iterator = typename AuReverseIterator; using size_type = AuUInt; using difference_type = AuSInt; diff --git a/Include/auROXTL/Iterators/auUTF8Iterator.hpp b/Include/auROXTL/Iterators/auUTF8Iterator.hpp index 5f4402d..f9add19 100644 --- a/Include/auROXTL/Iterators/auUTF8Iterator.hpp +++ b/Include/auROXTL/Iterators/auUTF8Iterator.hpp @@ -30,8 +30,6 @@ struct AuUTF8Iterator inline AuUTF8Iterator(const AuROString &in, AuUInt uOffset = AuROString::npos); - inline AuUTF8Iterator(const AuROString &in); - cstatic AuUTF8Iterator FromStringView(AuROString in, AuUInt uOffset = AuROString::npos); inline constexpr const char *base() const; diff --git a/Include/auROXTL/Iterators/auUTF8Iterator.ipp b/Include/auROXTL/Iterators/auUTF8Iterator.ipp index b7683ee..6841cc1 100644 --- a/Include/auROXTL/Iterators/auUTF8Iterator.ipp +++ b/Include/auROXTL/Iterators/auUTF8Iterator.ipp @@ -50,7 +50,7 @@ inline AuUTF8Iterator::AuUTF8Iterator(const char *pStart) inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in, AuUInt uOffset) { this->baseView = in; - this->pCurrent = in.Begin(); + this->pCurrent = in.Begin(); if (uOffset != AuROString::npos) { @@ -66,12 +66,6 @@ inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in, AuUInt uOffset) } } -inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in) -{ - this->baseView = in; - this->pCurrent = in.Begin(); -} - AuUTF8Iterator AuUTF8Iterator::FromStringView(AuROString in, AuUInt uOffset) { return AuUTF8Iterator(in, uOffset); @@ -220,7 +214,7 @@ inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator+=(const difference_typ auto pNext = pBegin + uDiff; auto uNext = uLength - uDiff; - for (AU_ITERATE_N(i, offset)) + for (AU_ITERATE_N(i, AuUInt(offset))) { if (auto uCount = AuCodepointsNextLength(AuROString(pNext, uNext))) { @@ -263,7 +257,7 @@ inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator-=(const difference_typ return *this; } - for (AU_ITERATE_N(i, offset)) + for (AU_ITERATE_N(i, AuUInt(offset))) { auto uOffset = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(this->baseView, uDiff); if (uOffset != AuString::npos) diff --git a/Include/auROXTL/auArray.hpp b/Include/auROXTL/auArray.hpp index fc3e272..06f572d 100644 --- a/Include/auROXTL/auArray.hpp +++ b/Include/auROXTL/auArray.hpp @@ -19,19 +19,22 @@ struct AuArray static const AuUInt kElementCount = Count; - using value_type = T; + using value_type = T; - using size_type = AuUInt; - using difference_type = AuSInt; + using size_type = AuUInt; + using difference_type = AuSInt; - using pointer = value_type *; - using const_pointer = const value_type *; + using pointer = value_type *; + using const_pointer = const value_type *; - using reference = value_type &; - using const_reference = const value_type &; + using reference = value_type &; + using const_reference = const value_type &; - using iterator = pointer; - using const_iterator = const_pointer; + using iterator = pointer; + using const_iterator = const_pointer; + + using reverse_iterator = typename AuReverseIterator; + using const_reverse_iterator = typename AuReverseIterator; void fill(const T &value) { @@ -48,11 +51,16 @@ struct AuArray } } + void Fill(const T &value) + { + this->fill(value); + } + void swap(AuArray &other) { AuArray temp; - if constexpr (std::is_trivially_copyable_v) + if constexpr (AuIsTriviallyCopyable_v) { AuMemcpy(temp, this->elements, sizeof(this->elements)); AuMemcpy(this->elements, other.elements, sizeof(this->elements)); @@ -77,6 +85,11 @@ struct AuArray } } } + + void Swap(AuArray &other) + { + this->swap(other); + } constexpr iterator begin() { @@ -88,6 +101,16 @@ struct AuArray return this->elements; } + constexpr iterator Begin() + { + return this->elements; + } + + constexpr const_iterator Begin() const + { + return this->elements; + } + constexpr iterator end() { return this->elements + kElementCount; @@ -98,6 +121,16 @@ struct AuArray return this->elements + kElementCount; } + constexpr iterator End() + { + return this->elements + kElementCount; + } + + constexpr const_iterator End() const + { + return this->elements + kElementCount; + } + constexpr const_iterator cbegin() const { return begin(); @@ -108,21 +141,101 @@ struct AuArray return end(); } + constexpr const_iterator CBegin() const + { + return begin(); + } + + constexpr const_iterator CEnd() const + { + return end(); + } + + constexpr const_reverse_iterator rbegin() const + { + return reverse_iterator(end()); + } + + constexpr reverse_iterator RBegin() + { + return reverse_iterator(end()); + } + + constexpr const_reverse_iterator RBegin() const + { + return const_reverse_iterator(end()); + } + + constexpr reverse_iterator rend() + { + return reverse_iterator(begin()); + } + + constexpr const_reverse_iterator rend() const + { + return reverse_iterator(begin()); + } + + constexpr reverse_iterator REnd() + { + return const_reverse_iterator(begin()); + } + + constexpr const_reverse_iterator REnd() const + { + return const_reverse_iterator(begin()); + } + + constexpr const_reverse_iterator crbegin() const + { + return const_reverse_iterator(end()); + } + + constexpr const_reverse_iterator crend() const + { + return const_reverse_iterator(begin()); + } + + constexpr const_reverse_iterator CRBegin() const + { + return const_reverse_iterator(end()); + } + + constexpr const_reverse_iterator CREnd() const + { + return const_reverse_iterator(begin()); + } + constexpr size_type size() const { return kElementCount; } + constexpr size_type Size() const + { + return kElementCount; + } + constexpr size_type max_size() const { return kElementCount; } + constexpr size_type MaxSize() const + { + return kElementCount; + } + constexpr bool empty() const { return false; } + constexpr bool Empty() const + { + return false; + } + reference at(size_type pos) { #if defined(AU_CFG_ID_DEBUG) @@ -146,6 +259,29 @@ struct AuArray return this->elements[pos]; } + reference At(size_type pos) + { + #if defined(AU_CFG_ID_DEBUG) + if (pos >= kElementCount) + { + AuMemoryPanic("out of bounds access"); + } + #endif + + return this->elements[pos]; + } + + constexpr const_reference At(size_type pos) const + { + #if defined(AU_CFG_ID_DEBUG) + if (pos >= kElementCount) + { + AuMemoryPanic("out of bounds access"); + } + #endif + return this->elements[pos]; + } + reference operator[](size_type pos) { #if defined(AU_CFG_ID_DEBUG) @@ -190,6 +326,26 @@ struct AuArray return this->elements[Count - 1]; } + constexpr reference Front() + { + return this->elements[0]; + } + + constexpr const_reference Front() const + { + return this->elements[0]; + } + + constexpr reference Back() + { + return this->elements[Count - 1]; + } + + constexpr const_reference Back() const + { + return this->elements[Count - 1]; + } + constexpr T *data() { return this->elements; @@ -200,6 +356,16 @@ struct AuArray return this->elements; } + constexpr T *Data() + { + return this->elements; + } + + constexpr const T *Data() const + { + return this->elements; + } + // oh look, its that feature in that nearly 30 year old programming language intended to replace xerox alto's OOP language for the internet era. AuUInt HashCode() const {