[Rcpp-devel] wrapping clone() via Rcpp module -- solution

Tama Ma pingnang at phys.ethz.ch
Wed Nov 16 02:05:20 CET 2011


Dear Rcpp developers,

1)	Here, I give my first attempt to solve this problem -- it is ugly but that works at least. (refer to below)
2)	Let me try to add the clone() function into the Rcpp Module...
3)	I still prefer the copy constructor solution.

	I am sorry for the delay, as digging into the source code with no little documentation really takes some time.

	Any suggestion is welcome.

Best regards,
Tama Ma



<dummy.hpp>
===========
#include <iostream>
#include <Rcpp.h>

class dummy
{
public:
  ~dummy() {}
  dummy()  {}
  dummy(double a_)          : _a(a_)       {}
  dummy(const dummy& obj_)  : _a(obj_._a)  {}

  SEXP Rcpp_clone() const { return Rcpp::internal::make_new_object<dummy>(new dummy(*this)); }

  double a()  const  { return _a; }

private:
  double _a;
};


<dummy.C>
=========
#include <Rcpp.h>
#include "dummy.hpp"


RCPP_MODULE(tamama)
{
  Rcpp::class_<dummy>("dummy")
    .default_constructor()
    .constructor<double>()
    .method( "clone" , &dummy::Rcpp_clone  )

    .method( "a"     , &dummy::a      )
    ;
}










On Nov 15, 2011, at 10:17 PM, Tama Ma wrote:

> Dear Rcpp developers,
> 
> 	As I venture on, I find that the wrapping of clone() function couldn't be wrapped. However, the same can be done in boost python. May I know how I could help fixing this bug? The following is the error log:
> 
> 
> Error log
> ====================
> g++ -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -I/opt/local/share/R-packages/Rcpp-0.9.7/inst/include -dynamiclib -o ./dummy.so ./dummy.C -L/opt/local/lib/R/lib/x86_64 -lR -lRblas -lRlapack -L/opt/local/share/R-packages/Rcpp-0.9.7/inst/lib/x86_64 -lRcpp
> In file included from /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/RcppCommon.h:313,
>                 from /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp.h:27,
>                 from ./dummy.C:1:
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h: In function 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_iterable(const T&, Rcpp::traits::false_type) [with T = dummy]':
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h:638:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&, Rcpp::traits::false_type) [with T = dummy]'
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h:654:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&, Rcpp::traits::false_type) [with T = dummy]'
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h:669:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&, Rcpp::traits::false_type) [with T = dummy]'
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h:687:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch(const T&, Rcpp::traits::wrap_type_unknown_tag) [with T = dummy]'
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h:791:   instantiated from 'SEXPREC* Rcpp::wrap(const T&) [with T = dummy]'
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/module/Module_generated_CppMethod.h:88:   instantiated from 'SEXPREC* Rcpp::const_CppMethod0<Class, OUT>::operator()(Class*, SEXPREC**) [with Class = dummy, OUT = dummy]'
> ./dummy.C:14:   instantiated from here
> /opt/local/share/R-packages/Rcpp-0.9.7/inst/include/Rcpp/internal/wrap.h:433: error: cannot convert 'const dummy' to 'SEXPREC*' in initialization
> make: *** [dummy.so] Error 1
> dhcp-192-033-102-240:Rcpp_clone tamama$ 
> 
> 
> <dummy.hpp>
> ===================
> #include <iostream>
> 
> class dummy
> {
> public:
>  ~dummy() {}
>  dummy()  {}
>  dummy(double a_)          : _a(a_)       {}
>  dummy(const dummy& obj_)  : _a(obj_._a)  {}
> 
>  dummy clone() const  { return dummy(*this); }
> 
>  double a()  const  { return _a; }
> 
> private:
>  double _a;
> };
> 
> 
> <dummy.C>
> ======================
> #include <Rcpp.h>
> #include "dummy.hpp"
> 
> 
> RCPP_MODULE(tamama)
> {
>  Rcpp::class_<dummy>("dummy")
>    .default_constructor()
>    .constructor<double>()
> 
>    .method( "clone" , &dummy::clone  )
>    .method( "a"     , &dummy::a      )
>    ;
> }
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Best regards,
> Tama Ma 
> (+41 78 640 50 15)
> 
> pingnang at phys.ethz.ch
> www.phys.ethz.ch/~pingnang
> 
> HIT K 31.3
> Institut für Theoretische Physik
> Wolfgang-Pauli-Strasse 27
> ETH Hönggerberg
> 8093 Zürich
> Switzerland
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> 


Best regards,
Tama Ma 
(+41 78 640 50 15)

pingnang at phys.ethz.ch
www.phys.ethz.ch/~pingnang

HIT K 31.3
Institut für Theoretische Physik
Wolfgang-Pauli-Strasse 27
ETH Hönggerberg
8093 Zürich
Switzerland



More information about the Rcpp-devel mailing list