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  enum class BigSegmentsStatus {
62  // The evaluation did not query any Big Segments.
63  kNone = 0,
64  // The query was successful and the segment state is up to date.
65  kHealthy = 1,
66  // The query was successful, but the segment state may not be up to
67  // date.
68  kStale = 2,
69  // Big Segments could not be queried because the SDK configuration did
70  // not include a Big Segment store.
71  kNotConfigured = 3,
72  // The query failed, for instance due to a database error.
73  kStoreError = 4,
74  };
75 
76  friend std::ostream& operator<<(std::ostream& out,
77  BigSegmentsStatus const& status);
78 
82  [[nodiscard]] enum Kind const& Kind() const;
83 
88  [[nodiscard]] std::optional<ErrorKind> ErrorKind() const;
89 
95  [[nodiscard]] enum BigSegmentsStatus BigSegmentsStatus() const;
96 
101  [[deprecated("use BigSegmentsStatus()")]] [[nodiscard]] std::optional<
102  std::string>
103  BigSegmentStatus() const;
104 
109  [[nodiscard]] std::optional<std::size_t> RuleIndex() const;
110 
115  [[nodiscard]] std::optional<std::string> RuleId() const;
116 
121  [[nodiscard]] std::optional<std::string> PrerequisiteKey() const;
122 
130  [[nodiscard]] bool InExperiment() const;
131 
132  EvaluationReason(enum Kind kind,
133  std::optional<enum ErrorKind> error_kind,
134  std::optional<std::size_t> rule_index,
135  std::optional<std::string> rule_id,
136  std::optional<std::string> prerequisite_key,
137  bool in_experiment,
138  enum BigSegmentsStatus big_segments_status);
139 
143  [[deprecated("use the BigSegmentsStatus overload")]] EvaluationReason(
144  enum Kind kind,
145  std::optional<enum ErrorKind> error_kind,
146  std::optional<std::size_t> rule_index,
147  std::optional<std::string> rule_id,
148  std::optional<std::string> prerequisite_key,
149  bool in_experiment,
150  std::optional<std::string> big_segment_status);
151 
152  explicit EvaluationReason(enum ErrorKind error_kind);
153 
157  static EvaluationReason Off();
158 
162  static EvaluationReason PrerequisiteFailed(std::string prerequisite_key);
163 
167  static EvaluationReason TargetMatch();
168 
173  static EvaluationReason Fallthrough(bool in_experiment);
174 
181  static EvaluationReason RuleMatch(std::size_t rule_index,
182  std::optional<std::string> rule_id,
183  bool in_experiment);
184 
189 
190  friend std::ostream& operator<<(std::ostream& out,
191  EvaluationReason const& reason);
192 
193  friend bool operator==(EvaluationReason const& lhs,
194  EvaluationReason const& rhs);
195 
196  private:
197  enum Kind kind_;
198  std::optional<enum ErrorKind> error_kind_;
199  std::optional<std::size_t> rule_index_;
200  std::optional<std::string> rule_id_;
201  std::optional<std::string> prerequisite_key_;
202  bool in_experiment_;
203  enum BigSegmentsStatus big_segments_status_;
204  std::optional<std::string> big_segment_status_;
205 };
206 
207 bool operator==(EvaluationReason const& lhs, EvaluationReason const& rhs);
208 bool operator!=(EvaluationReason const& lhs, EvaluationReason const& rhs);
209 
210 } // namespace launchdarkly
Definition: evaluation_reason.hpp:13
static EvaluationReason MalformedFlag()
Definition: evaluation_reason.cpp:135
static EvaluationReason TargetMatch()
Definition: evaluation_reason.cpp:103
static EvaluationReason Fallthrough(bool in_experiment)
Definition: evaluation_reason.cpp:113
BigSegmentsStatus
Definition: evaluation_reason.hpp:61
static EvaluationReason RuleMatch(std::size_t rule_index, std::optional< std::string > rule_id, bool in_experiment)
Definition: evaluation_reason.cpp:123
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:92
static EvaluationReason Off()
Definition: evaluation_reason.cpp:82
std::optional< std::string > RuleId() const
Definition: evaluation_reason.cpp:18
std::optional< std::string > BigSegmentStatus() const
Definition: evaluation_reason.cpp:35
std::optional< std::size_t > RuleIndex() const
Definition: evaluation_reason.cpp:14