Made the data argument in Point's __init__method to be an optional argument by making it a boost::python::optional. dev
authorAravindakshan Babu <akshan@stanford.edu>
Fri, 02 Jul 2010 17:08:02 -0700
branchdev
changeset 216 7aefb2d67203
parent 215 e94d521b72bb
child 217 64a272a34cb2
Made the data argument in Point's __init__method to be an optional argument by making it a boost::python::optional.
bindings/python/persistence-diagram.cpp
--- a/bindings/python/persistence-diagram.cpp	Fri Jul 02 04:19:29 2010 -0700
+++ b/bindings/python/persistence-diagram.cpp	Fri Jul 02 17:08:02 2010 -0700
@@ -2,6 +2,7 @@
 #include<utilities/types.h>
 
 #include<boost/python.hpp>
+#include<boost/python/init.hpp>
 #include<boost/shared_ptr.hpp>
 #include<boost/python/stl_iterator.hpp>
 #include <boost/python/def.hpp>
@@ -21,15 +22,6 @@
 
 namespace dp = dionysus::python;
 
-// TBD: Make the Data argument optional. Use bp::None ?
-template<class PDPoint>
-boost::shared_ptr< PDPoint >    init_from_coords( bp::object x_obj, bp::object y_obj, dp::Data d ){
-
-    RealType x = bp::extract<RealType>( x_obj ); RealType y = bp::extract<RealType>( y_obj );
-    boost::shared_ptr< PDPoint > p( new PDPoint( x, y, d ) );
-    return p;
-
-}
 
 template<class PDPoint>
 RealType    get_x_coord( const PDPoint& p ){
@@ -49,7 +41,7 @@
 void export_point( ){
 
     bp::class_<dp::PointD>("Point")
-    .def( "__init__", bp::make_constructor( &init_from_coords<dp::PointD> ) )
+    .def( bp::init< RealType, RealType, bp::optional<dp::Data>  >( ) )
     .add_property( "x", &get_x_coord<dp::PointD> )
     .add_property( "y", &get_y_coord<dp::PointD> )
     .add_property( "data", &get_data<dp::PointD> )