[Rcpp-commits] r546 - in pkg: . inst src src/Rcpp src/Rcpp/internal src/Rcpp/traits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Feb 1 18:23:50 CET 2010


Author: romain
Date: 2010-02-01 18:23:49 +0100 (Mon, 01 Feb 2010)
New Revision: 546

Added:
   pkg/src/Rcpp/traits/
   pkg/src/Rcpp/traits/wrap_type_traits.h
Modified:
   pkg/NEWS
   pkg/inst/ChangeLog
   pkg/src/Makevars
   pkg/src/Makevars.win
   pkg/src/Rcpp/internal/wrap.h
   pkg/src/RcppCommon.h
Log:
added Rcpp::traits namespace to host Rcpp's type traits

Modified: pkg/NEWS
===================================================================
--- pkg/NEWS	2010-02-01 16:48:42 UTC (rev 545)
+++ pkg/NEWS	2010-02-01 17:23:49 UTC (rev 546)
@@ -1,6 +1,9 @@
 
 0.7.5	(under development)
 
+    o	a new namespace Rcpp::traits has been added to host the various
+    	type traits used by wrap
+
     o 	wrap is now able to handle more stl and tr1 types. Given that T
     	can be wrapped, the following can be wrapped: 
     	- std::list<T>

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-02-01 16:48:42 UTC (rev 545)
+++ pkg/inst/ChangeLog	2010-02-01 17:23:49 UTC (rev 546)
@@ -1,3 +1,9 @@
+2010-02-01  Romain Francois <francoisromain at free.fr>
+
+	* src/traits/wrap_type_traits.h: new namespace Rcpp::traits::
+	to host Rcpp type traits used by the template meta programming 
+	dispatching of wrap
+
 2010-01-31  Dirk Eddelbuettel  <edd at debian.org>
 
 	* doxyfile: several updates plus improvements related to examples/

Modified: pkg/src/Makevars
===================================================================
--- pkg/src/Makevars	2010-02-01 16:48:42 UTC (rev 545)
+++ pkg/src/Makevars	2010-02-01 17:23:49 UTC (rev 546)
@@ -39,10 +39,12 @@
 		- at if test ! -e $(USERDIR)$(R_ARCH); then mkdir -p $(USERDIR)$(R_ARCH); fi
 		- at if test ! -e $(USERDIR)$(R_ARCH)/Rcpp; then mkdir -p $(USERDIR)$(R_ARCH)/Rcpp; fi
 		- at if test ! -e $(USERDIR)$(R_ARCH)/Rcpp/internal; then mkdir -p $(USERDIR)$(R_ARCH)/Rcpp/internal; fi
+		- at if test ! -e $(USERDIR)$(R_ARCH)/Rcpp/traits; then mkdir -p $(USERDIR)$(R_ARCH)/Rcpp/traits; fi
 		cp $(USERLIB) $(USERDIR)$(R_ARCH)
 		cp Rcpp*.h $(USERDIR)$(R_ARCH)
 		cp Rcpp/*.h $(USERDIR)$(R_ARCH)/Rcpp
 		cp Rcpp/internal/*.h $(USERDIR)$(R_ARCH)/Rcpp/internal
+		cp Rcpp/traits/*.h $(USERDIR)$(R_ARCH)/Rcpp/traits
 		cp $(USERLIBST) $(USERDIR)$(R_ARCH)
 		rm $(USERLIB) $(USERLIBST)
 

Modified: pkg/src/Makevars.win
===================================================================
--- pkg/src/Makevars.win	2010-02-01 16:48:42 UTC (rev 545)
+++ pkg/src/Makevars.win	2010-02-01 17:23:49 UTC (rev 546)
@@ -69,6 +69,7 @@
 		cp -vax *.h $(USERDIR)
 		cp -vax Rcpp/*.h $(USERDIR)/Rcpp
 		cp -vax Rcpp/internal/*.h $(USERDIR)/Rcpp/internal
+		cp -vax Rcpp/traits/*.h $(USERDIR)/Rcpp/traits
 
 
 

Modified: pkg/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/src/Rcpp/internal/wrap.h	2010-02-01 16:48:42 UTC (rev 545)
+++ pkg/src/Rcpp/internal/wrap.h	2010-02-01 17:23:49 UTC (rev 546)
@@ -82,43 +82,6 @@
 template<> void r_init_vector<STRSXP>(SEXP x) ;
 // }}}
 
-// {{{ wrap_type_traits
-struct wrap_type_stl_container_tag{};    // stl type container, with begin and end methods
-struct wrap_type_primitive_tag{};        // primitive type
-struct wrap_type_unknown_tag{};          // unknown, not sure what to do with this type
-
-template <typename T> struct wrap_type_traits { typedef wrap_type_unknown_tag category; } ;
-
-// partial specialization for stl containers
-template <typename T> struct wrap_type_traits< std::vector<T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::list<T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::set<T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::deque<T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::multiset<T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::map<std::string,T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::multimap<std::string,T> > { typedef wrap_type_stl_container_tag category ; } ;
-#ifdef HAS_TR1_UNORDERED_MAP
-template <typename T> struct wrap_type_traits< std::tr1::unordered_map<std::string,T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::tr1::unordered_multimap<std::string,T> > { typedef wrap_type_stl_container_tag category ; } ;
-#endif
-#ifdef HAS_TR1_UNORDERED_SET
-template <typename T> struct wrap_type_traits< std::tr1::unordered_set<T> > { typedef wrap_type_stl_container_tag category ; } ;
-template <typename T> struct wrap_type_traits< std::tr1::unordered_multiset<T> > { typedef wrap_type_stl_container_tag category ; } ;
-#endif
-
-// #ifdef HAS_INIT_LISTS
-// template <typename T> struct wrap_type_traits< std::initializer_list<T> > { typedef wrap_type_stl_container_tag category ; } ;
-// #endif
-template <> struct wrap_type_traits<int> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<double> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<Rbyte> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<Rcomplex> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<size_t> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<bool> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<std::string> { typedef wrap_type_primitive_tag category; } ;
-template <> struct wrap_type_traits<char> { typedef wrap_type_primitive_tag category; } ;
-// }}}
-
 // {{{ r_type_traits
 struct r_type_primitive_tag{} ;
 struct r_type_string_tag{} ;
@@ -369,16 +332,16 @@
 
 // {{{ wrap dispatch
 // generic wrap for stl containers
-template <typename T> SEXP wrap_dispatch( const T& object, wrap_type_stl_container_tag ){
+template <typename T> SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_stl_container_tag ){
 	return range_wrap( object.begin(), object.end() ) ;
 }
 // wrapping a primitive type : int, double, std::string
-template <typename T> SEXP wrap_dispatch( const T& object, wrap_type_primitive_tag ){
+template <typename T> SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_primitive_tag ){
 	return primitive_wrap( object ) ;
 }
 // when we don't know how to deal with it, we try implicit conversion
 // if the type T is convertible to SEXP
-template <typename T> SEXP wrap_dispatch( const T& object, wrap_type_unknown_tag ){
+template <typename T> SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_unknown_tag ){
 	return wrap_dispatch_unknown( object, typename is_convertible<T,SEXP>::type() ) ;
 }
 // }}}
@@ -386,7 +349,7 @@
 } // internal
 
 template <typename T> SEXP wrap(const T& object){
-	return internal::wrap_dispatch( object, typename internal::wrap_type_traits<T>::category() ) ;
+	return internal::wrap_dispatch( object, typename ::Rcpp::traits::wrap_type_traits<T>::wrap_category() ) ;
 }
 // {{{ // explicit instanciations (not needed)
 // template SEXP wrap<int>(const int& object) ;

Added: pkg/src/Rcpp/traits/wrap_type_traits.h
===================================================================
--- pkg/src/Rcpp/traits/wrap_type_traits.h	                        (rev 0)
+++ pkg/src/Rcpp/traits/wrap_type_traits.h	2010-02-01 17:23:49 UTC (rev 546)
@@ -0,0 +1,90 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// wrap_type_traits.h: Rcpp R/C++ interface class library -- traits to help wrap
+//
+// Copyright (C) 2010	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__wrap_type_traits__h
+#define Rcpp__traits__wrap_type_traits__h
+
+namespace Rcpp{
+namespace traits{
+
+/**
+ * Identifies an stl type container, with begin and end methods. 
+ */
+struct wrap_type_stl_container_tag{};
+
+/**
+ * primitive type : int, double, std::string, Rcomplex, size_t, Rbyte
+ */
+struct wrap_type_primitive_tag{};
+
+/**
+ * unknown. Implicit conversion to SEXP will be tried.
+ */
+struct wrap_type_unknown_tag{};          // unknown, not sure what to do with this type
+
+/**
+ * Type trait that helps the dispatch of wrap to the proper method
+ *
+ * This builds a struct that contains a typedef called wrap_category
+ * that has to be one of "wrap_type_stl_container_tag", 
+ * "wrap_type_primitive_tag" or "wrap_type_unknown_tag"
+ *
+ * The default is "wrap_type_unknown_tag" and many
+ * partial or complete specializations
+ * are defined below.
+ */
+template <typename T> struct wrap_type_traits { typedef wrap_type_unknown_tag wrap_category; } ;
+
+/**
+ * partial specialization for stl containers
+ */ 
+template <typename T> struct wrap_type_traits< std::vector<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::list<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::set<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::deque<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::multiset<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::map<std::string,T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::multimap<std::string,T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+#ifdef HAS_TR1_UNORDERED_MAP
+template <typename T> struct wrap_type_traits< std::tr1::unordered_map<std::string,T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::tr1::unordered_multimap<std::string,T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+#endif
+#ifdef HAS_TR1_UNORDERED_SET
+template <typename T> struct wrap_type_traits< std::tr1::unordered_set<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+template <typename T> struct wrap_type_traits< std::tr1::unordered_multiset<T> > { typedef wrap_type_stl_container_tag wrap_category ; } ;
+#endif
+
+/**
+ * Total specialization for primitive types
+ */
+template <> struct wrap_type_traits<int> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<double> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<Rbyte> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<Rcomplex> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<size_t> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<bool> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<std::string> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits<char> { typedef wrap_type_primitive_tag wrap_category; } ;
+
+} // namespace traits
+} // namespace Rcpp
+#endif

Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h	2010-02-01 16:48:42 UTC (rev 545)
+++ pkg/src/RcppCommon.h	2010-02-01 17:23:49 UTC (rev 546)
@@ -24,6 +24,22 @@
 #ifndef RcppCommon_h
 #define RcppCommon_h
 
+/**
+ * \brief Rcpp API
+ */
+namespace Rcpp{
+/**
+ * \brief traits used to dispatch wrap
+ */
+namespace traits{
+} // traits
+/**
+ * \brief internal implementation details
+ */
+namespace internal{	
+} // internal 
+} // Rcpp
+
 #ifdef __GNUC__
 	#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
 	#ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -209,6 +225,8 @@
 } // namespace Rcpp
 
 // DO NOT CHANGE THE ORDER OF THESE INCLUDES
+#include <Rcpp/traits/wrap_type_traits.h>
+
 #include <Rcpp/internal/convertible.h>
 #include <Rcpp/internal/wrap.h>
 #include <Rcpp/RObject.h>



More information about the Rcpp-commits mailing list