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 committed Aug 10, 2015
1 parent 1b85b6e commit eb10697
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 55 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 @@ -373,7 +373,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
8 changes: 4 additions & 4 deletions src/ripple/app/main/CollectorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,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 +73,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
12 changes: 6 additions & 6 deletions src/ripple/app/misc/HashRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class HashRouter : public IHashRouter
};

public:
explicit HashRouter (int holdTime)
: mHoldTime (holdTime)
explicit HashRouter (int entryHoldTimeInSeconds)
: mEntryHoldTimeInSeconds (entryHoldTimeInSeconds)
{
}

Expand Down Expand Up @@ -124,7 +124,7 @@ class HashRouter : public IHashRouter
// Stores all expiration times and the hashes indexed for them
std::map< int, std::list<uint256> > mSuppressionTimes;

int mHoldTime;
int mEntryHoldTimeInSeconds;
};

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -164,7 +164,7 @@ HashRouter::Entry& HashRouter::findCreateEntry (uint256 const& index, bool& crea
created = true;

int now = UptimeTimer::getInstance ().getElapsedSeconds ();
int expireTime = now - mHoldTime;
int expireTime = now - mEntryHoldTimeInSeconds;

// See if any supressions need to be expired
std::map< int, std::list<uint256> >::iterator it = mSuppressionTimes.begin ();
Expand Down Expand Up @@ -271,9 +271,9 @@ bool HashRouter::swapSet (uint256 const& index, std::set<PeerShortID>& peers, in
return true;
}

IHashRouter* IHashRouter::New (int holdTime)
std::unique_ptr<IHashRouter> IHashRouter::New (int entryHoldTimeInSeconds)
{
return new HashRouter (holdTime);
return std::make_unique<HashRouter> (entryHoldTimeInSeconds);
}

} // ripple
16 changes: 8 additions & 8 deletions src/ripple/app/misc/IHashRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ class IHashRouter
return 300;
}

// VFALCO TODO rename the parameter to entryHoldTimeInSeconds
static IHashRouter* New (int holdTime);
static std::unique_ptr<IHashRouter> New (int entryHoldTimeInSeconds);

virtual ~IHashRouter () { }

// VFALCO TODO Replace "Supression" terminology with something more semantically meaningful.
// VFALCO TODO Replace "Supression" terminology with something more
// semantically meaningful.
virtual bool addSuppression (uint256 const& index) = 0;

virtual bool addSuppressionPeer (uint256 const& index, PeerShortID peer) = 0;

virtual bool addSuppressionPeer (uint256 const& index, PeerShortID peer, int& flags) = 0;
virtual bool addSuppressionPeer(uint256 const& index, PeerShortID) = 0;
virtual bool addSuppressionPeer(
uint256 const& index, PeerShortID, int& flags) = 0;

virtual bool addSuppressionFlags (uint256 const& index, int flag) = 0;

Expand All @@ -82,7 +81,8 @@ class IHashRouter

virtual int getFlags (uint256 const& index) = 0;

virtual bool swapSet (uint256 const& index, std::set<PeerShortID>& peers, int flag) = 0;
virtual bool swapSet (
uint256 const& index, std::set<PeerShortID>&, int flag) = 0;

/**
Function wrapper that will check the signature status
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
4 changes: 2 additions & 2 deletions src/ripple/basics/impl/ResolverAsio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,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
5 changes: 2 additions & 3 deletions src/ripple/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ Env::close(NetClock::time_point const& closeTime)
for (auto iter = cur->txs.begin();
iter != cur->txs.end(); ++iter)
txs.push_back(iter->first);
std::unique_ptr<IHashRouter> router(
IHashRouter::New(60));
auto router = IHashRouter::New(60);
OrderedTxs retries(uint256{});
{
OpenView accum(&*next);
Expand Down Expand Up @@ -263,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 eb10697

Please sign in to comment.