Rcpp Version 1.0.14
Loading...
Searching...
No Matches
is_na.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// is_na.h: Rcpp R/C++ interface class library -- is_na
4//
5// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp__sugar__is_na_h
23#define Rcpp__sugar__is_na_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <int RTYPE, bool NA, typename VEC_TYPE>
29class IsNa : public ::Rcpp::VectorBase< LGLSXP, false, IsNa<RTYPE,NA,VEC_TYPE> > {
30public:
33
34 IsNa( const BASE& obj_) : obj(obj_){}
35
36 inline int operator[]( R_xlen_t i ) const {
37 return ::Rcpp::traits::is_na<RTYPE>( obj[i] ) ;
38 }
39
40 inline R_xlen_t size() const { return obj.size() ; }
41
42private:
43 const BASE& obj ;
44
45} ;
46
47// specialization for the case where we already know
48// the result (FALSE) because it is embedded in the type
49// (the second template parameter of VectorBase)
50template <int RTYPE, typename VEC_TYPE>
51class IsNa<RTYPE,false,VEC_TYPE> : public ::Rcpp::VectorBase< LGLSXP, false, IsNa<RTYPE,false,VEC_TYPE> > {
52public:
55
56 IsNa( const BASE& obj_) : obj(obj_){}
57
58 inline int operator[]( R_xlen_t i ) const {
59 return FALSE ;
60 }
61
62 inline R_xlen_t size() const { return obj.size() ; }
63
64private:
65 const BASE& obj ;
66
67} ;
68
69template <typename T>
70class IsNa_Vector_is_na : public Rcpp::VectorBase<LGLSXP, false, IsNa_Vector_is_na<T> >{
71 public:
72 IsNa_Vector_is_na( const T& x) : ref(x){}
73
74 inline int operator[]( R_xlen_t i) const {
75 #if defined(RCPP_NEW_DATE_DATETIME_VECTORS)
76 return ::Rcpp::traits::is_na<T>(ref[i]);
77 #else
78 return ref[i].is_na() ;
79 #endif
80 }
81
82 inline R_xlen_t size() const { return ref.size() ; }
83
84 private:
85 const T& ref ;
86} ;
87
88} // sugar
89
90template <int RTYPE, bool NA, typename T>
94
98
102
109
110
111} // Rcpp
112#endif
113
R_xlen_t size() const
Definition VectorBase.h:49
Rcpp::VectorBase< RTYPE, false, VEC_TYPE > BASE
Definition is_na.h:54
traits::storage_type< RTYPE >::type STORAGE
Definition is_na.h:53
int operator[](R_xlen_t i) const
Definition is_na.h:74
IsNa_Vector_is_na(const T &x)
Definition is_na.h:72
R_xlen_t size() const
Definition is_na.h:82
IsNa(const BASE &obj_)
Definition is_na.h:34
traits::storage_type< RTYPE >::type STORAGE
Definition is_na.h:31
R_xlen_t size() const
Definition is_na.h:40
int operator[](R_xlen_t i) const
Definition is_na.h:36
const BASE & obj
Definition is_na.h:43
Rcpp::VectorBase< RTYPE, NA, VEC_TYPE > BASE
Definition is_na.h:32
Rcpp API.
Definition algo.h:28
sugar::IsNa< RTYPE, NA, T > is_na(const Rcpp::VectorBase< RTYPE, NA, T > &t)
Definition is_na.h:91
T as(SEXP x)
Definition as.h:151