#include <boost/python.hpp>
#include "iostream"
#include "string"
#include "boost/weak_ptr.hpp"
#include "boost/enable_shared_from_this.hpp"

using namespace boost::python;
using namespace std;
//using Teuchos::RCP;

struct K 
// : public boost::enable_shared_from_this<K> 
{
  virtual int foo() = 0;

  virtual ~K() {
    std::cout << "destructor for K called ..." << std::endl;
  }

  /*boost::shared_ptr<K> getThisRCP() {
    return shared_from_this();
  }*/
};

struct KWrapper : public K, public boost::python::wrapper<K>, 
  public boost::enable_shared_from_this<KWrapper> 
{

  KWrapper() {

  }

  virtual int foo() {
    if( override f = this->get_override("foo") ) {
      return f();
    } else {
      return base_foo();
    }
  }

  boost::shared_ptr<KWrapper> getThisRCP2() {
    return shared_from_this();
  }

  int base_foo() {
    return 0; 
  }
};

BOOST_PYTHON_MODULE(thisRCPPy) 
{
  {
    typedef K ClassT;
    class_<KWrapper, boost::shared_ptr<KWrapper>, boost::noncopyable >("K", init<>() )
      //.def("getThisRCP", &ClassT::getThisRCP)
      .def("getThisRCP2", &KWrapper::getThisRCP2)
      .def("foo", &ClassT::foo)
      ;
  }
}
