[Rcpp-commits] r1178 - in pkg/Rcpp: . inst inst/include/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu May 6 10:42:29 CEST 2010
Author: romain
Date: 2010-05-06 10:42:29 +0200 (Thu, 06 May 2010)
New Revision: 1178
Modified:
pkg/Rcpp/NEWS
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/include/Rcpp/preprocessor.h
Log:
+ RCPP_XP_FIELD_GET and RCPP_XP_FIELD_SET macros, RCPP_XP_FIELD now does both getters and setters
Modified: pkg/Rcpp/NEWS
===================================================================
--- pkg/Rcpp/NEWS 2010-05-06 08:20:24 UTC (rev 1177)
+++ pkg/Rcpp/NEWS 2010-05-06 08:42:29 UTC (rev 1178)
@@ -45,6 +45,39 @@
// do something with foo
}
+
+ The macro RCPP_XP_FIELD_GET generates a .Call compatible function that
+ can be used to access the value of a field of a class handled by an
+ external pointer. For example with a class like this:
+
+ class Foo{
+ public:
+ int bar ;
+ }
+
+ RCPP_XP_FIELD_GET( Foo_bar_get, Foo, bar ) ;
+
+ RCPP_XP_FIELD_GET will generate the .Call compatible function called
+ Foo_bar_get that can be used to retrieved the value of bar.
+
+
+ The macro RCPP_FIELD_SET generates a .Call compatible function that
+ can be used to set the value of a field. For example:
+
+ RCPP_XP_FIELD_SET( Foo_bar_set, Foo, bar ) ;
+
+ generates the .Call compatible function called "Foo_bar_set" that
+ can be used to set the value of bar
+
+
+ The macro RCPP_XP_FIELD generates both getter and setter. For example
+
+ RCPP_XP_FIELD( Foo_bar, Foo, bar )
+
+ generates the .Call compatible Foo_bar_get and Foo_bar_set using the
+ macros RCPP_XP_FIELD_GET and RCPP_XP_FIELD_SET previously described
+
+
The macros RCPP_XP_METHOD_0, ..., RCPP_XP_METHOD_65 faciliate
calling a method of an object that is stored in an external pointer. For
example:
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-05-06 08:20:24 UTC (rev 1177)
+++ pkg/Rcpp/inst/ChangeLog 2010-05-06 08:42:29 UTC (rev 1178)
@@ -6,6 +6,11 @@
* inst/include/Rcpp/DataFrame.h: DataFrame::create now uses the R function
data.frame and not as.data.frame, which respects the stringsAsFactors
argument.
+
+ * inst/include/Rcpp/preprocessor.h: added RCPP_XP_FIELD_SET and RCPP_XP_FIELD_SET
+ macros to generate getter and setter for a field of a class handled by an
+ external pointer. RCPP_XP_FIELD is modified to generate both getter and
+ setter
2010-05-05 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/inst/include/Rcpp/preprocessor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/preprocessor.h 2010-05-06 08:20:24 UTC (rev 1177)
+++ pkg/Rcpp/inst/include/Rcpp/preprocessor.h 2010-05-06 08:42:29 UTC (rev 1178)
@@ -57,16 +57,30 @@
#include <Rcpp/preprocessor_generated.h>
-#define RCPP_XP_FIELD(__NAME__,__CLASS__,__FIELD__) \
-extern "C" SEXP __NAME__( SEXP xp ){ \
- SEXP res = R_NilValue ; \
- BEGIN_RCPP \
- ::Rcpp::XPtr<__CLASS__> ptr(xp) ; \
- res = ::Rcpp::wrap( ptr->__FIELD__ ) ; \
- END_RCPP \
- return res ; \
+#define RCPP_XP_FIELD_GET(__NAME__,__CLASS__,__FIELD__) \
+extern "C" SEXP __NAME__( SEXP xp ){ \
+ SEXP res = R_NilValue ; \
+ BEGIN_RCPP \
+ ::Rcpp::XPtr<__CLASS__> ptr(xp) ; \
+ res = ::Rcpp::wrap( ptr->__FIELD__ ) ; \
+ END_RCPP \
+ return res ; \
}
+#define RCPP_XP_FIELD_SET(__NAME__,__CLASS__,__FIELD__) \
+extern "C" SEXP __NAME__( SEXP xp, SEXP value ){ \
+ BEGIN_RCPP \
+ ::Rcpp::XPtr<__CLASS__> ptr(xp) ; \
+ ptr->__FIELD__ = ::Rcpp::internal::converter(value) ; \
+ END_RCPP \
+ return R_NilValue ; \
+}
+
+#define RCPP_XP_FIELD(__PREFIX__,__CLASS__,__FIELD__) \
+RCPP_XP_FIELD_GET( __PREFIX__##_get, __CLASS__, __FIELD__ ) \
+RCPP_XP_FIELD_SET( __PREFIX__##_set, __CLASS__, __FIELD__ )
+
+
#define RCPP_TRAITS(__CLASS__,__SEXPTYPE__) \
namespace Rcpp{ namespace traits { \
template<> struct r_type_traits<__CLASS__>{ \
More information about the Rcpp-commits
mailing list