29 #ifndef GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H
30 #define GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H
32 #include "GpgConstants.h"
60 static
int GetDefaultChannel();
67 [[nodiscard]]
int GetChannel() const;
74 void SetChannel(
int channel);
77 int channel_ = _default_channel;
78 static constexpr
int _default_channel = 0;
88 void ReleaseChannel(
int channel);
103 std::vector<int> GetAllChannelId();
113 std::unique_ptr<ChannelObject> p_obj);
117 std::map<int, std::unique_ptr<ChannelObject>>
140 std::map<size_t, std::unique_ptr<SingletonStorage>> storages_map_;
147 template <
typename T>
171 int channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL) {
173 "T not derived from SingletonFunctionObject<T>");
179 auto* _p_pbj = (T*)(p_storage->FindObjectInChannel(channel));
181 if (_p_pbj ==
nullptr) {
182 auto new_obj = std::unique_ptr<ChannelObject>(
new T(channel));
183 return *(T*)(p_storage->SetObjectInChannel(channel, std::move(new_obj)));
198 std::function<std::unique_ptr<ChannelObject>(
void)> factory) {
200 "T not derived from SingletonFunctionObject<T>");
206 auto _p_pbj = (T*)(p_storage->FindObjectInChannel(channel));
208 if (_p_pbj ==
nullptr) {
210 T*)(p_storage->SetObjectInChannel(channel, std::move(factory())));
268 void operator=(
const T&) =
delete;
object which in channel system
Definition: GpgFunctionObject.h:40
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.cpp:43
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.cpp:45
ChannelObject() noexcept
Construct a new Default Channel Object object.
Definition: GpgFunctionObject.h:148
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:196
SingletonFunctionObject(const SingletonFunctionObject< T > &)=delete
prohibit copy
SingletonFunctionObject(int channel)
Construct a new Singleton Function Object object.
Definition: GpgFunctionObject.h:282
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:232
static std::vector< int > GetAllChannelId()
Get all the channel ids.
Definition: GpgFunctionObject.h:246
static T & GetInstance(int channel=GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL)
Get the Instance object.
Definition: GpgFunctionObject.h:170
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:239
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:221
Definition: GpgFunctionObject.h:121
SingletonStorage * GetSingletonStorage(const std::type_info &)
Get the Singleton Storage object.
Definition: GpgFunctionObject.cpp:99
std::shared_mutex storages_mutex_
mutex for storages_map_
Definition: GpgFunctionObject.h:139
static SingletonStorageCollection * GetInstance(bool force_refresh)
Get the Instance object.
Definition: GpgFunctionObject.cpp:125
Definition: GpgFunctionObject.h:81
std::shared_mutex instances_mutex_
mutex for _instances_map
Definition: GpgFunctionObject.h:116
std::vector< int > GetAllChannelId()
Get all the channel ids.
Definition: GpgFunctionObject.cpp:71
std::map< int, std::unique_ptr< ChannelObject > > instances_map_
map of singleton instances
Definition: GpgFunctionObject.h:118
void ReleaseChannel(int channel)
Definition: GpgFunctionObject.cpp:47
Executive files related to the basic operations that are provided by GpgBasicOperator.
Definition: CoreCommonUtil.cpp:29