Skip to content
Back to formatted view

Raw Message

Message-ID: <CAD3XY6z_KSor2RdDQKjLx1NUoeMEoTq89k6hc_N-4dpkXvQ-Dw@mail.gmail.com>
Date: 2017-02-21T13:15:53Z
From: Yousra El Bachir
Subject: [Rcpp-devel] Rcpp : passing user-defined c++ class

Hi all,

I am calling from R (say funcR) a c++ function (say funcCpp) which needs
either some programmer-defined c++ class (say programmerClassCpp1, 2,
etc...) or a user-defined c++ class (say userClassCpp). Here is an
illustration of what I am doing:

funcR(..., class="ClassCpp"){

  # do something and then call the c++ function

   funcCpp(class);
}

funcCpp(std::string classCpp){

  switch(classCpp){
      case "class1" : point to the programmer defined c++
class programmerClassCpp1; break;
      case "class2" : point to the programmer defined c++
class programmerClassCpp2; break;
      case "new": point to the user defined c++ class userClassCpp; break;
      default : Rcpp::stop("not supported class");
     };
}

This post

  http://gallery.rcpp.org/articles/passing-cpp-function-pointers/

reflects what I need for a function and I am wondering whether it is
possible to do this for a class. The obvious solution is to replicate
manually what has been done in the post to each method of the class (for
instance, work on a vector of functors to the class methods), but I don't
see it as the optimal solution.

Many thanks for any hint,
Yousra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170221/1f7461ca/attachment.html>