Last active
September 8, 2019 22:46
-
-
Save jign/46bd13eecba508fbc57772fa9a4e5d32 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org> | |
*/ | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "Kismet/BlueprintFunctionLibrary.h" | |
#include "GameplayTags.h" | |
#include <type_traits> | |
#include "FlipLibrary.generated.h" | |
// Flipside Standard Library | |
namespace fstd { | |
/** Implementation of C++17's conjunction. Performs a logical AND on the sequence of traits */ | |
template<typename...> struct conjunction : std::true_type { }; | |
template<typename B1> struct conjunction<B1> : B1 { }; | |
template<typename B1, typename... Bn> struct conjunction<B1, Bn...> : | |
std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type { }; | |
/** Implementation of C++17's disjunction. Performs a logical OR on the sequence of traits */ | |
template<typename...> struct disjunction : std::false_type { }; | |
template<typename B1> struct disjunction<B1> : B1 { }; | |
template<typename B1, typename... Bn> struct disjunction<B1, Bn...> : | |
std::conditional<bool(B1::value), B1, disjunction<Bn...>>::type { }; | |
} | |
/** | |
* | |
*/ | |
UCLASS() | |
class FLIPSIDE_API UFlipLibrary : public UBlueprintFunctionLibrary | |
{ | |
GENERATED_BODY() | |
public: | |
/** Checks if all the tags are in the container, accepts either FGameplayTags or strings, returns true if all tags are present */ | |
template<typename... Args> | |
static bool ContainerHasAllTags(const FGameplayTagContainer* Container, Args... TagsToCheck) | |
{ | |
static_assert( | |
fstd::disjunction< | |
fstd::conjunction<std::is_same<const char*, Args>... >, | |
fstd::conjunction<std::is_same<FGameplayTag, Args>...>>::value, | |
"'Args' must be of either type 'const char*' or 'FGameplayTag'"); | |
return ContainerHasAllTagsImpl(Container, TagsToCheck...); | |
} | |
private: | |
static bool ContainerHasAllTagsImpl(const FGameplayTagContainer* Container, FGameplayTag Tag) | |
{ | |
return Container->HasTag(Tag); | |
} | |
static bool ContainerHasAllTagsImpl(const FGameplayTagContainer* Container, const char* Tag) | |
{ | |
const auto FoundTag{ UGameplayTagsManager::Get().RequestGameplayTag(FName(Tag)) }; | |
return Container->HasTag(FoundTag); | |
} | |
template<typename... Args> | |
static bool ContainerHasAllTagsImpl(const FGameplayTagContainer* Container, FGameplayTag FirstTag, Args... OtherTags) | |
{ | |
return ContainerHasAllTagsImpl(Container, FirstTag) && ContainerHasAllTagsImpl(Container, OtherTags...); | |
} | |
template<typename... Args> | |
static bool ContainerHasAllTagsImpl(const FGameplayTagContainer* Container, const char* FirstTag, Args... OtherTags) | |
{ | |
return ContainerHasAllTagsImpl(Container, FirstTag) && ContainerHasAllTagsImpl(Container, OtherTags...); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment