C++ Server-Side SDK
LaunchDarkly SDK
evaluation_reason.hpp
1 #pragma once
2 
3 #include <cstddef>
4 #include <optional>
5 #include <ostream>
6 #include <string>
7 
8 namespace launchdarkly {
9 
14  public:
18  enum class Kind {
19  // The flag was off and therefore returned its configured off value.
20  kOff = 0,
21  // The flag was on but the context did not match any targets or rules.
22  kFallthrough = 1,
23  // The context key was specifically targeted for this flag.
24  kTargetMatch = 2,
25  // The context matched one of the flag's rules.
26  kRuleMatch = 3,
27  // The flag was considered off because it had at least one prerequisite
28  // flag that either was off or did not return the desired variation.
29  kPrerequisiteFailed = 4,
30  // The flag could not be evaluated, e.g. because it does not exist or
31  // due to an unexpected error.
32  kError = 5
33  };
34  friend std::ostream& operator<<(std::ostream& out, Kind const& kind);
35 
39  enum class ErrorKind {
40  // The SDK was not yet fully initialized and cannot evaluate flags.
41  kClientNotReady = 0,
42  // The application did not pass valid context attributes to the SDK
43  // evaluation method.
44  kUserNotSpecified = 1,
45  // No flag existed with the specified flag key.
46  kFlagNotFound = 2,
47  // The application requested an evaluation result of one type but the
48  // resulting flag variation value was of a different type.
49  kWrongType = 3,
50  // The flag had invalid properties.
51  kMalformedFlag = 4,
52  // An unexpected error happened that stopped evaluation.
53  kException = 5,
54  };
55 
56  friend std::ostream& operator<<(std::ostream& out, ErrorKind const& kind);
57 
61  [[nodiscard]] enum Kind const& Kind() const;
62 
67  [[nodiscard]] std::optional<ErrorKind> ErrorKind() const;
68 
73  [[nodiscard]] std::optional<std::size_t> RuleIndex() const;
74 
79  [[nodiscard]] std::optional<std::string> RuleId() const;
80 
85  [[nodiscard]] std::optional<std::string> PrerequisiteKey() const;
86 
94  [[nodiscard]] bool InExperiment() const;
95 
110  [[nodiscard]] std::optional<std::string> BigSegmentStatus() const;
111 
112  EvaluationReason(enum Kind kind,
113  std::optional<enum ErrorKind> error_kind,
114  std::optional<std::size_t> rule_index,
115  std::optional<std::string> rule_id,
116  std::optional<std::string> prerequisite_key,
117  bool in_experiment,
118  std::optional<std::string> big_segment_status);
119 
120  explicit EvaluationReason(enum ErrorKind error_kind);
121 
125  static EvaluationReason Off();
126 
130  static EvaluationReason PrerequisiteFailed(std::string prerequisite_key);
131 
135  static EvaluationReason TargetMatch();
136 
141  static EvaluationReason Fallthrough(bool in_experiment);
142 
149  static EvaluationReason RuleMatch(std::size_t rule_index,
150  std::optional<std::string> rule_id,
151  bool in_experiment);
152 
157 
158  friend std::ostream& operator<<(std::ostream& out,
159  EvaluationReason const& reason);
160 
161  private:
162  enum Kind kind_;
163  std::optional<enum ErrorKind> error_kind_;
164  std::optional<std::size_t> rule_index_;
165  std::optional<std::string> rule_id_;
166  std::optional<std::string> prerequisite_key_;
167  bool in_experiment_;
168  std::optional<std::string> big_segment_status_;
169 };
170 
171 bool operator==(EvaluationReason const& lhs, EvaluationReason const& rhs);
172 bool operator!=(EvaluationReason const& lhs, EvaluationReason const& rhs);
173 
174 } // namespace launchdarkly
Definition: evaluation_reason.hpp:13
static EvaluationReason MalformedFlag()
Definition: evaluation_reason.cpp:88
static EvaluationReason TargetMatch()
Definition: evaluation_reason.cpp:71
static EvaluationReason Fallthrough(bool in_experiment)
Definition: evaluation_reason.cpp:76
static EvaluationReason RuleMatch(std::size_t rule_index, std::optional< std::string > rule_id, bool in_experiment)
Definition: evaluation_reason.cpp:81
Kind
Definition: evaluation_reason.hpp:18
ErrorKind
Definition: evaluation_reason.hpp:39
bool InExperiment() const
Definition: evaluation_reason.cpp:26
std::optional< std::string > PrerequisiteKey() const
Definition: evaluation_reason.cpp:22
static EvaluationReason PrerequisiteFailed(std::string prerequisite_key)
Definition: evaluation_reason.cpp:64
static EvaluationReason Off()
Definition: evaluation_reason.cpp:59
std::optional< std::string > RuleId() const
Definition: evaluation_reason.cpp:18
std::optional< std::string > BigSegmentStatus() const
Definition: evaluation_reason.cpp:30
std::optional< std::size_t > RuleIndex() const
Definition: evaluation_reason.cpp:14