Skip to content

Commit

Permalink
Replace calls to new(). (XRPLF#243)
Browse files Browse the repository at this point in the history
* Replace all unavoidable uses of `new` with `std::make_unique` or
  `std::make_shared`.

* Fix some 80-column issues.
  • Loading branch information
rec authored and scottschurr committed Sep 3, 2015
1 parent ef51128 commit d5193a7
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class ApplicationImp

, m_orderBookDB (*m_jobQueue)

, m_pathRequests (new PathRequests (
, m_pathRequests (std::make_unique<PathRequests> (
m_logs.journal("PathRequest"), m_collectorManager->collector ()))

, m_ledgerMaster (make_LedgerMaster (getConfig (), stopwatch (),
Expand Down
9 changes: 5 additions & 4 deletions src/ripple/app/main/CollectorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <BeastConfig.h>
#include <ripple/app/main/CollectorManager.h>
#include <beast/cxx14/memory.h>

namespace ripple {

Expand Down Expand Up @@ -56,12 +57,12 @@ class CollectorManagerImp
{
}

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);
}
Expand All @@ -73,10 +74,10 @@ CollectorManager::~CollectorManager ()
{
}

CollectorManager* CollectorManager::New (Section const& params,
std::unique_ptr<CollectorManager> CollectorManager::New(Section const& params,
beast::Journal journal)
{
return new CollectorManagerImp (params, journal);
return std::make_unique<CollectorManagerImp>(params, journal);
}

}
8 changes: 5 additions & 3 deletions src/ripple/app/main/CollectorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ namespace ripple {
class CollectorManager
{
public:
static CollectorManager* New (Section const& params,
beast::Journal journal);
static std::unique_ptr<CollectorManager> 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;
};

}
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/app/misc/HashRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ class HashRouter

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);

Expand Down
6 changes: 3 additions & 3 deletions src/ripple/basics/ResolverAsio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolverAsio> New (
boost::asio::io_service&, beast::Journal);
};

}
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/basics/impl/ResolverAsio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ripple/basics/ResolverAsio.h>
#include <beast/asio/IPAddressConversion.h>
#include <beast/asio/placeholders.h>
#include <beast/cxx14/memory.h>
#include <beast/module/asio/AsyncObject.h>
#include <beast/threads/WaitableEvent.h>
#include <boost/asio.hpp>
Expand Down Expand Up @@ -299,11 +300,11 @@ class ResolverAsioImpl

//-----------------------------------------------------------------------------

ResolverAsio *ResolverAsio::New (
std::unique_ptr<ResolverAsio> ResolverAsio::New (
boost::asio::io_service& io_service,
beast::Journal journal)
{
return new ResolverAsioImpl (io_service, journal);
return std::make_unique<ResolverAsioImpl> (io_service, journal);
}

//-----------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions src/ripple/core/impl/JobQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,9 @@ class JobQueueImp
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<LoadEvent> (iter-> second.load (), name, true);
}

void addLoadEvents (JobType t,
Expand Down
20 changes: 8 additions & 12 deletions src/ripple/net/impl/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ class HTTPClientImp
{
WriteLog (lsTRACE, HTTPClient) << "Fetch: " << mDeqSites[0];

std::shared_ptr <boost::asio::ip::tcp::resolver::query> query (
new boost::asio::ip::tcp::resolver::query (
auto query = std::make_shared<boost::asio::ip::tcp::resolver::query>(
mDeqSites[0],
beast::lexicalCast <std::string> (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);
Expand Down Expand Up @@ -528,9 +527,8 @@ void HTTPClient::get (
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
std::string const& strData)> complete)
{
std::shared_ptr <HTTPClientImp> client (
new HTTPClientImp (io_service, port, responseMax));

auto client = std::make_shared<HTTPClientImp> (
io_service, port, responseMax);
client->get (bSSL, deqSites, strPath, timeout, complete);
}

Expand All @@ -547,9 +545,8 @@ void HTTPClient::get (
{
std::deque<std::string> deqSites (1, strSite);

std::shared_ptr <HTTPClientImp> client (
new HTTPClientImp (io_service, port, responseMax));

auto client = std::make_shared<HTTPClientImp> (
io_service, port, responseMax);
client->get (bSSL, deqSites, strPath, timeout, complete);
}

Expand All @@ -566,9 +563,8 @@ void HTTPClient::request (
{
std::deque<std::string> deqSites (1, strSite);

std::shared_ptr <HTTPClientImp> client (
new HTTPClientImp (io_service, port, responseMax));

auto client = std::make_shared<HTTPClientImp> (
io_service, port, responseMax);
client->request (bSSL, deqSites, setRequest, timeout, complete);
}

Expand Down
4 changes: 3 additions & 1 deletion src/ripple/peerfinder/sim/FunctionQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class FunctionQueue
*/
template <typename Function>
void post (Function f)
{ m_work.emplace_back (new Work <Function> (f)); }
{
m_work.emplace_back (std::make_unique<Work <Function>>(f));
}

/** Run all pending functions.
The functions will be invoked in the order they were queued.
Expand Down
3 changes: 0 additions & 3 deletions src/ripple/protocol/STAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ class STAccount final
}

bool isValueH160 () const;

private:
static STAccount* construct (SerialIter&, SField const&);
};

} // ripple
Expand Down
6 changes: 0 additions & 6 deletions src/ripple/protocol/impl/STAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ())
{
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d5193a7

Please sign in to comment.