From d5193a776e9972db334892f7036888d2cbd6c9fd Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Mon, 10 Aug 2015 11:37:59 -0400 Subject: [PATCH] Replace calls to new(). (#243) * Replace all unavoidable uses of `new` with `std::make_unique` or `std::make_shared`. * Fix some 80-column issues. --- src/ripple/app/main/Application.cpp | 2 +- src/ripple/app/main/CollectorManager.cpp | 9 +++++---- src/ripple/app/main/CollectorManager.h | 8 +++++--- src/ripple/app/misc/HashRouter.h | 6 ++++-- src/ripple/basics/ResolverAsio.h | 6 +++--- src/ripple/basics/impl/ResolverAsio.cpp | 5 +++-- src/ripple/core/impl/JobQueue.cpp | 5 ++--- src/ripple/net/impl/HTTPClient.cpp | 20 ++++++++------------ src/ripple/peerfinder/sim/FunctionQueue.h | 4 +++- src/ripple/protocol/STAccount.h | 3 --- src/ripple/protocol/impl/STAccount.cpp | 6 ------ src/ripple/test/jtx/impl/Env.cpp | 2 +- 12 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 0b86f215ee..10b2428ac5 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -371,7 +371,7 @@ public: , m_orderBookDB (*m_jobQueue) - , m_pathRequests (new PathRequests ( + , m_pathRequests (std::make_unique ( m_logs.journal("PathRequest"), m_collectorManager->collector ())) , m_ledgerMaster (make_LedgerMaster (getConfig (), stopwatch (), diff --git a/src/ripple/app/main/CollectorManager.cpp b/src/ripple/app/main/CollectorManager.cpp index 664326cb86..f81c2b00d4 100644 --- a/src/ripple/app/main/CollectorManager.cpp +++ b/src/ripple/app/main/CollectorManager.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace ripple { @@ -56,12 +57,12 @@ public: { } - beast::insight::Collector::ptr const& collector () + beast::insight::Collector::ptr const& collector () override { return m_collector; } - beast::insight::Group::ptr const& group (std::string const& name) + beast::insight::Group::ptr const& group (std::string const& name) override { return m_groups->get (name); } @@ -73,10 +74,10 @@ CollectorManager::~CollectorManager () { } -CollectorManager* CollectorManager::New (Section const& params, +std::unique_ptr CollectorManager::New(Section const& params, beast::Journal journal) { - return new CollectorManagerImp (params, journal); + return std::make_unique(params, journal); } } diff --git a/src/ripple/app/main/CollectorManager.h b/src/ripple/app/main/CollectorManager.h index a1cf4e711f..ae33240c6a 100644 --- a/src/ripple/app/main/CollectorManager.h +++ b/src/ripple/app/main/CollectorManager.h @@ -29,11 +29,13 @@ namespace ripple { class CollectorManager { public: - static CollectorManager* New (Section const& params, - beast::Journal journal); + static std::unique_ptr New ( + Section const& params, beast::Journal journal); + virtual ~CollectorManager () = 0; virtual beast::insight::Collector::ptr const& collector () = 0; - virtual beast::insight::Group::ptr const& group (std::string const& name) = 0; + virtual beast::insight::Group::ptr const& group ( + std::string const& name) = 0; }; } diff --git a/src/ripple/app/misc/HashRouter.h b/src/ripple/app/misc/HashRouter.h index 21ca16a005..35697e00be 100644 --- a/src/ripple/app/misc/HashRouter.h +++ b/src/ripple/app/misc/HashRouter.h @@ -128,12 +128,14 @@ public: virtual ~HashRouter() = default; - // VFALCO TODO Replace "Supression" terminology with something more semantically meaningful. + // VFALCO TODO Replace "Supression" terminology with something more + // semantically meaningful. bool addSuppression (uint256 const& index); bool addSuppressionPeer (uint256 const& index, PeerShortID peer); - bool addSuppressionPeer (uint256 const& index, PeerShortID peer, int& flags); + bool addSuppressionPeer (uint256 const& index, PeerShortID peer, + int& flags); bool addSuppressionFlags (uint256 const& index, int flag); diff --git a/src/ripple/basics/ResolverAsio.h b/src/ripple/basics/ResolverAsio.h index 9f68ad0601..5a72f6e0d8 100644 --- a/src/ripple/basics/ResolverAsio.h +++ b/src/ripple/basics/ResolverAsio.h @@ -29,9 +29,9 @@ namespace ripple { class ResolverAsio : public Resolver { public: - static ResolverAsio* New ( - boost::asio::io_service& io_service, - beast::Journal journal); + static + std::unique_ptr New ( + boost::asio::io_service&, beast::Journal); }; } diff --git a/src/ripple/basics/impl/ResolverAsio.cpp b/src/ripple/basics/impl/ResolverAsio.cpp index e4ee440409..1d1592968e 100644 --- a/src/ripple/basics/impl/ResolverAsio.cpp +++ b/src/ripple/basics/impl/ResolverAsio.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -299,11 +300,11 @@ public: //----------------------------------------------------------------------------- -ResolverAsio *ResolverAsio::New ( +std::unique_ptr ResolverAsio::New ( boost::asio::io_service& io_service, beast::Journal journal) { - return new ResolverAsioImpl (io_service, journal); + return std::make_unique (io_service, journal); } //----------------------------------------------------------------------------- diff --git a/src/ripple/core/impl/JobQueue.cpp b/src/ripple/core/impl/JobQueue.cpp index bedea251f2..2714263dbe 100644 --- a/src/ripple/core/impl/JobQueue.cpp +++ b/src/ripple/core/impl/JobQueue.cpp @@ -257,10 +257,9 @@ public: assert (iter != m_jobData.end ()); if (iter == m_jobData.end ()) - return LoadEvent::autoptr (); + return {}; - return LoadEvent::autoptr ( - new LoadEvent (iter-> second.load (), name, true)); + return std::make_unique (iter-> second.load (), name, true); } void addLoadEvents (JobType t, diff --git a/src/ripple/net/impl/HTTPClient.cpp b/src/ripple/net/impl/HTTPClient.cpp index e333aecdda..b9a4b26e05 100644 --- a/src/ripple/net/impl/HTTPClient.cpp +++ b/src/ripple/net/impl/HTTPClient.cpp @@ -167,11 +167,10 @@ public: { WriteLog (lsTRACE, HTTPClient) << "Fetch: " << mDeqSites[0]; - std::shared_ptr query ( - new boost::asio::ip::tcp::resolver::query ( + auto query = std::make_shared( mDeqSites[0], beast::lexicalCast (mPort), - boost::asio::ip::resolver_query_base::numeric_service)); + boost::asio::ip::resolver_query_base::numeric_service); mQuery = query; mDeadline.expires_from_now (mTimeout, mShutdown); @@ -528,9 +527,8 @@ void HTTPClient::get ( std::function complete) { - std::shared_ptr client ( - new HTTPClientImp (io_service, port, responseMax)); - + auto client = std::make_shared ( + io_service, port, responseMax); client->get (bSSL, deqSites, strPath, timeout, complete); } @@ -547,9 +545,8 @@ void HTTPClient::get ( { std::deque deqSites (1, strSite); - std::shared_ptr client ( - new HTTPClientImp (io_service, port, responseMax)); - + auto client = std::make_shared ( + io_service, port, responseMax); client->get (bSSL, deqSites, strPath, timeout, complete); } @@ -566,9 +563,8 @@ void HTTPClient::request ( { std::deque deqSites (1, strSite); - std::shared_ptr client ( - new HTTPClientImp (io_service, port, responseMax)); - + auto client = std::make_shared ( + io_service, port, responseMax); client->request (bSSL, deqSites, setRequest, timeout, complete); } diff --git a/src/ripple/peerfinder/sim/FunctionQueue.h b/src/ripple/peerfinder/sim/FunctionQueue.h index 189bfd7de0..5a55bba0eb 100644 --- a/src/ripple/peerfinder/sim/FunctionQueue.h +++ b/src/ripple/peerfinder/sim/FunctionQueue.h @@ -62,7 +62,9 @@ public: */ template void post (Function f) - { m_work.emplace_back (new Work (f)); } + { + m_work.emplace_back (std::make_unique>(f)); + } /** Run all pending functions. The functions will be invoked in the order they were queued. diff --git a/src/ripple/protocol/STAccount.h b/src/ripple/protocol/STAccount.h index 3a6747d5f3..21ec92e4ff 100644 --- a/src/ripple/protocol/STAccount.h +++ b/src/ripple/protocol/STAccount.h @@ -105,9 +105,6 @@ public: } bool isValueH160 () const; - -private: - static STAccount* construct (SerialIter&, SField const&); }; } // ripple diff --git a/src/ripple/protocol/impl/STAccount.cpp b/src/ripple/protocol/impl/STAccount.cpp index 9428113a00..36e59c0452 100644 --- a/src/ripple/protocol/impl/STAccount.cpp +++ b/src/ripple/protocol/impl/STAccount.cpp @@ -39,12 +39,6 @@ std::string STAccount::getText () const return toBase58(u); } -STAccount* -STAccount::construct (SerialIter& u, SField const& name) -{ - return new STAccount (name, u.getVLBuffer ()); -} - STAccount::STAccount (SField const& n, AccountID const& v) : STBlob (n, v.data (), v.size ()) { diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp index ea6053ba11..dfccc61aa9 100644 --- a/src/ripple/test/jtx/impl/Env.cpp +++ b/src/ripple/test/jtx/impl/Env.cpp @@ -262,7 +262,7 @@ Env::submit (JTx const& jt) [&](OpenView& view, beast::Journal j) { std::tie(ter, didApply) = ripple::apply( - view, *stx, applyFlags(), + view, *stx, applyFlags(), directSigVerify, config, beast::Journal{}); return didApply;