Hello,

I've added support for properties in classes that are exposed by Rcpp modules.

Here is a full example that works with inline 0.3.5 and the svn version of Rcpp:

        inc  <- '
        class Num{
        public:
            Num() : x(0.0), y(0){} ;
        
            double getX() const { return x ; }
            void setX(double value){ x = value ; }
        
            int getY() { return y ; }
        
        private:
            double x ;
            int y ;
        };
        
        RCPP_MODULE(yada){
                using namespace Rcpp ;
        
                class_<Num>( "Num" )
                
                        // read and write property
                        .property( "x", &Num::getX, &Num::setX )
                        
                        // read-only property
                        .property( "y", &Num::getY )
                ;
        }
        '
        fx <- cxxfunction( signature(), "" , include = inc, plugin = "Rcpp" )



> mod <- Module( "yada", getDynLib(fx) )
> Num <- mod$Num
>     w <- new( Num )
> w$x
[1] 0
> w$x <- 3
> w$x
[1] 3
> w$y
[1] 0
> w$y <- 6L
Erreur dans `$<-`(`*tmp*`, "y", value = 6L) : property is read only

The vignette (http://addictedtor.free.fr/misc/rcpp/Rcpp-modules.pdf) has been updated to document this.

For public data members, I might do what Boost.Python does later:
http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_data_members


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/c6YnCi : graph gallery collage
|- http://bit.ly/bZ7ltC : inline 0.3.5
`- http://bit.ly/8YUsiC : highlight 0.2-0

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to