C++ Server-Side SDK
LaunchDarkly SDK
Loading...
Searching...
No Matches
memory_store.hpp
1#pragma once
2
3#include "../../data_interfaces/destination/idestination.hpp"
4#include "../../data_interfaces/store/istore.hpp"
5
6#include <memory>
7#include <mutex>
8#include <string>
9#include <unordered_map>
10
11namespace launchdarkly::server_side::data_components {
12
15 public:
16 [[nodiscard]] std::shared_ptr<data_model::FlagDescriptor> GetFlag(
17 std::string const& key) const override;
18
19 [[nodiscard]] std::shared_ptr<data_model::SegmentDescriptor> GetSegment(
20 std::string const& key) const override;
21
22 [[nodiscard]] std::
23 unordered_map<std::string, std::shared_ptr<data_model::FlagDescriptor>>
24 AllFlags() const override;
25
26 [[nodiscard]] std::unordered_map<
27 std::string,
28 std::shared_ptr<data_model::SegmentDescriptor>>
29 AllSegments() const override;
30
31 [[nodiscard]] bool Initialized() const override;
32
33 [[nodiscard]] std::string const& Identity() const override;
34
35 void Init(data_model::SDKDataSet dataSet) override;
36
37 void Upsert(std::string const& key,
38 data_model::FlagDescriptor flag) override;
39
40 void Upsert(std::string const& key,
41 data_model::SegmentDescriptor segment) override;
42
43 bool RemoveFlag(std::string const& key);
44
45 bool RemoveSegment(std::string const& key);
46
47 MemoryStore() = default;
48 ~MemoryStore() override = default;
49
50 MemoryStore(MemoryStore const& item) = delete;
51 MemoryStore(MemoryStore&& item) = delete;
52 MemoryStore& operator=(MemoryStore const&) = delete;
53 MemoryStore& operator=(MemoryStore&&) = delete;
54
55 private:
56 static inline std::string const description_ = "memory";
57 std::unordered_map<std::string, std::shared_ptr<data_model::FlagDescriptor>>
58 flags_;
59 std::unordered_map<std::string,
60 std::shared_ptr<data_model::SegmentDescriptor>>
61 segments_;
62 bool initialized_ = false;
63 mutable std::mutex data_mutex_;
64};
65
66} // namespace launchdarkly::server_side::data_components
std::unordered_map< std::string, std::shared_ptr< data_model::SegmentDescriptor > > AllSegments() const override
Get a map of all segments.
Definition memory_store.cpp:32
void Init(data_model::SDKDataSet dataSet) override
Initialize the destination with a base set of data.
Definition memory_store.cpp:46
std::unordered_map< std::string, std::shared_ptr< data_model::FlagDescriptor > > AllFlags() const override
Get a map of all flags.
Definition memory_store.cpp:26
std::shared_ptr< data_model::SegmentDescriptor > GetSegment(std::string const &key) const override
Get the segment named by key. Returns nullptr if no such flag exists.
Definition memory_store.cpp:15
std::shared_ptr< data_model::FlagDescriptor > GetFlag(std::string const &key) const override
Get the flag named by key. Returns nullptr if no such flag exists.
Definition memory_store.cpp:5
std::string const & Identity() const override
Definition memory_store.cpp:42
void Upsert(std::string const &key, data_model::FlagDescriptor flag) override
Upsert a flag named by key.
Definition memory_store.cpp:62
bool Initialized() const override
Definition memory_store.cpp:37
IDestination represents a sink for data received by the SDK. A destination may be a database,...
Definition idestination.hpp:14
IStore provides shared ownership of flag and segment domain objects.
Definition istore.hpp:15