[Rcpp-commits] r3133 - 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
Wed Jul 13 11:59:05 CEST 2011


Author: romain
Date: 2011-07-13 11:59:04 +0200 (Wed, 13 Jul 2011)
New Revision: 3133

Added:
   pkg/Rcpp/inst/include/Rcpp/traits/is_eigen_base.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
helping RcppEigen for real

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-07-11 13:33:06 UTC (rev 3132)
+++ pkg/Rcpp/ChangeLog	2011-07-13 09:59:04 UTC (rev 3133)
@@ -1,3 +1,11 @@
+2011-07-13  Romain Francois  <romain at r-enthusiasts.com>
+
+    * inst/include/Rcpp/traits/is_eigen_base.h: helper traits to facilitate 
+    implementation of the RcppEigen package. The is_eigen_base traits identifies
+    if a class derives from EigenBase using SFINAE
+    
+    * inst/include/Rcpp/internal/wrap.h: new layer of dispatch to help RcppEigen
+
 2011-07-07  Romain Francois  <romain at r-enthusiasts.com>
 
     * inst/include/Rcpp/XPtr.h: The XPtr class template gains a second template

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2011-07-11 13:33:06 UTC (rev 3132)
+++ pkg/Rcpp/DESCRIPTION	2011-07-13 09:59:04 UTC (rev 3133)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Seamless R and C++ Integration
-Version: 0.9.5
+Version: 0.9.5.1
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, 
  with contributions by Douglas Bates and John Chambers

Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2011-07-11 13:33:06 UTC (rev 3132)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2011-07-13 09:59:04 UTC (rev 3133)
@@ -29,7 +29,10 @@
 // don't include it directly
 
 namespace Rcpp{
-
+	namespace RcppEigen{
+		template <typename T> SEXP eigen_wrap( const T& object ) ;
+	}
+	
 template <typename T> SEXP wrap( const T& object ) ;
 
 template <typename T> class CustomImporter ;
@@ -646,13 +649,24 @@
 	return primitive_wrap( object ) ;
 }
 
+template <typename T>
+inline SEXP wrap_dispatch_eigen( const T& object, ::Rcpp::traits::false_type){
+	return wrap_dispatch_unknown( object, typename ::Rcpp::traits::is_convertible<T,SEXP>::type() ) ;
+}
+
+template <typename T>
+inline SEXP wrap_dispatch_eigen( const T& object, ::Rcpp::traits::true_type){
+	return ::Rcpp::RcppEigen::eigen_wrap( object ) ;
+}
+
+
 /**
  * called when T is wrap_type_unknown_tag and is not an Importer class
  * The next step is to try implicit conversion to SEXP
  */
 template <typename T> 
 inline SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::false_type){
-	return wrap_dispatch_unknown( object, typename ::Rcpp::traits::is_convertible<T,SEXP>::type() ) ;
+	return wrap_dispatch_eigen( object, typename traits::is_eigen_base<T>::type() ) ;
 }
 
 /**

Added: pkg/Rcpp/inst/include/Rcpp/traits/is_eigen_base.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/is_eigen_base.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/traits/is_eigen_base.h	2011-07-13 09:59:04 UTC (rev 3133)
@@ -0,0 +1,47 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// is_sugar_expression.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2011 Doug Bates, 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__is_eigen_base_h
+#define Rcpp__traits__is_eigen_base_h
+
+namespace Rcpp{
+namespace traits{
+
+	template<typename T>
+	class _is_eigen_helper : __sfinae_types {
+      template<typename U> struct _Wrap_type { };
+
+      template<typename U>
+        static __one __test(_Wrap_type<typename U::StorageKind>*);
+
+      template<typename U>
+        static __two __test(...);
+
+    public:
+      static const bool value = sizeof(__test<T>(0)) == 1;
+    };
+  
+  template<typename T> struct is_eigen_base : 
+  	integral_constant<bool, _is_eigen_helper<T>::value >{ };
+
+}
+}
+#endif

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2011-07-11 13:33:06 UTC (rev 3132)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2011-07-13 09:59:04 UTC (rev 3133)
@@ -272,6 +272,7 @@
 #include <Rcpp/traits/expands_to_logical.h>
 #include <Rcpp/traits/matrix_interface.h>
 #include <Rcpp/traits/is_sugar_expression.h>
+#include <Rcpp/traits/is_eigen_base.h>
 #include <Rcpp/traits/has_na.h>
 #include <Rcpp/traits/storage_type.h>
 #include <Rcpp/traits/r_sexptype_traits.h>



More information about the Rcpp-commits mailing list