Hermann Rodrigues | 12 May 16:16

Re: Making smart pointers a bit smarter

I solve an related problem, wrapping C++ Boost shared_ptr code to
Java, using the following typemaps:

namespace boost {

template < typename T >
class shared_ptr {
protected:
  shared_ptr();

public:
  %typemap(out) shared_ptr<T> {
    if ( (&$1)->get() == 0 )
      return $null;

    *( boost::shared_ptr<T> ** )&jresult = new boost::shared_ptr<T>( (
boost::shared_ptr<T> & )result );
  }

  %typemap(javaout) shared_ptr<T> {
    long ptr = $jnicall;
    if ( ptr == 0 )
      return null;
    return new $javaclassname( ptr, $owner );
  }

  T *operator->() const;
};

}

Boost::shared_ptr causes an assertion failure when the operator->() is
used to dereference a shared_ptr with an underlying NULL pointer.
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig


Gmane