[Rcpp-commits] r3830 - in pkg/Rcpp: . inst/include inst/include/Rcpp inst/include/Rcpp/module inst/include/Rcpp/traits
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Oct 24 21:15:19 CEST 2012
Author: romain
Date: 2012-10-24 21:15:18 +0200 (Wed, 24 Oct 2012)
New Revision: 3830
Added:
pkg/Rcpp/inst/include/Rcpp/module/macros.h
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/DESCRIPTION
pkg/Rcpp/inst/include/Rcpp/as.h
pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h
pkg/Rcpp/inst/include/RcppCommon.h
Log:
helping modules as<T> where T is some class exposed by a module
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-10-24 12:44:22 UTC (rev 3829)
+++ pkg/Rcpp/ChangeLog 2012-10-24 19:15:18 UTC (rev 3830)
@@ -4,6 +4,10 @@
* include/Rcpp/traits/un_pointer.h: traits to remove a pointer
* include/Rcpp/module/Module_generated_get_return_type.h : handle pointer return types
* include/Rcpp/config.h: define RCPP_HAS_DEMANGLING for MAC OS <= 10.7 (up to Lion)
+ * include/Rcpp/module/macros.h: new file that contains macro to help with modules
+ * include/Rcpp/traits/r_type_traits.h : new tag to allow as<T> where T
+ is some class exposed in a module
+ * include/Rcpp/as.h : implementation of as<T> in that case
2012-10-23 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION 2012-10-24 12:44:22 UTC (rev 3829)
+++ pkg/Rcpp/DESCRIPTION 2012-10-24 19:15:18 UTC (rev 3830)
@@ -1,6 +1,6 @@
Package: Rcpp
Title: Seamless R and C++ Integration
-Version: 0.9.15.2
+Version: 0.9.15.3
Date: $Date$
Author: Dirk Eddelbuettel and Romain Francois, with contributions
by Douglas Bates and John Chambers
Modified: pkg/Rcpp/inst/include/Rcpp/as.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/as.h 2012-10-24 12:44:22 UTC (rev 3829)
+++ pkg/Rcpp/inst/include/Rcpp/as.h 2012-10-24 19:15:18 UTC (rev 3830)
@@ -58,10 +58,17 @@
return (T*) as_module_object_internal(x) ;
}
- template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_module_object_tag ) {
+ /** handling object<T> */
+ template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_module_object_pointer_tag ) {
return as_module_object<typename T::object_type>( x ) ;
}
+ /** handling T such that T is exposed by a module */
+ template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_module_object_tag ){
+ T* obj = as_module_object<T>(x) ;
+ return &obj ;
+ }
+
}
Added: pkg/Rcpp/inst/include/Rcpp/module/macros.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/macros.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/macros.h 2012-10-24 19:15:18 UTC (rev 3830)
@@ -0,0 +1,31 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// macros.h: Rcpp R/C++ interface class library -- helper macros for Rcpp modules
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPP_MODULE_MACROS_H
+#define RCPP_MODULE_MACROS_H
+
+/** This macros should be used by packages using modules when a type is used
+ * as a parameter of a function or method exposed by modules. This defines
+ * the necessary trait that makes the class as<>'able
+ */
+#define R_TYPE_TRAITS(CLASS) namespace Rcpp{ namespace traits { template<> struct r_type_traits< CLASS >{ typedef r_type_module_object_tag r_category ; } ; }}
+
+#endif
Modified: pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h 2012-10-24 12:44:22 UTC (rev 3829)
+++ pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h 2012-10-24 19:15:18 UTC (rev 3830)
@@ -60,8 +60,14 @@
struct r_type_pairstring_generic_tag{} ;
/**
- * identifies a module object
+ * identifies a module object pointer (i.e. something like object<T>
*/
+struct r_type_module_object_pointer_tag{} ;
+
+/**
+ * identifies a module object. Implementers of modules can define the
+ * r_type_traits to sghow that their object is handled
+ */
struct r_type_module_object_tag{} ;
/**
@@ -72,7 +78,7 @@
/**
* module object type
*/
-template <typename T> struct r_type_traits< Rcpp::object<T> >{ typedef r_type_module_object_tag r_category ; } ;
+template <typename T> struct r_type_traits< Rcpp::object<T> >{ typedef r_type_module_object_pointer_tag r_category ; } ;
/**
* special cases pair<string,T> to deal with map<string,T> etc ...
Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h 2012-10-24 12:44:22 UTC (rev 3829)
+++ pkg/Rcpp/inst/include/RcppCommon.h 2012-10-24 19:15:18 UTC (rev 3830)
@@ -64,6 +64,8 @@
} // internal
} // Rcpp
+#include <Rcpp/module/macros.h>
+
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#ifdef __GXX_EXPERIMENTAL_CXX0X__
More information about the Rcpp-commits
mailing list