Skip to content

Commit

Permalink
Update config JSON model to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Feb 26, 2024
1 parent 55cd33d commit c0fea4b
Show file tree
Hide file tree
Showing 31 changed files with 2,507 additions and 1,806 deletions.
574 changes: 373 additions & 201 deletions include/configcat/config.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/configcat/configcatclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class ConfigCatClient {

/**
* Gets the value of a feature flag or setting as std::shared_ptr<Value> identified by the given [key].
* In case of any failure, nullptr will be returned. The [user] param identifies the caller.
* In case of any failure, std::nullopt will be returned. The [user] param identifies the caller.
*/
std::shared_ptr<Value> getValue(const std::string& key, const ConfigCatUser* user = nullptr) const;
std::optional<Value> getValue(const std::string& key, const ConfigCatUser* user = nullptr) const;

/**
* Gets the value and evaluation details of a feature flag or setting identified by the given `key`.
Expand Down
12 changes: 10 additions & 2 deletions include/configcat/configcatlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,30 @@ class LogEntry {
return *this;
}

// TODO: remove?
LogEntry& operator<<(const ConfigCatUser* user) {
return operator<<(*user);
}

// TODO: remove?
LogEntry& operator<<(const ConfigCatUser& user) {
if (logger && level <= logger->getLogLevel())
message += user.toJson();
return *this;
}

LogEntry& operator<<(const Value& v) {
// TODO: remove?
LogEntry& operator<<(const std::optional<Value>& v) {
if (logger && level <= logger->getLogLevel())
message += valueToString(v);
message += v ? v->toString() : "<invalid value>";
return *this;
}

// TODO: remove?
LogEntry& operator<<(const SettingValue& v) {
return *this << static_cast<std::optional<Value>>(v);
}

template<typename Type>
LogEntry& operator<<(Type arg) {
if (logger && level <= logger->getLogLevel())
Expand Down
25 changes: 15 additions & 10 deletions include/configcat/evaluationdetails.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include <string>
#include <optional>
#include <chrono>
#include <functional>
#include <optional>
#include <string>

#include "config.h"

namespace configcat {
Expand All @@ -13,22 +15,25 @@ struct EvaluationDetails {
public:
EvaluationDetails(const std::string& key = "",
const Value& value = {},
const std::string& variationId = "",
const std::optional<std::string>& variationId = "",
const std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<double>>& fetchTime = {},
const ConfigCatUser* user = nullptr,
bool isDefaultValue = false,
const std::string& error = "",
const RolloutRule* matchedEvaluationRule = nullptr,
const RolloutPercentageItem* matchedEvaluationPercentageRule = nullptr)
const TargetingRule* matchedTargetingRule = nullptr,
const PercentageOption* matchedPercentageOption = nullptr)
: key(key)
, value(value)
, variationId(variationId)
, fetchTime(fetchTime)
, user(user)
, isDefaultValue(isDefaultValue)
, error(error)
, matchedEvaluationRule(matchedEvaluationRule ? std::optional<RolloutRule>{*matchedEvaluationRule} : std::nullopt)
, matchedEvaluationPercentageRule(matchedEvaluationPercentageRule ? std::optional<RolloutPercentageItem>{*matchedEvaluationPercentageRule} : std::nullopt)
// Unfortunately, std::optional<T&> is not possible (https://stackoverflow.com/a/26862721/8656352).
// We could use std::optional<std::reference_wrapper<T>> as a workaround. However, that would take up more space
// than pointers, so we'd rather resort to pointers, as this is ctor is not meant for public use.
, matchedTargetingRule(matchedTargetingRule ? std::optional<TargetingRule>(*matchedTargetingRule) : std::nullopt)
, matchedPercentageOption(matchedPercentageOption ? std::optional<PercentageOption>(*matchedPercentageOption) : std::nullopt)
{}

static EvaluationDetails fromError(const std::string& key, const Value& value, const std::string& error, const std::string& variationId = {}) {
Expand All @@ -37,13 +42,13 @@ struct EvaluationDetails {

std::string key;
Value value;
std::string variationId;
std::optional<std::string> variationId;
std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<double>> fetchTime;
const ConfigCatUser* user;
bool isDefaultValue;
std::string error;
std::optional<RolloutRule> matchedEvaluationRule;
std::optional<RolloutPercentageItem> matchedEvaluationPercentageRule;
std::optional<TargetingRule> matchedTargetingRule;
std::optional<PercentageOption> matchedPercentageOption;
};

} // namespace configcat
1 change: 0 additions & 1 deletion include/configcat/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace configcat {

class ConfigCatUser;
struct Value;

enum LogLevel {
LOG_LEVEL_ERROR,
Expand Down
Loading

0 comments on commit c0fea4b

Please sign in to comment.