GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
|
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())));
292 #endif // GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H
int channel_
The channel id.
Definition: GpgFunctionObject.h:77
Definition: GpgFunctionObject.h:148
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.cpp:43
SingletonStorage * GetSingletonStorage(const std::type_info &)
Get the Singleton Storage object.
Definition: GpgFunctionObject.cpp:99
Definition: CoreCommonUtil.cpp:29
static T & GetInstance(int channel=GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL)
Get the Instance object.
Definition: GpgFunctionObject.h:170
SingletonFunctionObject(int channel)
Construct a new Singleton Function Object object.
Definition: GpgFunctionObject.h:282
SingletonFunctionObject & operator=(const SingletonFunctionObject< T > &)=delete
prohibit copy
void SetChannel(int channel)
Set the Channel object.
Definition: GpgFunctionObject.cpp:39
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.h:239
virtual ~SingletonFunctionObject()=default
Destroy the Singleton Function Object object.
ChannelObject * SetObjectInChannel(int channel, std::unique_ptr< ChannelObject > p_obj)
Set a new object in channel object.
Definition: GpgFunctionObject.cpp:79
std::map< int, std::unique_ptr< ChannelObject > > instances_map_
map of singleton instances
Definition: GpgFunctionObject.h:118
std::shared_mutex storages_mutex_
mutex for storages_map_
Definition: GpgFunctionObject.h:139
Definition: GpgFunctionObject.h:121
ChannelObject * FindObjectInChannel(int channel)
Definition: GpgFunctionObject.cpp:56
static SingletonStorageCollection * GetInstance()
Get the Instance object.
Definition: GpgFunctionObject.cpp:125
static std::vector< int > GetAllChannelId()
Get all the channel ids.
Definition: GpgFunctionObject.h:246
ChannelObject() noexcept
Construct a new Default Channel Object object.
static T & CreateInstance(int channel, std::function< std::unique_ptr< ChannelObject >(void)> factory)
Create a Instance object.
Definition: GpgFunctionObject.h:196
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.cpp:45
object which in channel system
Definition: GpgFunctionObject.h:40
SingletonFunctionObject()=default
Construct a new Singleton Function Object object.
void ReleaseChannel(int channel)
Definition: GpgFunctionObject.cpp:47
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:232
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
static void ReleaseChannel(int channel)
Definition: GpgFunctionObject.h:221