[Rcpp-devel] CPP first dump on r-forge
Romain François
francoisromain at free.fr
Tue Dec 22 17:47:16 CET 2009
Hello,
(If nobody minds, I'll use this mailing list for discussing this new
project as well, since there is great overlap with Rcpp, and they might
merge at some point.)
I commited the first dump of the CPP package to r-forge:
http://r-forge.r-project.org/projects/cpp/
It currently contain S4 wrapper classes around these C++ "classes" from
the stl:
- vector<int>
- vector<double>
- vector<Rbyte> (called vector<raw>) in the R side
- set<int>
The package works like this, the CPP function (much inspired from the J
function of rJava) creates an S4 object of class "C++Class". This class
currently does not do much, but has a "new" method that can be used to
create object of this class. so for example to create a vector<int> one
can go like this:
x <- new( CPP("vector<int>") )
Then one can call methods of the C++ class using the dollar operator :
x$push_back( 1:10 )
x$size()
x$clear()
x$size()
The C++ objects are wrapped into S4 objects of a class that extends
directly or indirectly the "C++Object" class. The "C++Object" class is a
virtual class that has a slot "pointer" that is an R external pointer.
The method invocation currently uses a naming convention to determine
which C routine eventually gets called using the .Call interface. So for
example if we want to call the foo method of the bar class, and we are
passing it an integer vector and a numeric vector, i.e:
x <- new( CPP("foo") )
x$bar( 1:10, rnorm(10) )
The $ method cooks this routine name : "foo___bar___integer__double" and
attempts to call it.
C++ does not have reflection capabilities so we cannot just do
vector<MyClass> yet, but I'm starting to think about ways, perhaps using
the inline stuff ... not science fiction, but not history either. we'll see.
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/HlX9 : new package : bibtex
|- http://tr.im/Gq7i : ohloh
`- http://tr.im/FtUu : new package : highlight
More information about the Rcpp-devel
mailing list