-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathis_na.h
More file actions
72 lines (51 loc) · 1.75 KB
/
is_na.h
File metadata and controls
72 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef Rcpp__sugar__is_na_h
#define Rcpp__sugar__is_na_h
namespace Rcpp{
namespace sugar{
template <int RTYPE, bool NA, typename VEC_TYPE>
class IsNa : public ::Rcpp::VectorBase< LGLSXP, false, IsNa<RTYPE,NA,VEC_TYPE> > {
public:
typedef typename traits::storage_type<RTYPE>::type STORAGE ;
typedef Rcpp::VectorBase<RTYPE,NA,VEC_TYPE> BASE ;
IsNa( const BASE& obj_) : obj(obj_){}
inline int operator[]( int i ) const {
return ::Rcpp::traits::is_na<RTYPE>( obj[i] ) ;
}
inline int size() const { return obj.size() ; }
private:
const BASE& obj ;
} ;
// specialization for the case where we already know
// the result (FALSE) because it is embedded in the type
// (the second template parameter of VectorBase)
template <int RTYPE, typename VEC_TYPE>
class IsNa<RTYPE,false,VEC_TYPE> : public ::Rcpp::VectorBase< LGLSXP, false, IsNa<RTYPE,false,VEC_TYPE> > {
public:
typedef typename traits::storage_type<RTYPE>::type STORAGE ;
typedef Rcpp::VectorBase<RTYPE,false,VEC_TYPE> BASE ;
IsNa( const BASE& obj_) : obj(obj_){}
inline int operator[]( int i ) const {
return FALSE ;
}
inline int size() const { return obj.size() ; }
private:
const BASE& obj ;
} ;
template <typename T>
class IsNa_Vector_is_na : public Rcpp::VectorBase<LGLSXP, false, IsNa_Vector_is_na<T> >{
public:
IsNa_Vector_is_na( const T& x) : ref(x){}
inline int operator[]( int i) const {
return ref[i].is_na() ;
}
inline int size() const { return ref.size() ; }
private:
const T& ref ;
} ;
} // sugar
template <int RTYPE, bool NA, typename T>
inline sugar::IsNa<RTYPE,NA,T> is_na( const Rcpp::VectorBase<RTYPE,NA,T>& t){
return sugar::IsNa<RTYPE,NA,T>( t ) ;
}
} // Rcpp
#endif