Skip to content

Commit

Permalink
#253 Added FromIterator Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat committed Mar 18, 2024
1 parent 3e976d8 commit 3abd6d0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ FVector UCloud9ToolsLibrary::VInterpTo(
ClampLerp(Current.Z, Dist.Z, Alpha.Z, Target.Z),
};
}

TArray<FString> UCloud9ToolsLibrary::GetObjectEditorProperties(UClass* Class)
{
if (IsValid(Class))
{
return TFieldIterator<FProperty>(Class)
| ETContainer::FromIterator{}
| ETContainer::Filter{[](let& It) { return It.HasAnyPropertyFlags(CPF_Edit); }}
| ETContainer::Transform{[](let& It) { return It.GetName(); }}
| ETContainer::ToArray{};
}

log(Error, "Input class is invalid");
return {};
}
2 changes: 2 additions & 0 deletions Source/Cloud9/Tools/Cloud9ToolsLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ class CLOUD9_API UCloud9ToolsLibrary : public UBlueprintFunctionLibrary
const FVector Target,
float DeltaTime,
const FVector InterpSpeed);

static TArray<FString> GetObjectEditorProperties(UClass* Class);
};
2 changes: 1 addition & 1 deletion Source/Cloud9/Tools/Containers/Sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TSequence
/**
* Function returns current underlying Iterator value.
*/
ElementType operator*() const { return *Iterator; }
const ElementType& operator*() { return *Iterator; }

/**
* Function returns false if sequence is empty.
Expand Down
60 changes: 55 additions & 5 deletions Source/Cloud9/Tools/Extensions/TContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace ETIterator

namespace Private_ETContainer
{
template <typename OperatorType, typename ContainerType>
struct TFromIteratorIterator;

template <typename OperatorType, typename ContainerType>
struct TTransformIterator;

Expand All @@ -77,6 +80,19 @@ namespace Private_ETContainer

namespace ETContainer
{
struct FromIterator
{
template <typename ElementType>
constexpr auto operator()(TFieldIterator<ElementType>&& Self) const
{
using FIteratorType = TFieldIterator<ElementType>;
var Iterator = Private_ETContainer::TFromIteratorIterator<ElementType, FIteratorType>(Self);
return TSequence<ElementType, decltype(Iterator)>(MoveTemp(Iterator));
}

OPERATOR_BODY(FromIterator)
};

struct Random
{
template <typename ContainerType, typename ElementType = typename ContainerType::ElementType>
Expand Down Expand Up @@ -299,6 +315,33 @@ namespace ETContainer

namespace Private_ETContainer
{
template <typename InElementType, typename InIteratorType>
struct TFromIteratorIterator
{
using IteratorType = InIteratorType;
using ElementType = InElementType;

constexpr explicit TFromIteratorIterator(IteratorType Iterator): Iterator(Iterator) {}

// ReSharper disable once CppMemberFunctionMayBeStatic
constexpr void Initialize() {}

constexpr TFromIteratorIterator& operator++()
{
++Iterator;
return *this;
}

constexpr const ElementType& operator*() { return **Iterator; }

// constexpr ElementType operator*() { return **Iterator; }

constexpr explicit operator bool() const { return not Iterator; }

private:
IteratorType Iterator;;
};

template <typename OperatorType, typename ContainerType>
struct TTransformIterator
{
Expand All @@ -323,7 +366,11 @@ namespace Private_ETContainer

// constexpr const ElementType& operator->() const { return Iterator; }

constexpr ElementType operator*() const { return Operator.Operation(*Iterator); }
constexpr const ElementType& operator*()
{
Cache = Operator.Operation(*Iterator);
return *Cache;
}

constexpr explicit operator bool() const { return not Iterator; }

Expand All @@ -333,6 +380,8 @@ namespace Private_ETContainer
ContainerType Container;
IteratorType Iterator;
OperatorType Operator;

TOptional<ElementType> Cache;
};

template <typename OperatorType, typename ContainerType>
Expand All @@ -356,7 +405,7 @@ namespace Private_ETContainer

constexpr const ElementType& operator->() const { return Iterator; }

constexpr ElementType operator*() const { return *Iterator; }
constexpr const ElementType& operator*() { return *Iterator; }

constexpr explicit operator bool() const { return not Iterator; }

Expand All @@ -371,7 +420,8 @@ namespace Private_ETContainer

if (not bIsFound)
{
while (Iterator and not Operator.Predicate(*Iterator))
let& Value = *Iterator;
while (Iterator and not Operator.Predicate(Value))
{
++Iterator;
}
Expand Down Expand Up @@ -416,7 +466,7 @@ namespace Private_ETContainer

constexpr const ElementType& operator->() const { return Iterator; }

constexpr ElementType operator*() const { return *Iterator; }
constexpr const ElementType& operator*() { return *Iterator; }

constexpr explicit operator bool() const { return not Iterator; }

Expand Down Expand Up @@ -449,7 +499,7 @@ namespace Private_ETContainer

constexpr const ElementType& operator->() const { return Iterator; }

constexpr ElementType operator*() const { return *Iterator; }
constexpr const ElementType& operator*() { return *Iterator; }

constexpr explicit operator bool() const
{
Expand Down

0 comments on commit 3abd6d0

Please sign in to comment.