mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-22 23:04:09 +02:00
Use std::unique_ptr for CZMQNotifierFactory.
Instead of returning a raw pointer from CZMQNotifierFactory and implicitly requiring the caller to know that it has to take ownership, return a std::unique_ptr to make this explicit. This also changes the typedef for CZMQNotifierFactory to use the new C++11 using syntax, which makes it (a little) less cryptic.
This commit is contained in:
parent
b93b9d5456
commit
7f2ad1b9ac
@ -7,10 +7,14 @@
|
|||||||
|
|
||||||
#include <zmq/zmqconfig.h>
|
#include <zmq/zmqconfig.h>
|
||||||
|
|
||||||
|
#include <util/memory.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class CZMQAbstractNotifier;
|
class CZMQAbstractNotifier;
|
||||||
|
|
||||||
typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();
|
using CZMQNotifierFactory = std::unique_ptr<CZMQAbstractNotifier> (*)();
|
||||||
|
|
||||||
class CZMQAbstractNotifier
|
class CZMQAbstractNotifier
|
||||||
{
|
{
|
||||||
@ -21,9 +25,9 @@ public:
|
|||||||
virtual ~CZMQAbstractNotifier();
|
virtual ~CZMQAbstractNotifier();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static CZMQAbstractNotifier* Create()
|
static std::unique_ptr<CZMQAbstractNotifier> Create()
|
||||||
{
|
{
|
||||||
return new T();
|
return MakeUnique<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetType() const { return type; }
|
std::string GetType() const { return type; }
|
||||||
|
@ -45,13 +45,13 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create()
|
|||||||
std::string arg("-zmq" + entry.first);
|
std::string arg("-zmq" + entry.first);
|
||||||
if (gArgs.IsArgSet(arg))
|
if (gArgs.IsArgSet(arg))
|
||||||
{
|
{
|
||||||
CZMQNotifierFactory factory = entry.second;
|
const auto& factory = entry.second;
|
||||||
std::string address = gArgs.GetArg(arg, "");
|
const std::string address = gArgs.GetArg(arg, "");
|
||||||
CZMQAbstractNotifier *notifier = factory();
|
std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
|
||||||
notifier->SetType(entry.first);
|
notifier->SetType(entry.first);
|
||||||
notifier->SetAddress(address);
|
notifier->SetAddress(address);
|
||||||
notifier->SetOutboundMessageHighWaterMark(static_cast<int>(gArgs.GetArg(arg + "hwm", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM)));
|
notifier->SetOutboundMessageHighWaterMark(static_cast<int>(gArgs.GetArg(arg + "hwm", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM)));
|
||||||
notifiers.emplace_back(notifier);
|
notifiers.push_back(std::move(notifier));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user