29 #ifndef GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H
30 #define GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H
34 #include "GpgConstants.h"
62 static
int GetDefaultChannel();
69 [[nodiscard]]
int GetChannel() const;
76 void SetChannel(
int channel);
79 int channel_ = _default_channel;
80 static constexpr
int _default_channel = 0;
90 void ReleaseChannel(
int channel);
105 std::vector<int> GetAllChannelId();
115 std::unique_ptr<ChannelObject> p_obj);
119 std::map<int, std::unique_ptr<ChannelObject>>
142 std::map<size_t, std::unique_ptr<SingletonStorage>> storages_map_;
149 template <
typename T>
173 int channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL) {
174 static std::mutex g_channel_mutex_map_lock;
175 static std::map<int, std::mutex> g_channel_mutex_map;
178 std::lock_guard<std::mutex> guard(g_channel_mutex_map_lock);
179 if (g_channel_mutex_map.find(channel) == g_channel_mutex_map.end()) {
180 g_channel_mutex_map[channel];
185 "T not derived from SingletonFunctionObject<T>");
190 auto* _p_pbj = (T*)(p_storage->FindObjectInChannel(channel));
192 if (_p_pbj ==
nullptr) {
194 std::lock_guard<std::mutex> guard(g_channel_mutex_map[channel]);
197 if ((_p_pbj = (T*)(p_storage->FindObjectInChannel(channel))) !=
nullptr)
201 auto new_obj = std::unique_ptr<ChannelObject>(
new T(channel));
202 return *(T*)(p_storage->SetObjectInChannel(channel, std::move(new_obj)));
217 std::function<std::unique_ptr<ChannelObject>(
void)> factory) {
219 "T not derived from SingletonFunctionObject<T>");
225 auto _p_pbj = (T*)(p_storage->FindObjectInChannel(channel));
227 if (_p_pbj ==
nullptr) {
229 T*)(p_storage->SetObjectInChannel(channel, std::move(factory())));
287 void operator=(
const T&) =
delete;
object which in channel system
Definition: GpgFunctionObject.h:42
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.cpp:41
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.cpp:43
ChannelObject() noexcept
Construct a new Default Channel Object object.
Definition: GpgFunctionObject.h:150
SingletonFunctionObject()=default
Construct a new Singleton Function Object object.
static T & CreateInstance(int channel, std::function< std::unique_ptr< ChannelObject >(void)> factory)
Create a Instance object.
Definition: GpgFunctionObject.h:215
SingletonFunctionObject(const SingletonFunctionObject< T > &)=delete
prohibit copy
SingletonFunctionObject(int channel)
Construct a new Singleton Function Object object.
Definition: GpgFunctionObject.h:301
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:251
static std::vector< int > GetAllChannelId()
Get all the channel ids.
Definition: GpgFunctionObject.h:265
static T & GetInstance(int channel=GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL)
Get the Instance object.
Definition: GpgFunctionObject.h:172
SingletonFunctionObject(const T &)=delete
Construct a new Singleton Function Object object.
virtual ~SingletonFunctionObject()=default
Destroy the Singleton Function Object object.
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.h:258
SingletonFunctionObject & operator=(const SingletonFunctionObject< T > &)=delete
prohibit copy
SingletonFunctionObject(T &&)=delete
Construct a new Singleton Function Object object.
static void ReleaseChannel(int channel)
Definition: GpgFunctionObject.h:240
Definition: GpgFunctionObject.h:123
SingletonStorage * GetSingletonStorage(const std::type_info &)
Get the Singleton Storage object.
Definition: GpgFunctionObject.cpp:97
std::shared_mutex storages_mutex_
mutex for storages_map_
Definition: GpgFunctionObject.h:141
static SingletonStorageCollection * GetInstance(bool force_refresh)
Get the Instance object.
Definition: GpgFunctionObject.cpp:122
Definition: GpgFunctionObject.h:83
std::shared_mutex instances_mutex_
mutex for _instances_map
Definition: GpgFunctionObject.h:118
std::vector< int > GetAllChannelId()
Get all the channel ids.
Definition: GpgFunctionObject.cpp:69
std::map< int, std::unique_ptr< ChannelObject > > instances_map_
map of singleton instances
Definition: GpgFunctionObject.h:120
void ReleaseChannel(int channel)
Definition: GpgFunctionObject.cpp:45
Executive files related to the basic operations that are provided by GpgBasicOperator.
Definition: CoreCommonUtil.cpp:31