-
Notifications
You must be signed in to change notification settings - Fork 39
Improve Container Types #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mozz3d
wants to merge
25
commits into
wopss:master
Choose a base branch
from
Mozz3d:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4756017
Adjust file paths
Mozz3d 880f4bd
Improve Container Types
Mozz3d b6f4513
Fix include path
Mozz3d 937f56d
Adjustments
Mozz3d 6080dc9
Several improvements & adjustments
Mozz3d 00a2473
Fix mistake & ArrayIterator crediting
Mozz3d 3ae9d42
Fix errors
Mozz3d 9a904b4
Fix compiler warning
Mozz3d ca50d24
Several adjustments
Mozz3d 52c2085
Move SortedArray.hpp
Mozz3d 8d95b35
Adjust include in TweakDB.hpp
Mozz3d b837509
Fixes and cleanup
Mozz3d 4a0fa19
More adjustments
Mozz3d bd9f667
Several more improvments
Mozz3d bf62ff2
Some fixes and minor improvement
Mozz3d 6b00245
DynArray Buffer Move & Semantic Improvements
Mozz3d 27a4550
Fix errors
Mozz3d 619c6e5
Use `MoveEntries` only if `ValueType` is not trivially relocatable
Mozz3d 2835e65
Update `DynArray_Realloc` signature
Mozz3d 40ebc21
Fix instantiation (I think?)
Mozz3d 690fc40
Fix syntax
Mozz3d 5d88695
Fix my sheer stupidity
Mozz3d 0c9d751
Rename iterator based `Contains` to `Includes` & make private
Mozz3d 608b776
Fix StaticArray::Resize & improve empty check semantics
Mozz3d 674368e
Merge remote-tracking branch 'upstream/master' into pr/180
Mozz3d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cstdint> | ||
#include <stdexcept> | ||
|
||
#include <RED4ext/Common.hpp> | ||
#include <RED4ext/Detail/Containers/ArrayIterator.hpp> | ||
|
||
namespace RED4ext | ||
{ | ||
template<typename T> | ||
struct Span | ||
{ | ||
using ValueType = T; | ||
using Reference = ValueType&; | ||
using ConstReference = const Reference; | ||
using Pointer = ValueType*; | ||
using ConstPointer = const Pointer; | ||
|
||
using SizeType = std::uint32_t; | ||
using DifferenceType = std::ptrdiff_t; | ||
|
||
using Iterator = Detail::ArrayIterator<ValueType, Span>; | ||
using ConstIterator = Detail::ArrayIterator<const ValueType, Span>; | ||
using ReverseIterator = std::reverse_iterator<Iterator>; | ||
using ConstReverseIterator = std::reverse_iterator<ConstIterator>; | ||
|
||
Span() | ||
: beginPtr(nullptr) | ||
, endPtr(nullptr) | ||
{ | ||
} | ||
|
||
Span(Pointer aBegin, Pointer aEnd) | ||
: beginPtr(aBegin) | ||
, endPtr(aEnd) | ||
{ | ||
} | ||
|
||
Span(Pointer aBegin, SizeType aCount) | ||
: beginPtr(aBegin) | ||
, endPtr(aBegin + aCount) | ||
{ | ||
} | ||
|
||
constexpr Reference operator[](SizeType aIndex) | ||
{ | ||
assert(aIndex < Size()); | ||
return Data()[aIndex]; | ||
} | ||
|
||
constexpr ConstReference operator[](SizeType aIndex) const | ||
{ | ||
assert(aIndex < Size()); | ||
return Data()[aIndex]; | ||
} | ||
|
||
[[nodiscard]] constexpr Reference At(SizeType aIndex) | ||
{ | ||
if (aIndex >= Size()) | ||
throw std::out_of_range("Span::At: Position out of range"); | ||
|
||
return Data()[aIndex]; | ||
} | ||
|
||
[[nodiscard]] constexpr ConstReference At(SizeType aIndex) const | ||
{ | ||
if (aIndex >= Size()) | ||
throw std::out_of_range("Span::At: Position out of range"); | ||
|
||
return Data()[aIndex]; | ||
} | ||
|
||
[[nodiscard]] constexpr Iterator Find(ConstReference aValue) noexcept | ||
{ | ||
return Iterator(std::find(Begin(), End(), aValue)); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstIterator Find(ConstReference aValue) const noexcept | ||
{ | ||
return ConstIterator(std::find(Begin(), End(), aValue)); | ||
} | ||
|
||
[[nodiscard]] constexpr bool Contains(ConstReference aValue) const noexcept | ||
{ | ||
return Find(aValue) != End(); | ||
} | ||
|
||
[[nodiscard]] bool Contains(ConstIterator aPos) const noexcept | ||
{ | ||
return Begin() <= aPos && aPos <= End(); | ||
} | ||
|
||
[[nodiscard]] bool Contains(ConstIterator aFirst, ConstIterator aLast) const noexcept | ||
{ | ||
return Begin() <= (std::min)(aFirst, aLast) && (std::max)(aLast, aFirst) <= End(); | ||
} | ||
|
||
[[nodiscard]] constexpr Reference Front() | ||
{ | ||
assert(!Empty()); | ||
return Data()[0]; | ||
} | ||
|
||
[[nodiscard]] constexpr ConstReference Front() const | ||
{ | ||
assert(!Empty()); | ||
return Data()[0]; | ||
} | ||
|
||
[[nodiscard]] constexpr Reference Back() | ||
{ | ||
assert(!Empty()); | ||
return Data()[Size() - 1]; | ||
} | ||
|
||
[[nodiscard]] constexpr ConstReference Back() const | ||
{ | ||
assert(!Empty()); | ||
return Data()[Size() - 1]; | ||
} | ||
|
||
[[nodiscard]] constexpr Iterator Begin() noexcept | ||
{ | ||
return Iterator(beginPtr); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstIterator Begin() const noexcept | ||
{ | ||
return ConstIterator(beginPtr); | ||
} | ||
|
||
[[nodiscard]] constexpr Iterator End() noexcept | ||
{ | ||
return Iterator(endPtr); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstIterator End() const noexcept | ||
{ | ||
return ConstIterator(endPtr); | ||
} | ||
|
||
[[nodiscard]] constexpr ReverseIterator RBegin() noexcept | ||
{ | ||
return ReverseIterator(Begin()); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstReverseIterator RBegin() const noexcept | ||
{ | ||
return ConstReverseIterator(Begin()); | ||
} | ||
|
||
[[nodiscard]] constexpr ReverseIterator REnd() noexcept | ||
{ | ||
return ReverseIterator(End()); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstReverseIterator REnd() const noexcept | ||
{ | ||
return ConstReverseIterator(End()); | ||
} | ||
|
||
[[nodiscard]] constexpr bool Empty() const | ||
{ | ||
return Size() == 0; | ||
} | ||
|
||
[[nodiscard]] constexpr Pointer Data() noexcept | ||
{ | ||
return beginPtr; | ||
} | ||
|
||
[[nodiscard]] constexpr ConstPointer Data() const noexcept | ||
{ | ||
return beginPtr; | ||
} | ||
|
||
[[nodiscard]] constexpr DifferenceType Size() const | ||
{ | ||
return End() - Begin(); | ||
} | ||
|
||
T* beginPtr; // 00 | ||
T* endPtr; // 08 | ||
|
||
#pragma region STL | ||
[[nodiscard]] constexpr Iterator begin() noexcept | ||
{ | ||
return Begin(); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstIterator begin() const noexcept | ||
{ | ||
return Begin(); | ||
} | ||
|
||
[[nodiscard]] constexpr Iterator end() noexcept | ||
{ | ||
return End(); | ||
} | ||
|
||
[[nodiscard]] constexpr ConstIterator end() const noexcept | ||
{ | ||
return End(); | ||
} | ||
#pragma endregion | ||
}; | ||
RED4EXT_ASSERT_SIZE(Span<int32_t>, 0x10); | ||
RED4EXT_ASSERT_OFFSET(Span<int32_t>, beginPtr, 0x0); | ||
RED4EXT_ASSERT_OFFSET(Span<int32_t>, endPtr, 0x8); | ||
} // namespace RED4ext |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.