Commit 2ae8ad35 authored by Kenneth Leiter's avatar Kenneth Leiter

Use std::shared_ptr in Python bindings

parent b71d08cb
......@@ -121,7 +121,6 @@ MACRO(ADD_TEST_PYTHON executable)
-D "EXECUTABLE=${executable}"
-D "ARGUMENTS=${arguments}"
-D "PYTHONPATH=${python_pythonpath}"
-D "LDPATH=${python_ldpath}"
-D "PATH=${python_path}"
-D "SEPARATOR=${sep}"
-P "${python_binary_dir}/TestDriverPython.cmake"
......
......@@ -1120,49 +1120,49 @@ vXdmfSetRemoveAttribute(XDMFSET * set, unsigned int index);
PyObject * XdmfItemCast(shared_ptr<XdmfItem> obj) {
PyObject * result;
if(shared_ptr<XdmfAttribute> attribute = shared_dynamic_cast<XdmfAttribute>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfAttribute>(attribute)), SWIGTYPE_p_boost__shared_ptrT_XdmfAttribute_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfAttribute>(attribute)), SWIGTYPE_p_std__shared_ptrT_XdmfAttribute_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfCurvilinearGrid> gridCurvilinear = shared_dynamic_cast<XdmfCurvilinearGrid>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfCurvilinearGrid>(gridCurvilinear)), SWIGTYPE_p_boost__shared_ptrT_XdmfCurvilinearGrid_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfCurvilinearGrid>(gridCurvilinear)), SWIGTYPE_p_std__shared_ptrT_XdmfCurvilinearGrid_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfGridCollection> gridCollection = shared_dynamic_cast<XdmfGridCollection>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGridCollection>(gridCollection)), SWIGTYPE_p_boost__shared_ptrT_XdmfGridCollection_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGridCollection>(gridCollection)), SWIGTYPE_p_std__shared_ptrT_XdmfGridCollection_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfDomain> domain = shared_dynamic_cast<XdmfDomain>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfDomain>(domain)), SWIGTYPE_p_boost__shared_ptrT_XdmfDomain_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfDomain>(domain)), SWIGTYPE_p_std__shared_ptrT_XdmfDomain_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfGeometry> geometry = shared_dynamic_cast<XdmfGeometry>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGeometry>(geometry)), SWIGTYPE_p_boost__shared_ptrT_XdmfGeometry_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGeometry>(geometry)), SWIGTYPE_p_std__shared_ptrT_XdmfGeometry_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfGraph> graph = shared_dynamic_cast<XdmfGraph>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGraph>(graph)), SWIGTYPE_p_boost__shared_ptrT_XdmfGraph_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGraph>(graph)), SWIGTYPE_p_std__shared_ptrT_XdmfGraph_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfInformation> information = shared_dynamic_cast<XdmfInformation>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfInformation>(information)), SWIGTYPE_p_boost__shared_ptrT_XdmfInformation_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfInformation>(information)), SWIGTYPE_p_std__shared_ptrT_XdmfInformation_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfMap> map = shared_dynamic_cast<XdmfMap>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfMap>(map)), SWIGTYPE_p_boost__shared_ptrT_XdmfMap_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfMap>(map)), SWIGTYPE_p_std__shared_ptrT_XdmfMap_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfRectilinearGrid> gridRectilinear = shared_dynamic_cast<XdmfRectilinearGrid>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfRectilinearGrid>(gridRectilinear)), SWIGTYPE_p_boost__shared_ptrT_XdmfRectilinearGrid_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfRectilinearGrid>(gridRectilinear)), SWIGTYPE_p_std__shared_ptrT_XdmfRectilinearGrid_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfRegularGrid> gridRegular = shared_dynamic_cast<XdmfRegularGrid>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfRegularGrid>(gridRegular)), SWIGTYPE_p_boost__shared_ptrT_XdmfRegularGrid_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfRegularGrid>(gridRegular)), SWIGTYPE_p_std__shared_ptrT_XdmfRegularGrid_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfSet> set = shared_dynamic_cast<XdmfSet>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfSet>(set)), SWIGTYPE_p_boost__shared_ptrT_XdmfSet_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfSet>(set)), SWIGTYPE_p_std__shared_ptrT_XdmfSet_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfTime> time = shared_dynamic_cast<XdmfTime>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfTime>(time)), SWIGTYPE_p_boost__shared_ptrT_XdmfTime_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfTime>(time)), SWIGTYPE_p_std__shared_ptrT_XdmfTime_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfTopology> topology = shared_dynamic_cast<XdmfTopology>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfTopology>(topology)), SWIGTYPE_p_boost__shared_ptrT_XdmfTopology_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfTopology>(topology)), SWIGTYPE_p_std__shared_ptrT_XdmfTopology_t, SWIG_POINTER_OWN);
}
else if(shared_ptr<XdmfUnstructuredGrid> gridUnstructured = shared_dynamic_cast<XdmfUnstructuredGrid>(obj)) {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfUnstructuredGrid>(gridUnstructured)), SWIGTYPE_p_boost__shared_ptrT_XdmfUnstructuredGrid_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfUnstructuredGrid>(gridUnstructured)), SWIGTYPE_p_std__shared_ptrT_XdmfUnstructuredGrid_t, SWIG_POINTER_OWN);
}
else {
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfItem>(obj)), SWIGTYPE_p_boost__shared_ptrT_XdmfItem_t, SWIG_POINTER_OWN);
result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfItem>(obj)), SWIGTYPE_p_std__shared_ptrT_XdmfItem_t, SWIG_POINTER_OWN);
}
return result;
}
......
......@@ -17,6 +17,7 @@ if(VERSION_CONTROL_AUTOUPDATE OR
)
endif()
option(BUILD_SHARED_LIBS "Build the shared library" ON)
if(BUILD_SHARED_LIBS)
set(LIBTYPE SHARED)
set(BUILD_SHARED 1)
......@@ -116,22 +117,6 @@ endif()
TEST_BIG_ENDIAN(XDMF_BIG_ENDIAN)
unset(HAVE_BOOST_SHARED_DYNAMIC_CAST CACHE)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Boost_INCLUDE_DIRS})
check_cxx_source_compiles("
#include <boost/shared_ptr.hpp>
struct Base { virtual ~Base(){} };
struct Derived : public Base {};
int main(int ac, char * av[])
{
boost::shared_ptr<Base> ptr(new Base());
boost::shared_dynamic_cast<Derived>(ptr);
}
"
HAVE_BOOST_SHARED_DYNAMIC_CAST)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XdmfCoreConfig.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/XdmfCoreConfig.hpp)
......
......@@ -24,7 +24,6 @@
#ifndef XDMFCONFIG_HPP_
#define XDMFCONFIG_HPP_
#cmakedefine HAVE_BOOST_SHARED_DYNAMIC_CAST
#cmakedefine HAVE_CXX11_ENABLE_IF
#cmakedefine XDMF_BIG_ENDIAN
......
......@@ -434,14 +434,14 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
// Define equality operators
%extend XdmfItem {
bool equals(boost::shared_ptr<XdmfItem> item) {
bool equals(std::shared_ptr<XdmfItem> item) {
if (item == NULL) {
return false;
}
return self == item.get();
}
bool IsEqual(boost::shared_ptr<XdmfItem> item) {
bool IsEqual(std::shared_ptr<XdmfItem> item) {
if (item == NULL) {
return false;
}
......@@ -451,14 +451,14 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%extend XdmfItemProperty {
bool equals(boost::shared_ptr<XdmfItemProperty> itemProperty) {
bool equals(std::shared_ptr<XdmfItemProperty> itemProperty) {
if (itemProperty == NULL) {
return false;
}
return self == itemProperty.get();
}
bool IsEqual(boost::shared_ptr<XdmfItemProperty> itemProperty) {
bool IsEqual(std::shared_ptr<XdmfItemProperty> itemProperty) {
if (itemProperty == NULL) {
return false;
}
......@@ -564,7 +564,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
static shared_ptr<XdmfHDF5Controller> XdmfHDF5ControllerCast(PyObject * obj)
{
void * resultPointer = 0;
swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfHeavyDataController_t");
swig_type_info * returnType = SWIG_TypeQuery("_p_std__shared_ptrT_XdmfHeavyDataController_t");
SWIG_ConvertPtr(obj, &resultPointer, returnType, 0);
shared_ptr<XdmfHeavyDataController> * returnControllerPointer =
reinterpret_cast<shared_ptr<XdmfHeavyDataController> *>(resultPointer);
......@@ -944,7 +944,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
static shared_ptr<XdmfArray> XdmfArrayPtr(PyObject * obj)
{
void * resultPointer = 0;
swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
swig_type_info * returnType = SWIG_TypeQuery("_p_std__shared_ptrT_XdmfArray_t");
SWIG_ConvertPtr(obj, &resultPointer, returnType, 0);
shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
......@@ -1169,7 +1169,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
virtual shared_ptr<XdmfArray> execute(std::vector<shared_ptr<XdmfArray> > valueVector)
{
swig_type_info * paramType = SWIG_TypeQuery("_p_std__vectorT_boost__shared_ptrT_XdmfArray_t_std__allocatorT_boost__shared_ptrT_XdmfArray_t_t_t");
swig_type_info * paramType = SWIG_TypeQuery("_p_std__vectorT_std__shared_ptrT_XdmfArray_t_std__allocatorT_std__shared_ptrT_XdmfArray_t_t_t");
PyObject * pyVector = SWIG_NewPointerObj(static_cast<void*>(& valueVector), paramType, SWIG_POINTER_NEW);
PyObject * args = PyTuple_New(1);
/* In this case you could also cast a pointer to the vector
......@@ -1177,7 +1177,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
PyTuple_SetItem(args, 0, pyVector);
PyObject * resultObject = PyObject_CallObject(mInternalFunction, args);
void * resultPointer = 0;
swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
swig_type_info * returnType = SWIG_TypeQuery("_p_std__shared_ptrT_XdmfArray_t");
SWIG_ConvertPtr(resultObject, &resultPointer, returnType, 0);
shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
......@@ -1216,7 +1216,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
virtual shared_ptr<XdmfArray> execute(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
swig_type_info * paramType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
swig_type_info * paramType = SWIG_TypeQuery("_p_std__shared_ptrT_XdmfArray_t");
PyObject * pyVal1 = SWIG_NewPointerObj(static_cast<void*>(& val1), paramType, SWIG_POINTER_NEW);
PyObject * pyVal2 = SWIG_NewPointerObj(static_cast<void*>(& val2), paramType, SWIG_POINTER_NEW);
PyObject * args = PyTuple_New(2);
......@@ -1224,7 +1224,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
PyTuple_SetItem(args, 1, pyVal2);
PyObject * resultObject = PyObject_CallObject(mInternalOperation, args);
void * resultPointer = 0;
swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
swig_type_info * returnType = SWIG_TypeQuery("_p_std__shared_ptrT_XdmfArray_t");
SWIG_ConvertPtr(resultObject, &resultPointer, returnType, 0);
shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
......@@ -1261,12 +1261,12 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
#endif /* SWIGPYTHON */
%include boost_shared_ptr.i
%include std_shared_ptr.i
%inline
%{
#include <boost/shared_ptr.hpp>
using namespace boost;
#include <memory>
using namespace std;
%}
%include std_string.i
......@@ -1306,8 +1306,8 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
// Abstract Base Classes
%template(BaseVisitable) Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
%template(LokiArrayVisitor) Loki::Visitor<XdmfArray>;
%template(LokiItemVisitor) Loki::Visitor<XdmfItem>;
%include XdmfCore.hpp
%include XdmfError.hpp
......@@ -1411,9 +1411,9 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(Float32Vector) std::vector<float>;
%template(Float64Vector) std::vector<double>;
%template(StringVector) std::vector<std::string>;
%template(ItemVector) std::vector<boost::shared_ptr<XdmfItem> >;
%template(HeavyControllerVector) std::vector<boost::shared_ptr<XdmfHeavyDataController> >;
%template(ArrayMap) std::map<std::string, boost::shared_ptr<XdmfArray> >;
%template(ItemVector) std::vector<std::shared_ptr<XdmfItem> >;
%template(HeavyControllerVector) std::vector<std::shared_ptr<XdmfHeavyDataController> >;
%template(ArrayMap) std::map<std::string, std::shared_ptr<XdmfArray> >;
%template(StringMap) std::map<std::string, std::string>;
%template(DSMStructreVector) std::vector<std::pair<std::string, unsigned int> >;
%template(DSMApplicationPair) std::pair<std::string, unsigned int>;
......@@ -29,26 +29,14 @@
#include <memory>
#include "XdmfCoreConfig.hpp"
//#include <boost/shared_ptr.hpp>
using std::shared_ptr;
using std::const_pointer_cast;
//using boost::shared_ptr;
//using boost::const_pointer_cast;
//#ifdef HAVE_BOOST_SHARED_DYNAMIC_CAST
//using boost::shared_dynamic_cast;
//#else
template <typename T, typename U>
shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
{
typedef typename shared_ptr<T>::element_type E;
E * p = dynamic_cast< E* >( r.get() );
return p? shared_ptr<T>( r, p ): shared_ptr<T>();
return std::dynamic_pointer_cast<T>(r);
}
//#endif /* HAVE_BOOST_SHARED_DYNAMIC_CAST */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment