[Rcpp-commits] r3821 - in pkg/Rcpp: . inst/include inst/include/Rcpp/internal inst/include/Rcpp/traits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 23 17:08:53 CEST 2012


Author: romain
Date: 2012-10-23 17:08:52 +0200 (Tue, 23 Oct 2012)
New Revision: 3821

Added:
   pkg/Rcpp/inst/include/Rcpp/traits/module_wrap_traits.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
simplify implementation of module wrap

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-10-23 14:39:05 UTC (rev 3820)
+++ pkg/Rcpp/ChangeLog	2012-10-23 15:08:52 UTC (rev 3821)
@@ -5,6 +5,8 @@
         simplified the code (removing 35% of the generated code now rendered useless)
         * include/Rcpp/module/Module_generated_PointerCppMethod.h: using module_wrap and
         simplified the code
+        * include/Rcpp/traits/module_wrap_traits.h : new file. helping implementation of 
+        module_wrap
 
 2012-10-22  Romain Francois <romain at r-enthusiasts.com>
 

Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2012-10-23 14:39:05 UTC (rev 3820)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2012-10-23 15:08:52 UTC (rev 3821)
@@ -796,24 +796,26 @@
 	return internal::wrap_dispatch( object, typename ::Rcpp::traits::wrap_type_traits<T>::wrap_category() ) ;
 }
 
+template <typename Class, typename T>
+inline SEXP module_wrap_dispatch( const T& obj, Rcpp::traits::void_wrap_tag ){
+	return R_NilValue ;
+}
 
-
-
 template <typename Class, typename T>
-inline SEXP module_wrap_dispatch( const T& obj, Rcpp::traits::true_type ){
+inline SEXP module_wrap_dispatch( const T& obj, Rcpp::traits::pointer_wrap_tag ){
 	return wrap( object<Class>( obj ) ) ;
 }
+
 template <typename Class, typename T>
-inline SEXP module_wrap_dispatch( const T& obj, Rcpp::traits::false_type ){
+inline SEXP module_wrap_dispatch( const T& obj, Rcpp::traits::normal_wrap_tag ){
 	return wrap( obj ) ;
 }
 
 template <typename Class, typename T>
 inline SEXP module_wrap( const T& obj ){
-	return module_wrap_dispatch<Class,T>( obj, Rcpp::traits::same_type<Class*,T>() ) ;	
+	return module_wrap_dispatch<Class,T>( obj, Rcpp::traits::module_wrap_traits<Class,T>::category() ) ;	
 }
 
-
 // special case - FIXME : this is not template specializations of wrap<>
 inline SEXP wrap(const char* const v ){ 
     if (v == NULL)

Added: pkg/Rcpp/inst/include/Rcpp/traits/module_wrap_traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/module_wrap_traits.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/traits/module_wrap_traits.h	2012-10-23 15:08:52 UTC (rev 3821)
@@ -0,0 +1,39 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// module_wrap_traits.h: Rcpp R/C++ interface class library -- traits to help module wrap
+//
+// 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__traits__module_wrap_traits__h
+#define Rcpp__traits__module_wrap_traits__h
+
+namespace Rcpp{
+namespace traits{
+
+struct normal_wrap_tag{} ;	
+struct void_wrap_tag{} ;
+struct pointer_wrap_tag{} ;
+	
+template <typename Class, typename T> struct module_wrap_traits   { typedef normal_wrap_tag category; } ;
+template <typename Class> struct module_wrap_traits<Class,void>   { typedef void_wrap_tag category; } ;
+template <typename Class> struct module_wrap_traits<Class,Class*> { typedef pointer_wrap_tag category; } ;
+   
+} // namespace traits
+} // namespace Rcpp
+#endif

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2012-10-23 14:39:05 UTC (rev 3820)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2012-10-23 15:08:52 UTC (rev 3821)
@@ -298,6 +298,7 @@
 #include <Rcpp/traits/storage_type.h>
 #include <Rcpp/traits/r_type_traits.h>
 #include <Rcpp/traits/wrap_type_traits.h>
+#include <Rcpp/traits/module_wrap_traits.h>
 #include <Rcpp/traits/is_na.h>
 #include <Rcpp/traits/if_.h>
 #include <Rcpp/traits/get_na.h>



More information about the Rcpp-commits mailing list