Skip to content

Commit

Permalink
removed dedicated wrappers module + refactor to allow a single includ…
Browse files Browse the repository at this point in the history
…e in examples
  • Loading branch information
pasotee committed Jul 25, 2024
1 parent 82f69f2 commit 7f7d00f
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 111 deletions.
6 changes: 0 additions & 6 deletions ConfigCat.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"LoadingPhase": "PreDefault",
"PlatformAllowList": [ "Win64", "Mac", "Linux", "Android", "iOS" ]
},
{
"Name": "ConfigCatWrappers",
"Type": "Runtime",
"LoadingPhase": "PreDefault",
"PlatformAllowList": [ "Win64", "Mac", "Linux", "Android", "iOS" ]
},
{
"Name": "ConfigCatEditor",
"Type": "Editor",
Expand Down
1 change: 0 additions & 1 deletion Source/ConfigCat/ConfigCat.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public ConfigCat(ReadOnlyTargetRules Target) : base(Target)

PrivateDependencyModuleNames.AddRange(new[]
{
"ConfigCatWrappers",
"ConfigCatCppSdk"
});

Expand Down
8 changes: 4 additions & 4 deletions Source/ConfigCat/Private/ConfigCatSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "ConfigCatLogger.h"
#include "ConfigCatNetworkAdapter.h"
#include "ConfigCatSettings.h"
#include "ConfigCatSettingsWrapper.h"
#include "ConfigCatEvaluationWrapper.h"
#include "ConfigCatUserWrapper.h"
#include "ConfigCatValueWrapper.h"

#include "Wrappers/ConfigCatSettingsWrapper.h"
#include "Wrappers/ConfigCatEvaluationWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

using namespace configcat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatEvaluationWrapper.h"
#include "Wrappers/ConfigCatEvaluationWrapper.h"

#include "ConfigCatCppSDK/Include/log.h"

#include "ConfigCatPercentageOptionWrapper.h"
#include "ConfigCatTargetingRuleWrapper.h"
#include "ConfigCatUserWrapper.h"
#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatPercentageOptionWrapper.h"
#include "Wrappers/ConfigCatTargetingRuleWrapper.h"
#include "Wrappers/ConfigCatUserWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatEvaluationWrapper* UConfigCatEvaluationWrapper::CreateEvaluation(const configcat::EvaluationDetailsBase& InEvaluationDetails)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

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

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

UConfigCatPercentageOptionWrapper* UConfigCatPercentageOptionWrapper::CreatePercentageOption(const configcat::PercentageOption& InPercentageOption)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

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

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

UConfigCatSettingValueContainerWrapper* UConfigCatSettingValueContainerWrapper::CreateSettingValue(const configcat::SettingValueContainer& SettingValueContainer)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatSettingsWrapper.h"
#include "Wrappers/ConfigCatSettingsWrapper.h"

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

using namespace configcat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatTargetingRuleWrapper.h"
#include "Wrappers/ConfigCatTargetingRuleWrapper.h"

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

UConfigCatUserConditionWrapper* UConfigCatUserConditionWrapper::CreateUserCondition(const configcat::UserCondition& InUserCondition)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatUserWrapper.h"
#include "Wrappers/ConfigCatUserWrapper.h"

#include <ConfigCatCppSDK/Include/configcatuser.h>

using namespace configcat;

namespace
{
const ConfigCatUser::AttributeValue* GetUserAttributeForKey(const std::shared_ptr<ConfigCatUser>& User, const FString& Key)
{
if (!User)
{
return {};
}

const std::string AttributeKey = TCHAR_TO_UTF8(*Key);
return User->getAttribute(AttributeKey);
}
}

UConfigCatUserWrapper* UConfigCatUserWrapper::CreateUser(const FString& Id, const FString& Email, const FString& Country, const TMap<FString, FString>& Attributes)
{
const std::string& UserId = TCHAR_TO_UTF8(*Id);
Expand Down Expand Up @@ -50,7 +64,7 @@ FString UConfigCatUserWrapper::GetStringAttribute(const FString& Key) const
{
if (HasStringAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return UTF8_TO_TCHAR(std::get<std::string>(*Attribute).c_str());
}

Expand All @@ -61,7 +75,7 @@ double UConfigCatUserWrapper::GetNumberAttribute(const FString& Key) const
{
if (HasNumberAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return std::get<double>(*Attribute);
}

Expand All @@ -72,7 +86,7 @@ FDateTime UConfigCatUserWrapper::GetTimeAttribute(const FString& Key) const
{
if (HasTimeAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
const auto TimeSinceEpoch = std::get<date_time_t>(*Attribute).time_since_epoch().count();
return FDateTime::FromUnixTimestamp(TimeSinceEpoch);
}
Expand All @@ -84,7 +98,7 @@ TArray<FString> UConfigCatUserWrapper::GetStringArrayAttribute(const FString& Ke
{
if (HasStringArrayAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
TArray<FString> Result;
const std::vector<std::string> ArrayAttribute = std::get<std::vector<std::string>>(*Attribute);
for (const std::string& ArrayIt : ArrayAttribute)
Expand All @@ -104,35 +118,24 @@ bool UConfigCatUserWrapper::HasAnyAttribute(const FString& Key) const

bool UConfigCatUserWrapper::HasStringAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<std::string>(*Attribute);
}

bool UConfigCatUserWrapper::HasNumberAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<double>(*Attribute);
}

bool UConfigCatUserWrapper::HasTimeAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<date_time_t>(*Attribute);
}

bool UConfigCatUserWrapper::HasStringArrayAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<std::vector<std::string>>(*Attribute);
}

const ConfigCatUser::AttributeValue* UConfigCatUserWrapper::GetUserAttributeForKey(const FString& Key) const
{
if (!User)
{
return {};
}

const std::string AttributeKey = TCHAR_TO_UTF8(*Key);
return User->getAttribute(AttributeKey);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

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

UConfigCatValueWrapper* UConfigCatValueWrapper::CreateValue(const configcat::SettingValue& InValue)
{
Expand Down
2 changes: 2 additions & 0 deletions Source/ConfigCat/Public/ConfigCatSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <Subsystems/GameInstanceSubsystem.h>
#include <memory>

#include "Wrappers/ConfigCatUserWrapper.h"

#include "ConfigCatSubsystem.generated.h"

class UConfigCatSettingsWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UConfigCatUserWrapper;
class UConfigCatValueWrapper;

UCLASS(DisplayName="Config Cat Evaluation")
class CONFIGCATWRAPPERS_API UConfigCatEvaluationWrapper : public UObject
class CONFIGCAT_API UConfigCatEvaluationWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class UConfigCatValueWrapper;

UCLASS(DisplayName="Config Cat Percentage Option")
class CONFIGCATWRAPPERS_API UConfigCatPercentageOptionWrapper : public UObject
class CONFIGCAT_API UConfigCatPercentageOptionWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class EConfigCatSettingTypeWrapper : uint8
};

UCLASS(DisplayName="Config Cat Setting")
class CONFIGCATWRAPPERS_API UConfigCatSettingWrapper : public UObject
class CONFIGCAT_API UConfigCatSettingWrapper : public UObject
{
GENERATED_BODY()

Expand Down Expand Up @@ -54,7 +54,7 @@ class CONFIGCATWRAPPERS_API UConfigCatSettingWrapper : public UObject
};

UCLASS(DisplayName="Config Cat Settings")
class CONFIGCATWRAPPERS_API UConfigCatSettingsWrapper : public UObject
class CONFIGCAT_API UConfigCatSettingsWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum class EConfigCatUserComparator : uint8
};

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

Expand Down Expand Up @@ -94,7 +94,7 @@ enum class EConfigCatPrerequisiteFlagComparator : uint8
};

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

Expand All @@ -120,7 +120,7 @@ enum class EConfigCatSegmentComparator : uint8
};

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

Expand All @@ -136,7 +136,7 @@ class CONFIGCATWRAPPERS_API UConfigCatSegmentConditionWrapper : public UObject
};

USTRUCT(BlueprintType)
struct CONFIGCATWRAPPERS_API FConfigCatConditionContainer
struct CONFIGCAT_API FConfigCatConditionContainer
{
GENERATED_BODY()

Expand All @@ -161,7 +161,7 @@ struct FConfigCatThenContainer
};

UCLASS(DisplayName="Config Cat Targeting Rule")
class CONFIGCATWRAPPERS_API UConfigCatTargetingRuleWrapper : public UObject
class CONFIGCAT_API UConfigCatTargetingRuleWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

#pragma once

#include <ConfigCatCppSDK/Include/configcatuser.h>

#include <Misc/DateTime.h>

#include <memory>

#include "ConfigCatUserWrapper.generated.h"

namespace configcat
{
class ConfigCatUser;
}

UCLASS(DisplayName="Config Cat User")
class CONFIGCATWRAPPERS_API UConfigCatUserWrapper : public UObject
class CONFIGCAT_API UConfigCatUserWrapper : public UObject
{
GENERATED_BODY()

Expand Down Expand Up @@ -47,7 +51,4 @@ class CONFIGCATWRAPPERS_API UConfigCatUserWrapper : public UObject
bool HasStringArrayAttribute(const FString& Key) const;

std::shared_ptr<configcat::ConfigCatUser> User;

private:
const configcat::ConfigCatUser::AttributeValue* GetUserAttributeForKey(const FString& Key) const;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ConfigCatValueWrapper.generated.h"

UCLASS(DisplayName="Config Cat SettingValue")
class CONFIGCATWRAPPERS_API UConfigCatValueWrapper : public UObject
class CONFIGCAT_API UConfigCatValueWrapper : public UObject
{
GENERATED_BODY()

Expand Down
28 changes: 0 additions & 28 deletions Source/ConfigCatWrappers/ConfigCatWrappers.Build.cs

This file was deleted.

5 changes: 0 additions & 5 deletions Source/ConfigCatWrappers/Private/ConfigCatWrappers.cpp

This file was deleted.

Loading

0 comments on commit 7f7d00f

Please sign in to comment.