[Rcpp-devel] public data members in modules
romain at r-enthusiasts.com
romain at r-enthusiasts.com
Fri Jun 11 08:30:28 CEST 2010
Hello,
I've added "field" and "field_readonly" to allow exposing public data members of
a c++ class. For example (from the unit tests):
test.Module.member <- function(){
inc <- '
class Num{
public:
Num() : x(0.0), y(0){} ;
double x ;
int y ;
};
RCPP_MODULE(yada){
using namespace Rcpp ;
class_<Num>( "Num" )
// read and write data member
.field( "x", &Num::x )
// read only data member
.field_readonly( "y", &Num::y )
;
}
'
fx <- cxxfunction( signature(), "" , include = inc, plugin = "Rcpp" )
mod <- Module( "yada", getDynLib(fx) )
Num <- mod$Num
w <- new( Num )
checkEquals( w$x, 0.0 )
checkEquals( w$y, 0L )
w$x <- 2.0
checkEquals( w$x, 2.0 )
checkException( { w$y <- 3 } )
}
I've added a subsection on the vignette to reflect the addition.
Romain
More information about the Rcpp-devel
mailing list