C++ Server-Side SDK
LaunchDarkly SDK
all_flags_state.hpp
1 #pragma once
2 
3 #include <launchdarkly/data/evaluation_reason.hpp>
4 #include <launchdarkly/value.hpp>
5 
6 #include <cstdint>
7 #include <optional>
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
11 
12 namespace launchdarkly::server_side {
13 
28  public:
29  enum class Options : std::uint8_t {
33  Default = 0,
38  IncludeReasons = (1 << 0),
46  DetailsOnlyForTrackedFlags = (1 << 1),
51  ClientSideOnly = (1 << 2)
52  };
53 
57  class State {
58  public:
59  State(std::uint64_t version,
60  std::optional<std::int64_t> variation,
61  std::optional<EvaluationReason> reason,
62  bool track_events,
63  bool track_reason,
64  std::optional<std::uint64_t> debug_events_until_date);
65 
66  State(std::uint64_t version,
67  std::optional<std::int64_t> variation,
68  std::optional<EvaluationReason> reason,
69  bool track_events,
70  bool track_reason,
71  std::optional<std::uint64_t> debug_events_until_date,
72  std::vector<std::string> prerequisites);
73 
77  [[nodiscard]] std::uint64_t Version() const;
78 
83  [[nodiscard]] std::optional<std::int64_t> Variation() const;
84 
89  [[nodiscard]] std::optional<EvaluationReason> const& Reason() const;
90 
97  [[nodiscard]] bool TrackEvents() const;
98 
105  [[nodiscard]] bool TrackReason() const;
106 
111  [[nodiscard]] std::optional<std::uint64_t> const& DebugEventsUntilDate()
112  const;
113 
120  [[nodiscard]] bool OmitDetails() const;
121 
126  [[nodiscard]] std::vector<std::string> const& Prerequisites() const;
127 
128  friend class AllFlagsStateBuilder;
129 
130  private:
131  std::uint64_t version_;
132  std::optional<std::int64_t> variation_;
133  std::optional<EvaluationReason> reason_;
134  bool track_events_;
135  bool track_reason_;
136  std::optional<std::uint64_t> debug_events_until_date_;
137  bool omit_details_;
138  std::vector<std::string> prerequisites_;
139  };
140 
146  [[nodiscard]] bool Valid() const;
147 
151  [[nodiscard]] std::unordered_map<std::string, State> const& States() const;
152 
156  [[nodiscard]] std::unordered_map<std::string, Value> const& Values() const;
157 
161  AllFlagsState();
162 
168  AllFlagsState(std::unordered_map<std::string, Value> evaluations,
169  std::unordered_map<std::string, class State> flags_state);
170 
171  private:
172  bool const valid_;
173  std::unordered_map<std::string, class State> const flags_state_;
174  std::unordered_map<std::string, Value> const evaluations_;
175 };
176 
177 void operator|=(AllFlagsState::Options& lhs, AllFlagsState::Options rhs);
180 
183 
184 bool operator==(class AllFlagsState::State const& lhs,
185  class AllFlagsState::State const& rhs);
186 
187 bool operator==(AllFlagsState const& lhs, AllFlagsState const& rhs);
188 
189 } // namespace launchdarkly::server_side
Definition: all_flags_state_builder.hpp:15
Definition: all_flags_state.hpp:57
std::optional< std::int64_t > Variation() const
Definition: all_flags_state.cpp:41
std::optional< std::uint64_t > const & DebugEventsUntilDate() const
Definition: all_flags_state.cpp:61
std::uint64_t Version() const
Definition: all_flags_state.cpp:37
std::optional< EvaluationReason > const & Reason() const
Definition: all_flags_state.cpp:45
bool OmitDetails() const
Definition: all_flags_state.cpp:66
bool TrackEvents() const
Definition: all_flags_state.cpp:49
bool TrackReason() const
Definition: all_flags_state.cpp:53
std::vector< std::string > const & Prerequisites() const
Definition: all_flags_state.cpp:57
Definition: all_flags_state.hpp:27
std::unordered_map< std::string, Value > const & Values() const
Definition: all_flags_state.cpp:88
AllFlagsState()
Definition: all_flags_state.cpp:70
std::unordered_map< std::string, State > const & States() const
Definition: all_flags_state.cpp:84
Options
Definition: all_flags_state.hpp:29
bool Valid() const
Definition: all_flags_state.cpp:79