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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 2 09:19:42 CET 2010


Author: romain
Date: 2010-02-02 09:19:42 +0100 (Tue, 02 Feb 2010)
New Revision: 556

Added:
   pkg/src/Rcpp/traits/has_na.h
   pkg/src/Rcpp/traits/integral_constant.h
Modified:
   pkg/src/Rcpp/internal/convertible.h
   pkg/src/Rcpp/internal/wrap.h
   pkg/src/Rcpp/traits/storage_type.h
   pkg/src/RcppCommon.h
Log:
new trait Rcpp::traits::has_na to identify if a SEXP type supports missing values (not used yet)

Modified: pkg/src/Rcpp/internal/convertible.h
===================================================================
--- pkg/src/Rcpp/internal/convertible.h	2010-02-02 07:45:56 UTC (rev 555)
+++ pkg/src/Rcpp/internal/convertible.h	2010-02-02 08:19:42 UTC (rev 556)
@@ -27,25 +27,13 @@
 
 // this is a private header, do not include it directly
 
-namespace Rcpp{
-namespace internal{
-template <class _T, _T _V> struct integral_constant {
-    static  const _T                value = _V;
-    typedef _T                      value_type;
-    typedef integral_constant<_T,_V> type;
- };
- typedef integral_constant<bool, true> true_type;
- typedef integral_constant<bool, false> false_type;
-}
-}
-
 #ifdef HAS_CXX0X
 // use the c++0x implementation
 #include <type_traits>
 namespace Rcpp{
 namespace internal{
 template <typename FROM, typename TO> struct is_convertible : 
-	public integral_constant<bool,std::is_convertible<FROM,TO>::value>{} ;
+	public ::Rcpp::traits::integral_constant<bool,std::is_convertible<FROM,TO>::value>{} ;
 } // internal
 } // Rcpp
 #else
@@ -55,7 +43,7 @@
 namespace Rcpp{
 namespace internal{
 template <typename FROM, typename TO> struct is_convertible : 
-	public integral_constant<bool,std::tr1::is_convertible<FROM,TO>::value>{} ;
+	public ::Rcpp::traits::integral_constant<bool,std::tr1::is_convertible<FROM,TO>::value>{} ;
 } // internal
 } // Rcpp
 #else
@@ -63,7 +51,7 @@
 namespace Rcpp{
 namespace internal{
 template <typename FROM, typename TO> struct is_convertible : 
-	public integral_constant<bool,true>{} ;
+	public ::Rcpp::traits::true_type{} ;
 } // internal
 } // Rcpp
 #endif

Modified: pkg/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/src/Rcpp/internal/wrap.h	2010-02-02 07:45:56 UTC (rev 555)
+++ pkg/src/Rcpp/internal/wrap.h	2010-02-02 08:19:42 UTC (rev 556)
@@ -314,7 +314,7 @@
  * into a SEXP
  */
 template <typename T>
-SEXP wrap_dispatch_unknown( const T& object, true_type ){
+SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::true_type ){
 	// here we know (or assume) that T is convertible to SEXP
 	SEXP x = object ;
 	return x ;
@@ -325,7 +325,7 @@
  * This generates compile time errors
  */
 template <typename T>
-SEXP wrap_dispatch_unknown( const T& object, false_type){
+SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::false_type){
 	// here we know that T is not convertible to SEXP
 #ifdef HAS_CXX0X
 	static_assert( !sizeof(T), "cannot convert type to SEXP" ) ;

Added: pkg/src/Rcpp/traits/has_na.h
===================================================================
--- pkg/src/Rcpp/traits/has_na.h	                        (rev 0)
+++ pkg/src/Rcpp/traits/has_na.h	2010-02-02 08:19:42 UTC (rev 556)
@@ -0,0 +1,65 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// has_na.h: Rcpp R/C++ interface class library -- NA handling
+//
+// 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__has_na__h
+#define Rcpp__traits__has_na__h
+
+namespace Rcpp{
+namespace traits{
+
+/**
+ * Indentifies if a given SEXP type has the concept of missing values
+ * 
+ * This is false by default and specialized for all types that do 
+ * have the concept
+ */
+template<int RTYPE> struct has_na : public false_type{} ;
+
+/**
+ * integer vectors support missing values
+ */
+template<> struct has_na<INTSXP> : public true_type{};
+
+/**
+ * numeric vectors support missing values
+ */
+template<> struct has_na<REALSXP> : public true_type{};
+
+/**
+ * complex vectors support missing values
+ */
+template<> struct has_na<CPLXSXP> : public true_type{};
+
+/**
+ * character vector support missing values
+ */
+template<> struct has_na<STRSXP> : public true_type{};
+
+/**
+ * logical vectors support missing values
+ */
+template<> struct has_na<LGLSXP> : public true_type{};
+
+}
+}
+
+#endif

Added: pkg/src/Rcpp/traits/integral_constant.h
===================================================================
--- pkg/src/Rcpp/traits/integral_constant.h	                        (rev 0)
+++ pkg/src/Rcpp/traits/integral_constant.h	2010-02-02 08:19:42 UTC (rev 556)
@@ -0,0 +1,40 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// has_na.h: Rcpp R/C++ interface class library -- NA handling
+//
+// 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__integral_constant__h
+#define Rcpp__traits__integral_constant__h
+
+namespace Rcpp{
+namespace traits{
+	
+template <class _T, _T _V> struct integral_constant {
+    static  const _T                value = _V;
+    typedef _T                      value_type;
+    typedef integral_constant<_T,_V> type;
+ };
+ typedef integral_constant<bool, true> true_type;
+ typedef integral_constant<bool, false> false_type;
+
+}
+}
+
+#endif

Modified: pkg/src/Rcpp/traits/storage_type.h
===================================================================
--- pkg/src/Rcpp/traits/storage_type.h	2010-02-02 07:45:56 UTC (rev 555)
+++ pkg/src/Rcpp/traits/storage_type.h	2010-02-02 08:19:42 UTC (rev 556)
@@ -36,7 +36,6 @@
 	typedef SEXP type ;
 } ;
 
-
 /**
  * Total specialization for integer vector (INTSXP)
  * typedef to int

Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h	2010-02-02 07:45:56 UTC (rev 555)
+++ pkg/src/RcppCommon.h	2010-02-02 08:19:42 UTC (rev 556)
@@ -225,6 +225,9 @@
 } // namespace Rcpp
 
 // DO NOT CHANGE THE ORDER OF THESE INCLUDES
+#include <Rcpp/traits/integral_constant.h>
+#include <Rcpp/traits/has_na.h>
+#include <Rcpp/traits/storage_type.h>
 #include <Rcpp/traits/r_sexptype_traits.h>
 #include <Rcpp/traits/storage_type.h>
 #include <Rcpp/traits/r_type_traits.h>



More information about the Rcpp-commits mailing list