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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 11 10:24:13 CEST 2010


Author: romain
Date: 2010-06-11 10:24:13 +0200 (Fri, 11 Jun 2010)
New Revision: 1516

Added:
   pkg/Rcpp/inst/include/Rcpp/traits/is_na.h
Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
+ is_na

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-11 06:32:20 UTC (rev 1515)
+++ pkg/Rcpp/inst/ChangeLog	2010-06-11 08:24:13 UTC (rev 1516)
@@ -9,6 +9,8 @@
 	* inst/doc/Rcpp-modules/Rcpp-modules.Rnw: a section to mention fields
 	as a way to expose data members
 
+	* inst/Rcpp/traits/is_na.h : new helper class Rcpp::traits::is_na
+
 2010-06-09  Dirk Eddelbuettel  <edd at debian.org>
 
 	* DESCRIPTION: Release 0.8.2

Added: pkg/Rcpp/inst/include/Rcpp/traits/is_na.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/is_na.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/traits/is_na.h	2010-06-11 08:24:13 UTC (rev 1516)
@@ -0,0 +1,56 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// is_na.h: Rcpp R/C++ interface class library -- vector operators
+//                                                                      
+// 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_is_na_h
+#define Rcpp__traits_is_na_h
+
+namespace Rcpp{
+namespace traits{
+	
+	// no definition on purpose
+	template <int RTYPE> 
+	bool is_na( typename storage_type<RTYPE>::type ) ;
+	
+	template <> 
+	inline bool is_na<INTSXP>( int x ){
+		return x == NA_INTEGER ;
+	}
+	
+	template <> 
+	inline bool is_na<REALSXP>( double x ){
+		return x == NA_REAL ;
+	}
+	
+	template <> 
+	inline bool is_na<CPLXSXP>( Rcomplex x ){
+		return x.r == NA_REAL || x.i == NA_REAL;
+	}
+	
+	template <>
+	inline bool is_na<RAWSXP>( Rbyte x){ return false; }
+	
+	template <>
+	inline bool is_na<STRSXP>( SEXP x ){ return x == NA_STRING ; }
+	
+}
+}
+
+#endif

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2010-06-11 06:32:20 UTC (rev 1515)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2010-06-11 08:24:13 UTC (rev 1516)
@@ -223,6 +223,7 @@
 #include <Rcpp/traits/storage_type.h>
 #include <Rcpp/traits/r_type_traits.h>
 #include <Rcpp/traits/wrap_type_traits.h>
+#include <Rcpp/traits/is_na.h>
 
 #include <Rcpp/traits/is_const.h>
 #include <Rcpp/traits/is_reference.h>



More information about the Rcpp-commits mailing list