C++ Client-Side SDK
LaunchDarkly SDK
client.hpp
1 #pragma once
2 
3 #include <chrono>
4 #include <future>
5 #include <memory>
6 #include <string>
7 #include <unordered_map>
8 
9 #include <launchdarkly/context.hpp>
10 #include <launchdarkly/value.hpp>
11 
12 #include <launchdarkly/client_side/data_source_status.hpp>
13 #include <launchdarkly/client_side/flag_notifier.hpp>
14 #include <launchdarkly/config/client.hpp>
15 #include <launchdarkly/data/evaluation_detail.hpp>
16 
17 namespace launchdarkly::client_side {
18 
26 class IClient {
27  public:
31  using FlagKey = std::string;
32 
58  virtual std::future<bool> StartAsync() = 0;
59 
80  [[nodiscard]] virtual bool Initialized() const = 0;
81 
90  [[nodiscard]] virtual std::unordered_map<FlagKey, Value> AllFlags()
91  const = 0;
92 
104  virtual void Track(std::string event_name,
105  Value data,
106  double metric_value) = 0;
107 
116  virtual void Track(std::string event_name, Value data) = 0;
117 
124  virtual void Track(std::string event_name) = 0;
125 
130  virtual void FlushAsync() = 0;
131 
149  virtual std::future<bool> IdentifyAsync(Context context) = 0;
150 
159  virtual bool BoolVariation(FlagKey const& key, bool default_value) = 0;
160 
170  bool default_value) = 0;
171 
180  virtual std::string StringVariation(FlagKey const& key,
181  std::string default_value) = 0;
182 
192  FlagKey const& key,
193  std::string default_value) = 0;
194 
203  virtual double DoubleVariation(FlagKey const& key,
204  double default_value) = 0;
205 
215  FlagKey const& key,
216  double default_value) = 0;
217 
226  virtual int IntVariation(FlagKey const& key, int default_value) = 0;
227 
237  int default_value) = 0;
238 
247  virtual Value JsonVariation(FlagKey const& key, Value default_value) = 0;
248 
258  FlagKey const& key,
259  Value default_value) = 0;
260 
267 
274 
275  virtual ~IClient() = default;
276  IClient(IClient const& item) = delete;
277  IClient(IClient&& item) = delete;
278  IClient& operator=(IClient const&) = delete;
279  IClient& operator=(IClient&&) = delete;
280 
281  protected:
282  IClient() = default;
283 };
284 
285 class Client : public IClient {
286  public:
287  Client(Config config, Context context);
288 
289  std::future<bool> StartAsync() override;
290 
291  [[nodiscard]] bool Initialized() const override;
292 
293  using FlagKey = std::string;
294  [[nodiscard]] std::unordered_map<FlagKey, Value> AllFlags() const override;
295 
296  void Track(std::string event_name,
297  Value data,
298  double metric_value) override;
299 
300  void Track(std::string event_name, Value data) override;
301 
302  void Track(std::string event_name) override;
303 
304  void FlushAsync() override;
305 
306  std::future<bool> IdentifyAsync(Context context) override;
307 
308  bool BoolVariation(FlagKey const& key, bool default_value) override;
309 
311  bool default_value) override;
312 
313  std::string StringVariation(FlagKey const& key,
314  std::string default_value) override;
315 
317  FlagKey const& key,
318  std::string default_value) override;
319 
320  double DoubleVariation(FlagKey const& key, double default_value) override;
321 
323  FlagKey const& key,
324  double default_value) override;
325 
326  int IntVariation(FlagKey const& key, int default_value) override;
327 
329  int default_value) override;
330 
331  Value JsonVariation(FlagKey const& key, Value default_value) override;
332 
334  Value default_value) override;
335 
337 
339 
344  [[nodiscard]] static char const* Version();
345 
346  private:
347  inline static char const* const kVersion =
348  "3.8.1"; // {x-release-please-version}
349  std::unique_ptr<IClient> client;
350 };
351 
352 } // namespace launchdarkly::client_side
Definition: context.hpp:29
Definition: evaluation_detail.hpp:18
Definition: value.hpp:42
Definition: client.hpp:285
EvaluationDetail< Value > JsonVariationDetail(FlagKey const &key, Value default_value) override
Definition: client.cpp:86
flag_manager::IFlagNotifier & FlagNotifier() override
Definition: client.cpp:95
double DoubleVariation(FlagKey const &key, double default_value) override
Definition: client.cpp:64
EvaluationDetail< double > DoubleVariationDetail(FlagKey const &key, double default_value) override
Definition: client.cpp:68
bool BoolVariation(FlagKey const &key, bool default_value) override
Definition: client.cpp:44
EvaluationDetail< std::string > StringVariationDetail(FlagKey const &key, std::string default_value) override
Definition: client.cpp:58
std::future< bool > StartAsync() override
Definition: client.cpp:15
std::unordered_map< FlagKey, Value > AllFlags() const override
Definition: client.cpp:20
EvaluationDetail< int > IntVariationDetail(FlagKey const &key, int default_value) override
Definition: client.cpp:77
std::future< bool > IdentifyAsync(Context context) override
Definition: client.cpp:40
static char const * Version()
Definition: client.cpp:99
Value JsonVariation(FlagKey const &key, Value default_value) override
Definition: client.cpp:82
EvaluationDetail< bool > BoolVariationDetail(FlagKey const &key, bool default_value) override
Definition: client.cpp:48
std::string StringVariation(FlagKey const &key, std::string default_value) override
Definition: client.cpp:53
void FlushAsync() override
Definition: client.cpp:36
data_sources::IDataSourceStatusProvider & DataSourceStatus() override
Definition: client.cpp:91
void Track(std::string event_name, Value data, double metric_value) override
Definition: client.cpp:24
int IntVariation(FlagKey const &key, int default_value) override
Definition: client.cpp:73
bool Initialized() const override
Definition: client.cpp:11
Definition: client.hpp:26
virtual double DoubleVariation(FlagKey const &key, double default_value)=0
virtual Value JsonVariation(FlagKey const &key, Value default_value)=0
virtual EvaluationDetail< bool > BoolVariationDetail(FlagKey const &key, bool default_value)=0
virtual data_sources::IDataSourceStatusProvider & DataSourceStatus()=0
virtual void Track(std::string event_name)=0
virtual void Track(std::string event_name, Value data, double metric_value)=0
virtual EvaluationDetail< double > DoubleVariationDetail(FlagKey const &key, double default_value)=0
virtual std::unordered_map< FlagKey, Value > AllFlags() const =0
virtual std::string StringVariation(FlagKey const &key, std::string default_value)=0
virtual flag_manager::IFlagNotifier & FlagNotifier()=0
virtual int IntVariation(FlagKey const &key, int default_value)=0
virtual EvaluationDetail< Value > JsonVariationDetail(FlagKey const &key, Value default_value)=0
virtual bool Initialized() const =0
virtual EvaluationDetail< int > IntVariationDetail(FlagKey const &key, int default_value)=0
virtual bool BoolVariation(FlagKey const &key, bool default_value)=0
virtual std::future< bool > StartAsync()=0
virtual std::future< bool > IdentifyAsync(Context context)=0
virtual void Track(std::string event_name, Value data)=0
std::string FlagKey
Definition: client.hpp:31
virtual EvaluationDetail< std::string > StringVariationDetail(FlagKey const &key, std::string default_value)=0
Definition: config.hpp:20