Rcpp Version 0.12.12
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 
25 namespace Rcpp{
26 namespace sugar{
27 
28 template <int RTYPE, bool NA, typename VEC_TYPE>
29 class IsNa : public ::Rcpp::VectorBase< LGLSXP, false, IsNa<RTYPE,NA,VEC_TYPE> > {
30 public:
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 
42 private:
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)
50 template <int RTYPE, typename VEC_TYPE>
51 class IsNa<RTYPE,false,VEC_TYPE> : public ::Rcpp::VectorBase< LGLSXP, false, IsNa<RTYPE,false,VEC_TYPE> > {
52 public:
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 
64 private:
65  const BASE& obj ;
66 
67 } ;
68 
69 template <typename T>
70 class 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  return ref[i].is_na() ;
76  }
77 
78  inline R_xlen_t size() const { return ref.size() ; }
79 
80  private:
81  const T& ref ;
82 } ;
83 
84 } // sugar
85 
86 template <int RTYPE, bool NA, typename T>
88  return sugar::IsNa<RTYPE,NA,T>( t ) ;
89 }
90 
93 }
96 }
97 
98 } // Rcpp
99 #endif
100 
IsNa_Vector_is_na(const T &x)
Definition: is_na.h:72
traits::storage_type< RTYPE >::type STORAGE
Definition: is_na.h:53
R_xlen_t size() const
Definition: VectorBase.h:49
int operator[](R_xlen_t i) const
Definition: is_na.h:74
R_xlen_t size() const
Definition: is_na.h:78
int operator[](R_xlen_t i) const
Definition: is_na.h:58
const BASE & obj
Definition: is_na.h:43
R_xlen_t size() const
Definition: is_na.h:40
int operator[](R_xlen_t i) const
Definition: is_na.h:36
Rcpp::VectorBase< RTYPE, NA, VEC_TYPE > BASE
Definition: is_na.h:32
sugar::IsNa< RTYPE, NA, T > is_na(const Rcpp::VectorBase< RTYPE, NA, T > &t)
Definition: is_na.h:87
Rcpp API.
Definition: algo.h:28
IsNa(const BASE &obj_)
Definition: is_na.h:34
Rcpp::VectorBase< RTYPE, false, VEC_TYPE > BASE
Definition: is_na.h:54
traits::storage_type< RTYPE >::type STORAGE
Definition: is_na.h:31