2
2
//
3
3
// is.h: Rcpp R/C++ interface class library -- is implementations
4
4
//
5
- // Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
5
+ // Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
6
6
//
7
7
// This file is part of Rcpp.
8
8
//
22
22
#ifndef Rcpp_api_meat_is_h
23
23
#define Rcpp_api_meat_is_h
24
24
25
- namespace Rcpp {
26
- namespace internal {
25
+ namespace Rcpp {
26
+ namespace internal {
27
27
28
- inline bool is_atomic ( SEXP x){ return Rf_length (x) == 1 ; }
29
- inline bool is_matrix (SEXP x){
30
- SEXP dim = Rf_getAttrib ( x, R_DimSymbol) ;
31
- return dim != R_NilValue && Rf_length (dim) == 2 ;
28
+ inline bool is_atomic (SEXP x) { return Rf_length (x) == 1 ; }
29
+ inline bool is_matrix (SEXP x) {
30
+ SEXP dim = Rf_getAttrib ( x, R_DimSymbol);
31
+ return dim != R_NilValue && Rf_length (dim) == 2 ;
32
32
}
33
- template <> inline bool is__simple<int >( SEXP x ) {
34
- return is_atomic (x) && TYPEOF (x) == INTSXP ;
33
+ template <> inline bool is__simple<int >(SEXP x) {
34
+ return is_atomic (x) && TYPEOF (x) == INTSXP;
35
35
}
36
- template <> inline bool is__simple<double >( SEXP x ) {
37
- return is_atomic (x) && TYPEOF (x) == REALSXP ;
36
+ template <> inline bool is__simple<double >(SEXP x) {
37
+ return is_atomic (x) && TYPEOF (x) == REALSXP;
38
38
}
39
- template <> inline bool is__simple<bool >( SEXP x ) {
40
- return is_atomic (x) && TYPEOF (x) == LGLSXP ;
39
+ template <> inline bool is__simple<bool >(SEXP x) {
40
+ return is_atomic (x) && TYPEOF (x) == LGLSXP;
41
41
}
42
- template <> inline bool is__simple<std::string>( SEXP x ) {
43
- return is_atomic (x) && TYPEOF (x) == STRSXP ;
42
+ template <> inline bool is__simple<std::string>(SEXP x) {
43
+ return is_atomic (x) && TYPEOF (x) == STRSXP;
44
44
}
45
- template <> inline bool is__simple<String>( SEXP x ) {
46
- return is_atomic (x) && TYPEOF (x) == STRSXP ;
45
+ template <> inline bool is__simple<String>(SEXP x) {
46
+ return is_atomic (x) && TYPEOF (x) == STRSXP;
47
47
}
48
48
template <> inline bool is__simple<CharacterVector>(SEXP x) {
49
49
return TYPEOF (x) == STRSXP;
@@ -52,111 +52,111 @@ namespace internal{
52
52
return TYPEOF (x) == STRSXP && is_matrix (x);
53
53
}
54
54
template <> inline bool is__simple<RObject>(SEXP) {
55
- return true ;
55
+ return true ;
56
56
}
57
- template <> inline bool is__simple<IntegerVector>( SEXP x ) {
58
- return TYPEOF (x) == INTSXP ;
57
+ template <> inline bool is__simple<IntegerVector>(SEXP x) {
58
+ return TYPEOF (x) == INTSXP;
59
59
}
60
- template <> inline bool is__simple<ComplexVector>( SEXP x ) {
61
- return TYPEOF (x) == CPLXSXP ;
60
+ template <> inline bool is__simple<ComplexVector>(SEXP x) {
61
+ return TYPEOF (x) == CPLXSXP;
62
62
}
63
- template <> inline bool is__simple<RawVector>( SEXP x ) {
64
- return TYPEOF (x) == RAWSXP ;
63
+ template <> inline bool is__simple<RawVector>(SEXP x) {
64
+ return TYPEOF (x) == RAWSXP;
65
65
}
66
- template <> inline bool is__simple<NumericVector>( SEXP x ) {
67
- return TYPEOF (x) == REALSXP ;
66
+ template <> inline bool is__simple<NumericVector>(SEXP x) {
67
+ return TYPEOF (x) == REALSXP;
68
68
}
69
- template <> inline bool is__simple<LogicalVector>( SEXP x ) {
70
- return TYPEOF (x) == LGLSXP ;
69
+ template <> inline bool is__simple<LogicalVector>(SEXP x) {
70
+ return TYPEOF (x) == LGLSXP;
71
71
}
72
- template <> inline bool is__simple<Language>( SEXP x ) {
73
- return TYPEOF (x) == LANGSXP ;
72
+ template <> inline bool is__simple<Language>(SEXP x) {
73
+ return TYPEOF (x) == LANGSXP;
74
74
}
75
- template <> inline bool is__simple<DottedPair>( SEXP x ) {
75
+ template <> inline bool is__simple<DottedPair>(SEXP x) {
76
76
return (TYPEOF (x) == LANGSXP) || (TYPEOF (x) == LISTSXP);
77
77
}
78
- template <> inline bool is__simple<List>( SEXP x ) {
79
- return TYPEOF (x) == VECSXP ;
78
+ template <> inline bool is__simple<List>(SEXP x) {
79
+ return TYPEOF (x) == VECSXP;
80
80
}
81
- template <> inline bool is__simple<IntegerMatrix>( SEXP x ) {
82
- return TYPEOF (x) == INTSXP && is_matrix (x) ;
81
+ template <> inline bool is__simple<IntegerMatrix>(SEXP x) {
82
+ return TYPEOF (x) == INTSXP && is_matrix (x);
83
83
}
84
- template <> inline bool is__simple<ComplexMatrix>( SEXP x ) {
85
- return TYPEOF (x) == CPLXSXP && is_matrix (x) ;
84
+ template <> inline bool is__simple<ComplexMatrix>(SEXP x) {
85
+ return TYPEOF (x) == CPLXSXP && is_matrix (x);
86
86
}
87
- template <> inline bool is__simple<RawMatrix>( SEXP x ) {
88
- return TYPEOF (x) == RAWSXP && is_matrix (x) ;
87
+ template <> inline bool is__simple<RawMatrix>(SEXP x) {
88
+ return TYPEOF (x) == RAWSXP && is_matrix (x);
89
89
}
90
- template <> inline bool is__simple<NumericMatrix>( SEXP x ) {
91
- return TYPEOF (x) == REALSXP && is_matrix (x) ;
90
+ template <> inline bool is__simple<NumericMatrix>(SEXP x) {
91
+ return TYPEOF (x) == REALSXP && is_matrix (x);
92
92
}
93
- template <> inline bool is__simple<LogicalMatrix>( SEXP x ) {
94
- return TYPEOF (x) == LGLSXP && is_matrix (x) ;
93
+ template <> inline bool is__simple<LogicalMatrix>(SEXP x) {
94
+ return TYPEOF (x) == LGLSXP && is_matrix (x);
95
95
}
96
- template <> inline bool is__simple<GenericMatrix>( SEXP x ) {
97
- return TYPEOF (x) == VECSXP && is_matrix (x) ;
96
+ template <> inline bool is__simple<GenericMatrix>(SEXP x) {
97
+ return TYPEOF (x) == VECSXP && is_matrix (x);
98
98
}
99
99
100
100
101
- template <> inline bool is__simple<DataFrame>( SEXP x ) {
102
- if ( TYPEOF (x) != VECSXP ) return false ;
103
- return Rf_inherits ( x, " data.frame" ) ;
101
+ template <> inline bool is__simple<DataFrame>(SEXP x) {
102
+ if ( TYPEOF (x) != VECSXP ) return false ;
103
+ return Rf_inherits ( x, " data.frame" );
104
104
}
105
- template <> inline bool is__simple<WeakReference>( SEXP x ) {
106
- return TYPEOF (x) == WEAKREFSXP ;
105
+ template <> inline bool is__simple<WeakReference>(SEXP x) {
106
+ return TYPEOF (x) == WEAKREFSXP;
107
107
}
108
- template <> inline bool is__simple<Symbol>( SEXP x ) {
109
- return TYPEOF (x) == SYMSXP ;
108
+ template <> inline bool is__simple<Symbol>(SEXP x) {
109
+ return TYPEOF (x) == SYMSXP;
110
110
}
111
- template <> inline bool is__simple<S4>( SEXP x ) {
111
+ template <> inline bool is__simple<S4>(SEXP x) {
112
112
return ::Rf_isS4 (x);
113
113
}
114
- template <> inline bool is__simple<Reference>( SEXP x ) {
115
- if ( ! ::Rf_isS4 (x) ) return false ;
116
- return ::Rf_inherits (x, " envRefClass" ) ;
114
+ template <> inline bool is__simple<Reference>(SEXP x) {
115
+ if ( ! ::Rf_isS4 (x) ) return false ;
116
+ return ::Rf_inherits (x, " envRefClass" );
117
117
}
118
- template <> inline bool is__simple<Promise>( SEXP x ) {
119
- return TYPEOF (x) == PROMSXP ;
118
+ template <> inline bool is__simple<Promise>(SEXP x) {
119
+ return TYPEOF (x) == PROMSXP;
120
120
}
121
- template <> inline bool is__simple<Pairlist>( SEXP x ) {
122
- return TYPEOF (x) == LISTSXP ;
121
+ template <> inline bool is__simple<Pairlist>(SEXP x) {
122
+ return TYPEOF (x) == LISTSXP;
123
123
}
124
- template <> inline bool is__simple<Function>( SEXP x ) {
125
- return TYPEOF (x) == CLOSXP || TYPEOF (x) == SPECIALSXP || TYPEOF (x) == BUILTINSXP ;
124
+ template <> inline bool is__simple<Function>(SEXP x) {
125
+ return TYPEOF (x) == CLOSXP || TYPEOF (x) == SPECIALSXP || TYPEOF (x) == BUILTINSXP;
126
126
}
127
- template <> inline bool is__simple<Environment>( SEXP x ) {
128
- return TYPEOF (x) == ENVSXP ;
127
+ template <> inline bool is__simple<Environment>(SEXP x) {
128
+ return TYPEOF (x) == ENVSXP;
129
129
}
130
- template <> inline bool is__simple<Formula>( SEXP x ) {
131
- if ( TYPEOF (x) != LANGSXP ) return false ;
132
- return Rf_inherits ( x, " formula" ) ;
130
+ template <> inline bool is__simple<Formula>(SEXP x) {
131
+ if ( TYPEOF (x) != LANGSXP ) return false ;
132
+ return Rf_inherits (x, " formula" ) ;
133
133
}
134
134
135
- template <> inline bool is__simple<Date>( SEXP x ) {
136
- return is_atomic (x) && TYPEOF (x) == REALSXP && Rf_inherits ( x, " Date" ) ;
135
+ template <> inline bool is__simple<Date>(SEXP x) {
136
+ return is_atomic (x) && TYPEOF (x) == REALSXP && Rf_inherits (x, " Date" ) ;
137
137
}
138
- template <> inline bool is__simple<Datetime>( SEXP x ) {
139
- return is_atomic (x) && TYPEOF (x) == REALSXP && Rf_inherits ( x, " POSIXt" ) ;
138
+ template <> inline bool is__simple<Datetime>(SEXP x) {
139
+ return is_atomic (x) && TYPEOF (x) == REALSXP && Rf_inherits (x, " POSIXt" ) ;
140
140
}
141
- template <> inline bool is__simple<DateVector>( SEXP x ) {
142
- return TYPEOF (x) == REALSXP && Rf_inherits ( x, " Date" ) ;
141
+ template <> inline bool is__simple<DateVector>(SEXP x) {
142
+ return TYPEOF (x) == REALSXP && Rf_inherits (x, " Date" ) ;
143
143
}
144
- template <> inline bool is__simple<DatetimeVector>( SEXP x ) {
145
- return TYPEOF (x) == REALSXP && Rf_inherits ( x, " POSIXt" ) ;
144
+ template <> inline bool is__simple<DatetimeVector>(SEXP x) {
145
+ return TYPEOF (x) == REALSXP && Rf_inherits (x, " POSIXt" ) ;
146
146
}
147
147
148
148
inline bool is_module_object_internal (SEXP obj, const char * clazz){
149
- Environment env (obj) ;
150
- XPtr<class_Base> xp ( env.get (" .cppclass" ) );
151
- return xp->has_typeinfo_name ( clazz ) ;
152
- }
153
- template <typename T> bool is__module__object ( SEXP x){
154
- typedef typename Rcpp::traits::un_pointer<T>::type CLASS ;
155
- return is_module_object_internal (x, typeid (CLASS).name () ) ;
149
+ Environment env (obj);
150
+ XPtr<class_Base> xp ( env.get (" .cppclass" ));
151
+ return xp->has_typeinfo_name (clazz) ;
152
+ }
153
+ template <typename T> bool is__module__object (SEXP x) {
154
+ typedef typename Rcpp::traits::un_pointer<T>::type CLASS;
155
+ return is_module_object_internal (x, typeid (CLASS).name ()) ;
156
156
}
157
157
158
158
159
- } // namespace internal
159
+ } // namespace internal
160
160
} // namespace Rcpp
161
161
162
162
#endif
0 commit comments