[Rcpp-devel] Exposed C++-Class used within another exposed C++-Class

Dirk Eddelbuettel edd at debian.org
Tue Jun 29 05:07:19 CEST 2010


Hi Paul,

Thanks for your interest in Rcpp, and for posting here!

On 28 June 2010 at 16:48, Paul Theodor Pyl wrote:
| Hi,
| 
| I have a C++Class 'DSV' that I have successfully made accessible from R 
| with the following piece of code:
| 
| RCPP_MODULE(blubb){
| 
| using namespace Rcpp;
| 
| typedef DSV< int, int > DSVi;
| class_< DSVi >( "DSVi" )
| .method( "get", &DSVi::get )
| .method( "set", &DSVi::set )
| .method( "add", &DSVi::add )
| .method( "info", &DSVi::rinfo )
| .method( "apply", &aply< int, int > )
| ;
| 
| class_< DSVVec >( "DSVVec" )
| .method( "[[", &DSVVec::operator[] )
| .method( "load", &DSVVec::load );
| }
| 
| Now I would like to use another C++-class that will contain a vector of 
| DSV's, for example like so:
| 
| class DSVVec{
| 
| public:
| 
| DSVVec() {};
| 
| void load( std::string filename ) {
| /* ... */
| }
| 
| DSV< int, int > & operator[]( std::string name ){
| return dsvs[ GetID( name ) ];
| }
| 
| int GetID( std::string n ){ /* ... */ }
| 
| private:
| std::vector< DSV< int, int > > dsvs;
| 
| };
| 
| When I try this I get an error message from Rcpp that the generic 
| wrapping around DSV< int, int > has failed.
| (/wrap.h:395: error: cannot convert ‘const DSV<int, int>’ to ‘SEXPREC*’ 
| in initialization)
| Now the question is how to get 'DSVVec' to apply my already defined 
| wrapper for 'DSV' on the return value of it's operator[] function?

Tricky.  Now the entire layering would need to be recursive. Not sure if that
can be accomodated easily.

Maybe you have to punt and write a 'normal' interface / package rather than
using modules.  Or maybe Romain has another idea that will save your day.

Cheers, Dirk

| I use Rcpp 0.8.2 as downloaded from CRAN.
| 
| Cheers,
| Paul
| _______________________________________________
| 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

-- 
  Regards, Dirk


More information about the Rcpp-devel mailing list