Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
42a776d
base data structures fot hook implementation.
NeaguGeorgiana23 Jul 7, 2026
e968609
fix linter
NeaguGeorgiana23 Jul 7, 2026
334ec2a
fix linter
NeaguGeorgiana23 Jul 7, 2026
f110e5c
Merge branch 'main' into define-hook-data-structures
NeaguGeorgiana23 Jul 7, 2026
5cc878b
Update BUILD file.
NeaguGeorgiana23 Jul 10, 2026
bd66430
Correct include guards.
NeaguGeorgiana23 Jul 10, 2026
5332610
feat: Add HookData class.
NeaguGeorgiana23 Jul 10, 2026
c8fc92d
fix linter
NeaguGeorgiana23 Jul 10, 2026
3f5f4de
fix linter
NeaguGeorgiana23 Jul 10, 2026
b0f3a15
fix linter
NeaguGeorgiana23 Jul 10, 2026
e9e8852
fix linter
NeaguGeorgiana23 Jul 10, 2026
e333df0
add HookContext structure.
NeaguGeorgiana23 Jul 13, 2026
c59de28
fix linter
NeaguGeorgiana23 Jul 13, 2026
45ca64a
fix linter
NeaguGeorgiana23 Jul 13, 2026
3b93d77
add Hooks class.
NeaguGeorgiana23 Jul 14, 2026
a4aa1c2
fix linter.
NeaguGeorgiana23 Jul 14, 2026
d7cd54a
fix linter.
NeaguGeorgiana23 Jul 14, 2026
d6ef2c6
fix linter.
NeaguGeorgiana23 Jul 14, 2026
a2f7fee
fix linter.
NeaguGeorgiana23 Jul 14, 2026
a91afca
appli agent suggestions.
NeaguGeorgiana23 Jul 14, 2026
c0482f7
Merge branch 'main' into hooks
NeaguGeorgiana23 Jul 14, 2026
a0ca155
Merge branch 'main' into hooks
NeaguGeorgiana23 Jul 14, 2026
48ddb25
Update Hook class such that clients can implement typeless hooks.
NeaguGeorgiana23 Jul 28, 2026
fbece8f
fix linter.
NeaguGeorgiana23 Jul 28, 2026
1874040
Update signatore of function Before.
NeaguGeorgiana23 Jul 28, 2026
a351780
Merge branch 'main' into hooks
NeaguGeorgiana23 Jul 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions openfeature/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,44 @@ package(
default_visibility = ["//visibility:public"],
)

cc_library(
name = "general_flag_evaluation_details",
hdrs = ["general_flag_evaluation_details.h"],
include_prefix = "openfeature",
deps = [
":error_code",
":flag_metadata",
":reason",
":value",
],
)

cc_library(
name = "general_hook_context",
hdrs = ["general_hook_context.h"],
include_prefix = "openfeature",
deps = [
":evaluation_context",
":flag_type_value",
":hook_data",
":metadata",
":value",
],
)

cc_library(
name = "general_hook",
hdrs = ["general_hook.h"],
include_prefix = "openfeature",
deps = [
":evaluation_context",
":general_flag_evaluation_details",
":general_hook_context",
":hook_hints",
":value",
],
)

cc_library(
name = "client",
hdrs = ["client.h"],
Expand Down Expand Up @@ -74,6 +112,21 @@ cc_library(
],
)

cc_library(
name = "flag_evaluation_details",
srcs = ["flag_evaluation_details.cpp"],
hdrs = ["flag_evaluation_details.h"],
include_prefix = "openfeature",
deps = [
":general_flag_evaluation_details",
":error_code",
":flag_metadata",
":reason",
":resolution_details",
":value"
],
)

cc_library(
name = "flag_metadata",
hdrs = ["flag_metadata.h"],
Expand Down Expand Up @@ -102,6 +155,7 @@ cc_library(
hdrs = ["hook_context.h"],
include_prefix = "openfeature",
deps = [
"general_hook_context",
":evaluation_context",
":flag_metadata",
":flag_type_value",
Expand All @@ -124,6 +178,23 @@ cc_library(
include_prefix = "openfeature",
)

cc_library(
name = "hook",
srcs = ["hook.cpp"],
hdrs = ["hook.h"],
include_prefix = "openfeature",
deps = [
":general_flag_evaluation_details",
":general_hook_context",
":general_hook",
":evaluation_context",
":flag_evaluation_details",
":hook_context",
":hook_hints",
":value",
],
)

cc_library(
name = "metadata",
hdrs = ["metadata.h"],
Expand Down
72 changes: 72 additions & 0 deletions openfeature/flag_evaluation_details.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "openfeature/flag_evaluation_details.h"

#include <optional>
#include <string>
#include <string_view>

#include "openfeature/error_code.h"
#include "openfeature/flag_metadata.h"
#include "openfeature/reason.h"
#include "openfeature/resolution_details.h"
#include "openfeature/value.h"

namespace openfeature {

template <typename T>
FlagEvaluationDetails<T>::FlagEvaluationDetails(
std::string flag_key, T value, Reason reason,
std::optional<std::string> variant, const FlagMetadata& flag_metadata,
std::optional<ErrorCode> error_code,
std::optional<std::string> error_message)
: ResolutionDetails<T>(std::move(value), reason, std::move(variant),
flag_metadata, error_code, std::move(error_message)),
flag_key_(std::move(flag_key)) {}

template <typename T>
FlagEvaluationDetails<T>::FlagEvaluationDetails(
std::string flag_key, const ResolutionDetails<T>& resolution_details)
: ResolutionDetails<T>(resolution_details),
flag_key_(std::move(flag_key)) {}

template <typename T>
std::string_view FlagEvaluationDetails<T>::GetFlagKey() const {
return flag_key_;
}

template <typename T>
Reason FlagEvaluationDetails<T>::GetReason() const {
return ResolutionDetails<T>::GetReason();
}

template <typename T>
std::optional<std::string> FlagEvaluationDetails<T>::GetVariant() const {
return ResolutionDetails<T>::GetVariant();
}

template <typename T>
std::optional<ErrorCode> FlagEvaluationDetails<T>::GetErrorCode() const {
return ResolutionDetails<T>::GetErrorCode();
}

template <typename T>
std::optional<std::string> FlagEvaluationDetails<T>::GetErrorMessage() const {
return ResolutionDetails<T>::GetErrorMessage();
}

template <typename T>
const FlagMetadata& FlagEvaluationDetails<T>::GetFlagMetadata() const {
return ResolutionDetails<T>::GetFlagMetadata();
}

template <typename T>
Value FlagEvaluationDetails<T>::GetValueAsValue() const {
return Value(ResolutionDetails<T>::GetValue());
}

template class FlagEvaluationDetails<bool>;
template class FlagEvaluationDetails<std::string>;
template class FlagEvaluationDetails<int64_t>;
template class FlagEvaluationDetails<double>;
template class FlagEvaluationDetails<Value>;

} // namespace openfeature
58 changes: 58 additions & 0 deletions openfeature/flag_evaluation_details.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_
#define CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_

#include <optional>
#include <string>
#include <string_view>

#include "openfeature/error_code.h"
#include "openfeature/flag_metadata.h"
#include "openfeature/general_flag_evaluation_details.h"
#include "openfeature/reason.h"
#include "openfeature/resolution_details.h"
#include "openfeature/value.h"

namespace openfeature {

template <typename T>
class FlagEvaluationDetails : public ResolutionDetails<T>,
public GeneralFlagEvaluationDetails {
public:
FlagEvaluationDetails(
std::string flag_key, T value, Reason reason,
std::optional<std::string> variant, const FlagMetadata& flag_metadata,
std::optional<ErrorCode> error_code = std::nullopt,
std::optional<std::string> error_message = std::nullopt);

FlagEvaluationDetails(std::string flag_key,
const ResolutionDetails<T>& resolution_details);

FlagEvaluationDetails(const FlagEvaluationDetails&) = default;
FlagEvaluationDetails& operator=(const FlagEvaluationDetails&) = default;
FlagEvaluationDetails(FlagEvaluationDetails&&) noexcept = default;
FlagEvaluationDetails& operator=(FlagEvaluationDetails&&) noexcept = default;
~FlagEvaluationDetails() override = default;

std::string_view GetFlagKey() const override;
Reason GetReason() const override;
std::optional<std::string> GetVariant() const override;
std::optional<ErrorCode> GetErrorCode() const override;
std::optional<std::string> GetErrorMessage() const override;
const FlagMetadata& GetFlagMetadata() const override;

Value GetValueAsValue() const override;

private:
std::string flag_key_;
};

// Type aliases for common types.
using BoolFlagEvaluationDetails = FlagEvaluationDetails<bool>;
using StringFlagEvaluationDetails = FlagEvaluationDetails<std::string>;
using IntFlagEvaluationDetails = FlagEvaluationDetails<int64_t>;
using DoubleFlagEvaluationDetails = FlagEvaluationDetails<double>;
using ObjectFlagEvaluationDetails = FlagEvaluationDetails<Value>;

} // namespace openfeature

#endif // CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_
29 changes: 29 additions & 0 deletions openfeature/general_flag_evaluation_details.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_FLAG_EVALUATION_DETAILS_H_
#define CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_FLAG_EVALUATION_DETAILS_H_

#include <optional>
#include <string>
#include <string_view>

#include "openfeature/error_code.h"
#include "openfeature/flag_metadata.h"
#include "openfeature/reason.h"
#include "openfeature/value.h"

namespace openfeature {

class GeneralFlagEvaluationDetails {
public:
virtual ~GeneralFlagEvaluationDetails() = default;
virtual std::string_view GetFlagKey() const = 0;
virtual Value GetValueAsValue() const = 0;
virtual Reason GetReason() const = 0;
virtual std::optional<std::string> GetVariant() const = 0;
virtual const FlagMetadata& GetFlagMetadata() const = 0;
virtual std::optional<ErrorCode> GetErrorCode() const = 0;
virtual std::optional<std::string> GetErrorMessage() const = 0;
};

} // namespace openfeature

#endif // CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_FLAG_EVALUATION_DETAILS_H_
48 changes: 48 additions & 0 deletions openfeature/general_hook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_HOOK_H_
#define CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_HOOK_H_

#include <cstdint>
#include <exception>
#include <optional>

#include "openfeature/evaluation_context.h"
#include "openfeature/general_flag_evaluation_details.h"
#include "openfeature/general_hook_context.h"
#include "openfeature/hook_hints.h"
#include "openfeature/value.h"

namespace openfeature {

// Non-templated general class for all hooks. This will allow storing different
// hook types (e.g., BoolHook,
// StringHook) inside evaluation options.
class GeneralHook {
public:
GeneralHook() = default;
GeneralHook(const GeneralHook&) = delete;
GeneralHook(GeneralHook&&) = delete;
GeneralHook& operator=(const GeneralHook&) = delete;
GeneralHook& operator=(GeneralHook&&) = delete;
virtual ~GeneralHook() = default;

// 1. Before: Runs before flag evaluation occurs.
virtual std::optional<EvaluationContext> Before(const GeneralHookContext& ctx,
const HookHints& hints) {
return std::nullopt;
}
// 2. After: Runs immediately after successful flag evaluation.
virtual void After(const GeneralHookContext& ctx,
const GeneralFlagEvaluationDetails& details,
const HookHints& hints) {}
// 3. Error: Runs if an error occurs during evaluation or in Before/After.
virtual void Error(const GeneralHookContext& ctx, const std::exception& error,
const HookHints& hints) {}
// 4. Finally: Runs after evaluation occurs, regardless of success or error.
virtual void Finally(const GeneralHookContext& ctx,
const GeneralFlagEvaluationDetails& details,
const HookHints& hints) {}
};

} // namespace openfeature

#endif // CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_HOOK_H_
30 changes: 30 additions & 0 deletions openfeature/general_hook_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_HOOK_CONTEXT_H_
#define CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_HOOK_CONTEXT_H_

#include <memory>
#include <string>

#include "openfeature/evaluation_context.h"
#include "openfeature/flag_type_value.h"
#include "openfeature/hook_data.h"
#include "openfeature/metadata.h"
#include "openfeature/value.h"

namespace openfeature {

class GeneralHookContext {
public:
virtual ~GeneralHookContext() = default;
virtual const std::string& GetFlagKey() const = 0;
virtual FlagValueType GetType() const = 0;
virtual Value GetDefaultValueAsValue() const = 0;
virtual const EvaluationContext& GetEvaluationContext() const = 0;
virtual void SetEvaluationContext(EvaluationContext ctx) = 0;
virtual const Metadata& GetClientMetadata() const = 0;
virtual const Metadata& GetProviderMetadata() const = 0;
virtual std::shared_ptr<HookData> GetHookData() const = 0;
};

} // namespace openfeature

#endif // CPP_SDK_INCLUDE_OPENFEATURE_GENERAL_HOOK_CONTEXT_H_
12 changes: 12 additions & 0 deletions openfeature/hook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "openfeature/hook.h"

namespace openfeature {

// Explicit template instantiations for common hook types.
template class Hook<bool>;
template class Hook<std::string>;
template class Hook<int64_t>;
template class Hook<double>;
template class Hook<Value>;

} // namespace openfeature
Loading