Skip to content

Commit

Permalink
wrappers for targeting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pasotee committed May 15, 2024
1 parent 5f10108 commit 085f36a
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 11 deletions.
89 changes: 89 additions & 0 deletions Source/ConfigCat/Private/Wrapper/ConfigCatTargetingRuleWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

#include "Wrapper/ConfigCatTargetingRuleWrapper.h"

#include "Wrappers/ConfigCatSettingValueContainerWrapper.h"
#include "Wrappers/ConfigCatPercentageOptionWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"


UConfigCatUserConditionWrapper* UConfigCatUserConditionWrapper::CreateUserCondition(const configcat::UserCondition& InUserCondition)
{
UConfigCatUserConditionWrapper* Result = NewObject<UConfigCatUserConditionWrapper>();
Result->UserCondition = InUserCondition;
return Result;
}

FString UConfigCatUserConditionWrapper::GetComparisonAttribute() const
{
return UTF8_TO_TCHAR(UserCondition.comparisonAttribute.c_str());
}

EConfigCatUserComparator UConfigCatUserConditionWrapper::GetComparator() const
{
if (static_cast<int32>(UserCondition.comparator) < 0)
{
return EConfigCatUserComparator::Invalid;
}

return static_cast<EConfigCatUserComparator>(UserCondition.comparator);
}

Expand All @@ -33,13 +47,25 @@ TArray<FString> UConfigCatUserConditionWrapper::GetStringArrayComparisonValue()
return {};
}

UConfigCatPrerequisiteFlagConditionWrapper* UConfigCatPrerequisiteFlagConditionWrapper::CreatePrerequisiteFlagCondition(const configcat::PrerequisiteFlagCondition& InPrerequisiteFlagCondition)
{
UConfigCatPrerequisiteFlagConditionWrapper* Result = NewObject<UConfigCatPrerequisiteFlagConditionWrapper>();
Result->PrerequisiteFlagCondition = InPrerequisiteFlagCondition;
return Result;
}

FString UConfigCatPrerequisiteFlagConditionWrapper::GetPrerequisiteFlagKey() const
{
return UTF8_TO_TCHAR(PrerequisiteFlagCondition.prerequisiteFlagKey.c_str());
}

EConfigCatPrerequisiteFlagComparator UConfigCatPrerequisiteFlagConditionWrapper::GetComparator() const
{
if (static_cast<int32>(PrerequisiteFlagCondition.comparator) < 0)
{
return EConfigCatPrerequisiteFlagComparator::Invalid;
}

return static_cast<EConfigCatPrerequisiteFlagComparator>(PrerequisiteFlagCondition.comparator);
}

Expand All @@ -48,13 +74,25 @@ UConfigCatValueWrapper* UConfigCatPrerequisiteFlagConditionWrapper::GetCompariso
return UConfigCatValueWrapper::CreateValue(PrerequisiteFlagCondition.comparisonValue);
}

UConfigCatSegmentConditionWrapper* UConfigCatSegmentConditionWrapper::CreateSegmentCondition(const configcat::SegmentCondition& InSegmentCondition)
{
UConfigCatSegmentConditionWrapper* Result = NewObject<UConfigCatSegmentConditionWrapper>();
Result->SegmentCondition = InSegmentCondition;
return Result;
}

int32 UConfigCatSegmentConditionWrapper::GetSegmentIndex() const
{
return SegmentCondition.segmentIndex;
}

EConfigCatSegmentComparator UConfigCatSegmentConditionWrapper::GetComparator() const
{
if (static_cast<int32>(SegmentCondition.comparator) < 0)
{
return EConfigCatSegmentComparator::Invalid;
}

return static_cast<EConfigCatSegmentComparator>(SegmentCondition.comparator);
}

Expand All @@ -64,3 +102,54 @@ UConfigCatTargetingRuleWrapper* UConfigCatTargetingRuleWrapper::CreateTargetingR
Result->TargetingRule = InTargetingRule;
return Result;
}

TArray<FConfigCatConditionContainer> UConfigCatTargetingRuleWrapper::GetConditions() const
{
TArray<FConfigCatConditionContainer> Result;

for (const configcat::ConditionContainer& ConditionContainer : TargetingRule.conditions)
{
FConfigCatConditionContainer NewCondition;
const auto& Condition = ConditionContainer.condition;
if (std::holds_alternative<configcat::UserCondition>(Condition))
{
const configcat::UserCondition& UserCondition = std::get<configcat::UserCondition>(Condition);
NewCondition.UserCondition = nullptr;
Result.Add(NewCondition);
}
else if (std::holds_alternative<configcat::PrerequisiteFlagCondition>(Condition))
{
const configcat::PrerequisiteFlagCondition& PrerequisiteFlagCondition = std::get<configcat::PrerequisiteFlagCondition>(Condition);
NewCondition.PrerequisiteFlagCondition = nullptr;
Result.Add(NewCondition);
}
else if (std::holds_alternative<configcat::SegmentCondition>(Condition))
{
const configcat::SegmentCondition& SegmentCondition = std::get<configcat::SegmentCondition>(Condition);
NewCondition.SegmentCondition = nullptr;
Result.Add(NewCondition);
}
}

return Result;
}

FConfigCatThenContainer UConfigCatTargetingRuleWrapper::GetThen() const
{
FConfigCatThenContainer Result;
if (std::holds_alternative<configcat::SettingValueContainer>(TargetingRule.then))
{
const configcat::SettingValueContainer& SettingValueContainer = std::get<configcat::SettingValueContainer>(TargetingRule.then);
Result.SettingValueContainer = UConfigCatSettingValueContainerWrapper::CreateSettingValue(SettingValueContainer);
}
else if (std::holds_alternative<configcat::PercentageOptions>(TargetingRule.then))
{
const auto& PercentageOptions = std::get<configcat::PercentageOptions>(TargetingRule.then);
for (const auto& PercentageOption : PercentageOptions)
{
Result.PercentageOptions.Add(UConfigCatPercentageOptionWrapper::CreatePercentageOption(PercentageOption));
}
}

return Result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "Wrappers/ConfigCatSettingValueContainerWrapper.h"

#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatSettingValueContainerWrapper* UConfigCatSettingValueContainerWrapper::CreateSettingValue(const configcat::SettingValueContainer& SettingValueContainer)
{
UConfigCatSettingValueContainerWrapper* Result = NewObject<UConfigCatSettingValueContainerWrapper>();
Result->SettingValueContainer = SettingValueContainer;
return Result;
}

FString UConfigCatSettingValueContainerWrapper::GetVariationId() const
{
if (SettingValueContainer.variationId.has_value())
{
return UTF8_TO_TCHAR(SettingValueContainer.variationId.value().c_str());
}

return {};
}

UConfigCatValueWrapper* UConfigCatSettingValueContainerWrapper::GetValue() const
{
return UConfigCatValueWrapper::CreateValue(SettingValueContainer.value);
}
81 changes: 70 additions & 11 deletions Source/ConfigCat/Public/Wrapper/ConfigCatTargetingRuleWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

#include "ConfigCatTargetingRuleWrapper.generated.h"

class UConfigCatSettingValueContainerWrapper;
class UConfigCatPercentageOptionWrapper;
class UConfigCatValueWrapper;

enum class EConfigCatUserComparator
UENUM(BlueprintType)
enum class EConfigCatUserComparator : uint8
{
Invalid = -1,
TextIsOneOf = 0,
TextIsNotOneOf = 1,
TextContainsAnyOf = 2,
Expand Down Expand Up @@ -48,51 +49,108 @@ enum class EConfigCatUserComparator
TextNotEndsWithAnyOf = 33,
ArrayContainsAnyOf = 34,
ArrayNotContainsAnyOf = 35,

Invalid
};

UCLASS(DisplayName="Config Cat User Condition", Hidden)
class UConfigCatUserConditionWrapper : public UObject
{
GENERATED_BODY()

public:
static UConfigCatUserConditionWrapper* CreateUserCondition(const configcat::UserCondition& InUserCondition);

UFUNCTION(BlueprintPure, Category = "ConfigCat|UserCondition")
FString GetComparisonAttribute() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|UserCondition")
EConfigCatUserComparator GetComparator() const;

UFUNCTION(BlueprintPure, Category = "ConfigCat|UserCondition")
FString GetStringComparisonValue() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|UserCondition")
double GetNumberComparisonValue() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|UserCondition")
TArray<FString> GetStringArrayComparisonValue() const;

configcat::UserCondition UserCondition;
};

enum class EConfigCatPrerequisiteFlagComparator
UENUM(BlueprintType)
enum class EConfigCatPrerequisiteFlagComparator : uint8
{
Invalid = -1,
Equals = 0,
NotEquals = 1
NotEquals = 1,
Invalid
};

UCLASS(DisplayName="Config Cat Prerequisite Flag Condition", Hidden)
class UConfigCatPrerequisiteFlagConditionWrapper : public UObject
{
GENERATED_BODY()

public:
static UConfigCatPrerequisiteFlagConditionWrapper* CreatePrerequisiteFlagCondition(const configcat::PrerequisiteFlagCondition& InPrerequisiteFlagCondition);

UFUNCTION(BlueprintPure, Category = "ConfigCat|PrerequisiteFlagCondition")
FString GetPrerequisiteFlagKey() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|PrerequisiteFlagCondition")
EConfigCatPrerequisiteFlagComparator GetComparator() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|PrerequisiteFlagCondition")
UConfigCatValueWrapper* GetComparisonValue() const;

configcat::PrerequisiteFlagCondition PrerequisiteFlagCondition;
};

enum class EConfigCatSegmentComparator
UENUM(BlueprintType)
enum class EConfigCatSegmentComparator : uint8
{
Invalid = -1,
IsIn = 0,
IsNotIn = 2,
IsNotIn = 1,
Invalid
};

UCLASS(DisplayName="Config Cat Segment Condition", Hidden)
class UConfigCatSegmentConditionWrapper : public UObject
{
GENERATED_BODY()

public:
static UConfigCatSegmentConditionWrapper* CreateSegmentCondition(const configcat::SegmentCondition& InSegmentCondition);

UFUNCTION(BlueprintPure, Category = "ConfigCat|SegmentCondition")
int32 GetSegmentIndex() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|SegmentCondition")
EConfigCatSegmentComparator GetComparator() const;

configcat::SegmentCondition SegmentCondition;
};

USTRUCT(BlueprintType)
struct FConfigCatConditionContainer
{
GENERATED_BODY()

UPROPERTY(BlueprintReadOnly, Category = "ConfigCat|ConditionContainer")
UConfigCatUserConditionWrapper* UserCondition;
UPROPERTY(BlueprintReadOnly, Category = "ConfigCat|ConditionContainer")
UConfigCatPrerequisiteFlagConditionWrapper* PrerequisiteFlagCondition;
UPROPERTY(BlueprintReadOnly, Category = "ConfigCat|ConditionContainer")
UConfigCatSegmentConditionWrapper* SegmentCondition;
};

USTRUCT(BlueprintType)
struct FConfigCatThenContainer
{
GENERATED_BODY()

UPROPERTY(BlueprintReadOnly, Category = "ConfigCat|ThenContainer")
UConfigCatSettingValueContainerWrapper* SettingValueContainer = nullptr;

UPROPERTY(BlueprintReadOnly, Category = "ConfigCat|ThenContainer")
TArray<UConfigCatPercentageOptionWrapper*> PercentageOptions;
};

UCLASS(DisplayName="Config Cat Targeting Rule", Hidden)
class UConfigCatTargetingRuleWrapper : public UObject
{
Expand All @@ -101,9 +159,10 @@ class UConfigCatTargetingRuleWrapper : public UObject
public:
static UConfigCatTargetingRuleWrapper* CreateTargetingRule(const configcat::TargetingRule& InTargetingRule);

// TArray<UConfigCatConditionWrapper*> GetConditions() const;
UConfigCatValueWrapper* GetThenSettingValue() const;
TArray<UConfigCatPercentageOptionWrapper*> GetThenPercentageOptions() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|TargetingRule")
TArray<FConfigCatConditionContainer> GetConditions() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|TargetingRule")
FConfigCatThenContainer GetThen() const;

configcat::TargetingRule TargetingRule;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#pragma once

#include <ConfigCatCppSDK/Include/config.h>

#include "UObject/Object.h"

#include "ConfigCatSettingValueContainerWrapper.generated.h"

class UConfigCatValueWrapper;
UCLASS(DisplayName="Config Cat Setting Value Container", Hidden)
class CONFIGCAT_API UConfigCatSettingValueContainerWrapper : public UObject
{
GENERATED_BODY()

public:
static UConfigCatSettingValueContainerWrapper* CreateSettingValue(const configcat::SettingValueContainer& SettingValueContainer);

UFUNCTION(BlueprintPure, Category = "ConfigCat|SettingValueContainer")
FString GetVariationId() const;
UFUNCTION(BlueprintPure, Category = "ConfigCat|SettingValueContainer")
UConfigCatValueWrapper* GetValue() const;

configcat::SettingValueContainer SettingValueContainer;
};

0 comments on commit 085f36a

Please sign in to comment.