3#include "GlobalParam.h"
74 ~SingleThreadParam()
override =
default;
98 using container_t = std::unordered_map<concurrent_key_t, T>;
102 ~MemoizedParam()
override =
default;
111 container_t m_container;
120 class ConcurrentParamFactory {
123 ConcurrentParamFactory() =
delete;
129 template <
typename T>
130 static std::unique_ptr<ConcurrentParam<T>>
Create() {
136 return std::make_unique<SingleThreadParam<T>>();
138 return std::make_unique<MemoizedParam<T>>();
140 throw std::runtime_error(
"unknown GlobalConcurrencyModel '" +
GlobalConcurrencyModel() +
"'; valid options are 'single' or 'memoize'");
static std::unique_ptr< ConcurrentParam< T > > Create()
create a new ConcurrentParam-derived class instance
virtual void Save(T const &value, concurrent_key_t const key)=0
modify a value
std::mutex m_mutex
mutex for this ConcurrentParam
bool m_needs_hashing
whether this ConcurrentParam needs hashing for calling Load or Save
virtual bool HasKey(concurrent_key_t const key) const =0
bool NeedsHashing() const
whether or not hashing is needed to use this parameter
virtual std::size_t GetSize() const =0
bool m_empty
whether this ConcurrentParam has something saved
virtual T const Load(concurrent_key_t const key) const =0
access a stored value
ConcurrentParam(std::string const &model)
T const Load(concurrent_key_t const key) const override
access a stored value
bool HasKey(concurrent_key_t const key) const override
std::size_t GetSize() const override
void Save(T const &value, concurrent_key_t const key) override
modify a value
std::size_t GetSize() const override
void Save(T const &value, concurrent_key_t const key) override
modify a value
T const Load(concurrent_key_t const key) const override
access a stored value
bool HasKey(concurrent_key_t const key) const override
General, top-level namespace for algorithms and infrastructure. For algorithms and bindings,...
std::size_t concurrent_key_t
concurrent hash key type
GlobalParam< std::string > GlobalConcurrencyModel
The concurrency model, for running certain algorithms in a thread-safe way.