Replace boost::shared_ptr/weak_ptr by std::shared_ptr/weak_ptr

This commit is contained in:
gallaert 2020-04-19 12:05:45 +01:00 committed by James Turner
parent 5c52cdc255
commit 1e13cf6fec
5 changed files with 32 additions and 34 deletions

View File

@ -27,8 +27,6 @@
#include <osgText/Font>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <map>
#include <vector>
@ -62,8 +60,8 @@ namespace canvas
#define SG_FWD_DECL(name)\
class name;\
typedef boost::shared_ptr<name> name##Ptr;\
typedef boost::weak_ptr<name> name##WeakPtr;
typedef std::shared_ptr<name> name##Ptr;\
typedef std::weak_ptr<name> name##WeakPtr;
SG_FWD_DECL(Placement)
SG_FWD_DECL(SystemAdapter)

View File

@ -33,16 +33,22 @@
#include <boost/call_traits.hpp>
#include <boost/function.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/shared_ptr.hpp>
#include <map>
#include <memory>
template<class T>
inline T* get_pointer(boost::weak_ptr<T> const& p)
inline T* get_pointer(std::weak_ptr<T> const& p)
{
return p.lock().get();
}
template<class T>
inline T* get_pointer(std::shared_ptr<T> const& p)
{
return p.get();
}
template<class T>
inline T* get_pointer(SGWeakPtr<T> const& p)
{
@ -77,7 +83,7 @@ get_pointer(T ptr)
// With old g++ on Jenkins (21.07.2014), ADL for static_pointer_cast does not
// work.
using boost::static_pointer_cast;
using std::static_pointer_cast;
using osg::static_pointer_cast;
#else
// VS (2008, 2010, ... ?) only allow this version.
@ -193,7 +199,7 @@ namespace nasal
* int myMember();
* void doSomethingElse(const nasal::CallContext& ctx);
* }
* using MyClassPtr = boost::shared_ptr<MyClass>;
* using MyClassPtr = std::shared_ptr<MyClass>;
*
* std::string myOtherFreeMember(int num);
*
@ -201,7 +207,7 @@ namespace nasal
* {
* // Register a nasal ghost type for MyClass. This needs to be done only
* // once before creating the first ghost instance. The exposed class needs
* // to be wrapped inside a shared pointer, eg. boost::shared_ptr.
* // to be wrapped inside a shared pointer, eg. std::shared_ptr.
* Ghost<MyClassPtr>::init("MyClass")
* // Members can be exposed by getters and setters
* .member("x", &MyClass::getX, &MyClass::setX)

View File

@ -30,11 +30,12 @@ template<class T> class SGWeakPtr;
template<class T> class SGVec2;
template<class T> class SGVec4;
namespace boost
namespace std
{
template<class T> class shared_ptr;
template<class T> class weak_ptr;
}
namespace osg
{
class Referenced;
@ -114,7 +115,7 @@ SG_MAKE_TRAIT(<>, osg::Vec4f, is_vec4)
SG_MAKE_SHARED_PTR_TRAIT(SGSharedPtr, SGWeakPtr, true)
SG_MAKE_SHARED_PTR_TRAIT(osg::ref_ptr, osg::observer_ptr, true)
SG_MAKE_SHARED_PTR_TRAIT(boost::shared_ptr, boost::weak_ptr, false)
SG_MAKE_SHARED_PTR_TRAIT(std::shared_ptr, std::weak_ptr, false)
#undef SG_MAKE_SHARED_PTR_TRAIT

View File

@ -9,9 +9,6 @@
#include <simgear/math/SGMath.hxx>
#include <simgear/structure/map.hxx>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <cstring>
enum MyEnum
@ -79,7 +76,7 @@ struct DoubleDerived:
};
typedef boost::shared_ptr<Base> BasePtr;
typedef std::shared_ptr<Base> BasePtr;
typedef std::vector<BasePtr> BaseVec;
struct DoubleDerived2:
@ -102,13 +99,13 @@ class SGWeakReferenceBasedClass:
};
typedef boost::shared_ptr<Derived> DerivedPtr;
typedef boost::shared_ptr<DoubleDerived> DoubleDerivedPtr;
typedef boost::shared_ptr<DoubleDerived2> DoubleDerived2Ptr;
typedef std::shared_ptr<Derived> DerivedPtr;
typedef std::shared_ptr<DoubleDerived> DoubleDerivedPtr;
typedef std::shared_ptr<DoubleDerived2> DoubleDerived2Ptr;
typedef SGSharedPtr<SGReferenceBasedClass> SGRefBasedPtr;
typedef SGSharedPtr<SGWeakReferenceBasedClass> SGWeakRefBasedPtr;
typedef boost::weak_ptr<Derived> DerivedWeakPtr;
typedef std::weak_ptr<Derived> DerivedWeakPtr;
naRef derivedFreeMember(Derived&, const nasal::CallContext&) { return naNil(); }
naRef f_derivedGetX(const Derived& d, naContext c)
@ -361,9 +358,9 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing )
BOOST_CHECK_EQUAL( c.from_nasal<BasePtr>(derived), d3 );
BOOST_CHECK_NE( c.from_nasal<BasePtr>(derived), d2 );
BOOST_CHECK_EQUAL( c.from_nasal<DerivedPtr>(derived),
boost::dynamic_pointer_cast<Derived>(d3) );
std::dynamic_pointer_cast<Derived>(d3) );
BOOST_CHECK_EQUAL( c.from_nasal<DoubleDerived2Ptr>(derived),
boost::dynamic_pointer_cast<DoubleDerived2>(d3) );
std::dynamic_pointer_cast<DoubleDerived2>(d3) );
BOOST_CHECK_THROW( c.from_nasal<DoubleDerivedPtr>(derived), bad_nasal_cast );
std::map<std::string, BasePtr> instances;

View File

@ -6,10 +6,6 @@
#include <simgear/nasal/cppbind/Ghost.hxx>
#include <simgear/nasal/cppbind/NasalContext.hxx>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
class Base1:
public virtual SGVirtualWeakReferenced
{};
@ -43,7 +39,7 @@ typedef SGSharedPtr<SGReferenced> SGReferencedPtr;
CHECK_PTR_TRAIT_TYPE(weak, weak_ref, weak)\
CHECK_PTR_TRAIT(DerivedPtr, DerivedWeakPtr)
CHECK_PTR_TRAIT(boost::shared_ptr<Base1>, boost::weak_ptr<Base1>)
CHECK_PTR_TRAIT(std::shared_ptr<Base1>, std::weak_ptr<Base1>)
#undef CHECK_PTR_TRAIT
#undef CHECK_PTR_TRAIT_TYPE
@ -150,11 +146,11 @@ BOOST_AUTO_TEST_CASE( ghost_casting_storage )
CHECK_PTR_STORAGE_TRAIT_TYPE(DerivedPtr, Derived)
CHECK_PTR_STORAGE_TRAIT_TYPE(DerivedWeakPtr, DerivedWeakPtr)
typedef boost::shared_ptr<Derived> BoostDerivedPtr;
CHECK_PTR_STORAGE_TRAIT_TYPE(BoostDerivedPtr, BoostDerivedPtr)
typedef std::shared_ptr<Derived> StdDerivedPtr;
CHECK_PTR_STORAGE_TRAIT_TYPE(StdDerivedPtr, StdDerivedPtr)
typedef boost::weak_ptr<Derived> BoostDerivedWeakPtr;
CHECK_PTR_STORAGE_TRAIT_TYPE(BoostDerivedWeakPtr, BoostDerivedWeakPtr)
typedef std::weak_ptr<Derived> StdDerivedWeakPtr;
CHECK_PTR_STORAGE_TRAIT_TYPE(StdDerivedWeakPtr, StdDerivedWeakPtr)
#undef CHECK_PTR_STORAGE_TRAIT_TYPE
@ -164,8 +160,8 @@ BOOST_STATIC_ASSERT(( nasal::shared_ptr_traits<DerivedPtr>::is_intrusive::value)
BOOST_STATIC_ASSERT(( nasal::shared_ptr_traits<DerivedWeakPtr>::is_intrusive::value));
BOOST_STATIC_ASSERT(( nasal::shared_ptr_traits<SGReferencedPtr>::is_intrusive::value));
BOOST_STATIC_ASSERT((!nasal::shared_ptr_traits<boost::shared_ptr<Derived> >::is_intrusive::value));
BOOST_STATIC_ASSERT((!nasal::shared_ptr_traits<boost::weak_ptr<Derived> >::is_intrusive::value));
BOOST_STATIC_ASSERT((!nasal::shared_ptr_traits<std::shared_ptr<Derived> >::is_intrusive::value));
BOOST_STATIC_ASSERT((!nasal::shared_ptr_traits<std::weak_ptr<Derived> >::is_intrusive::value));
BOOST_AUTO_TEST_CASE( storage_traits )
{
@ -207,7 +203,7 @@ BOOST_AUTO_TEST_CASE( bind_methods )
arg4 = a4;
}
};
using TestClassPtr = boost::shared_ptr<TestClass>;
using TestClassPtr = std::shared_ptr<TestClass>;
auto set_func = boost::function<
void (TestClass&, int, const std::string&, const std::string&, int)
>(&TestClass::set);
@ -216,7 +212,7 @@ BOOST_AUTO_TEST_CASE( bind_methods )
.method("setReverse", set_func, std::index_sequence<3,2,1,0>{});
TestContext ctx;
auto test = boost::make_shared<TestClass>();
auto test = std::make_shared<TestClass>();
ctx.exec("me.set(1, \"s2\", \"s3\", 4);", ctx.to_me(test));
BOOST_CHECK_EQUAL(test->arg1, 1);