Tidy up for C++11, and fixes:

* Remove shared_ptr legacy support
* Add make_unique support for pre-C++14 environments
* Fix comparison bug in sqdb
* Use std::shared_ptr in a few places
This commit is contained in:
Vinnie Falco
2014-01-16 18:29:30 -05:00
parent fa10e90c9d
commit c341d1a71e
20 changed files with 49 additions and 107 deletions

View File

@@ -162,7 +162,6 @@
<ClInclude Include="..\..\beast\smart_ptr\SharedObject.h" />
<ClInclude Include="..\..\beast\smart_ptr\SharedPtr.h" />
<ClInclude Include="..\..\beast\StaticAssert.h" />
<ClInclude Include="..\..\beast\STL.h" />
<ClInclude Include="..\..\beast\Strings.h" />
<ClInclude Include="..\..\beast\strings\CharacterFunctions.h" />
<ClInclude Include="..\..\beast\strings\CharPointer_ASCII.h" />

View File

@@ -1158,9 +1158,6 @@
<ClInclude Include="..\..\beast\smart_ptr\AbstractObject.h">
<Filter>beast\smart_ptr</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\STL.h">
<Filter>beast</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\Insight.h">
<Filter>beast</Filter>
</ClInclude>

View File

@@ -1,25 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_STL_H_INCLUDED
#define BEAST_STL_H_INCLUDED
#include "stl/shared_ptr.h"
#endif

View File

@@ -20,7 +20,6 @@
#ifndef BEAST_INSIGHT_COUNTERIMPL_H_INCLUDED
#define BEAST_INSIGHT_COUNTERIMPL_H_INCLUDED
#include <functional>
#include <memory>
namespace beast {

View File

@@ -20,6 +20,9 @@
#ifndef BEAST_INSIGHT_GAUGEIMPL_H_INCLUDED
#define BEAST_INSIGHT_GAUGEIMPL_H_INCLUDED
#include <functional>
#include <memory>
namespace beast {
namespace insight {

View File

@@ -22,7 +22,7 @@
#include "HookImpl.h"
#include "../stl/shared_ptr.h"
#include <memory>
namespace beast {
namespace insight {

View File

@@ -22,7 +22,7 @@
#include "MeterImpl.h"
#include "../stl/shared_ptr.h"
#include <memory>
namespace beast {
namespace insight {

View File

@@ -24,6 +24,12 @@
namespace std {
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
# ifdef _MSC_VER
# define BOOST_NO_CXX11_VARIADIC_TEMPLATES
# endif
#endif
#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
template <class T>

View File

@@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "BeastConfig.h"
#include "shared_ptr.h"

View File

@@ -1,33 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_STL_SHARED_PTR_H_INCLUDED
#define BEAST_STL_SHARED_PTR_H_INCLUDED
#include <boost/smart_ptr.hpp>
namespace beast {
using boost::shared_ptr;
using boost::make_shared;
using boost::enable_shared_from_this;
}
#endif

View File

@@ -61,7 +61,6 @@
#include "../../beast/Threads.h"
#include "../../beast/Utility.h"
#include "../../beast/Chrono.h"
#include "../../beast/STL.h"
#include "system/StandardIncludes.h"

View File

@@ -139,7 +139,8 @@ Error session::open(String fileName, std::string options)
std::stringstream ssconn(options);
while (!err && !ssconn.eof() && ssconn.str().find('=') >= 0)
while (!err && !ssconn.eof() &&
ssconn.str().find('=') != std::string::npos)
{
std::string key, val;
std::getline(ssconn, key, '=');

View File

@@ -1363,9 +1363,9 @@ Application::Application ()
{
}
Application* Application::New ()
std::unique_ptr <Application> make_Application ()
{
return new ApplicationImp;
return std::make_unique <ApplicationImp> ();
}
Application& getApp ()

View File

@@ -72,8 +72,6 @@ public:
virtual LockType& getMasterLock () = 0;
public:
static Application* New ();
Application ();
virtual ~Application () { }
@@ -127,6 +125,26 @@ public:
virtual void signalStop () = 0;
};
/** Create an instance of the Application object.
As long as there are legacy calls to getApp it is not safe
to create more than one Application object at a time.
*/
std::unique_ptr <Application> make_Application();
// VFALCO DEPRECATED
//
// Please do not write new code that calls getApp(). Instead,
// Use dependency injection to construct your class with a
// reference to the desired interface (Application in this case).
// Or better yet, instead of relying on the entire Application
// object, construct with just the interfaces that you need.
//
// When working in existing code, try to clean it up by rewriting
// calls to getApp to use a data member instead, and inject the
// needed interfaces in the constructor.
//
// http://en.wikipedia.org/wiki/Dependency_injection
//
extern Application& getApp ();
#endif

View File

@@ -154,7 +154,7 @@ public:
// code demands the Application object exists.
//
// TODO To find out who, just comment the next line out
m_app.reset (Application::New ());
m_app = make_Application();
setAssertOnFailure (false);
}
@@ -455,7 +455,7 @@ int RippleMain::run (int argc, char const* const* argv)
if (!vm.count ("parameters"))
{
// No arguments. Run server.
std::unique_ptr <Application> app (Application::New ());
std::unique_ptr <Application> app (make_Application ());
setupServer ();
startServer ();
}

View File

@@ -42,6 +42,7 @@
#include "beast/beast/Asio.h"
#include "beast/beast/asio/io_latency_probe.h"
#include "beast/beast/make_unique.h"
# include "main/CollectorManager.h"
#include "main/CollectorManager.cpp"

View File

@@ -73,9 +73,9 @@ public:
beginTestCase ("Build");
shared_ptr <Table> t1 (beast::make_shared <Table> (smtFREE));
boost::shared_ptr <Table> t1 (boost::make_shared <Table> (smtFREE));
add_random_items (tableItems, *t1, random());
shared_ptr <Table> t2 (t1->snapShot (true));
boost::shared_ptr <Table> t2 (t1->snapShot (true));
add_random_items (tableItemsExtra, *t1, random ());
add_random_items (tableItemsExtra, *t2, random ());
@@ -88,23 +88,22 @@ public:
&FetchPackTests::on_fetch, this, boost::ref (map), _1, _2));
// try to rebuild t2 from the fetch pack
shared_ptr <Table> t3;
boost::shared_ptr <Table> t3;
try
{
TestFilter filter (map, journal ());
t3 = beast::make_shared <Table> (smtFREE, t2->getHash () );
t3 = boost::make_shared <Table> (smtFREE, t2->getHash () );
expect (t3->fetchRoot (t2->getHash (), &filter), "unable to get root");
// everything should be in the pack, no hashes should be needed
std::vector<uint256> hashes = t3->getNeededHashes(1, &filter);
std::vector <uint256> hashes = t3->getNeededHashes(1, &filter);
expect (hashes.empty(), "missing hashes");
}
catch (...)
{
journal().fatal << "exception";
fail ();
failException ();
}
expect (t3->getHash () == t2->getHash (), "root hashes do not match");

View File

@@ -20,12 +20,12 @@
namespace ripple {
namespace RadixMap {
shared_ptr <Item> make_random_item (Random& r)
boost::shared_ptr <Item> make_random_item (Random& r)
{
Serializer s;
for (int d = 0; d < 3; ++d)
s.add32 (r.nextInt ());
return beast::make_shared <Item> (
return boost::make_shared <Item> (
s.getRIPEMD160().to256(), s.peekData ());
}
@@ -35,7 +35,7 @@ void add_random_items (std::size_t n, Table& t, Random& r)
{
while (n--)
{
shared_ptr <SHAMapItem> item (
boost::shared_ptr <SHAMapItem> item (
make_random_item (r));
meets_postcondition (
t.addItem (*item, false, false));

View File

@@ -26,7 +26,7 @@ typedef SHAMapItem Item;
// Utility functions for RadixMap::Table (a.k.a. SHAMap) unit tests
/** Returns a pseudo random Table item. */
shared_ptr <Item> make_random_item (Random& r);
boost::shared_ptr <Item> make_random_item (Random& r);
/** Adds a set of random items to the Table.
@param n The number of items to add.

View File

@@ -97,7 +97,7 @@ public:
{
Cache::mapped_ptr const p1 (c.fetch (3));
Cache::mapped_ptr p2 (make_shared <Value> ("three"));
Cache::mapped_ptr p2 (boost::make_shared <Value> ("three"));
c.canonicalize (3, p2);
expect (p1.get() == p2.get());
}