Rcpp Version 1.0.14
Loading...
Searching...
No Matches
is.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2//
3// is.h: Rcpp R/C++ interface class library -- is implementations
4//
5// Copyright (C) 2013 - 2015 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_api_meat_is_h
23#define Rcpp_api_meat_is_h
24
25namespace Rcpp {
26 namespace internal {
27
28 inline bool is_atomic(SEXP x) { return Rf_length(x) == 1; }
29 inline bool is_matrix(SEXP x) {
31 return dim != R_NilValue && Rf_length(dim) == 2;
32 }
33 template <> inline bool is__simple<int>(SEXP x) {
34 return is_atomic(x) && TYPEOF(x) == INTSXP;
35 }
36 template <> inline bool is__simple<double>(SEXP x) {
37 return is_atomic(x) && TYPEOF(x) == REALSXP;
38 }
39 template <> inline bool is__simple<bool>(SEXP x) {
40 return is_atomic(x) && TYPEOF(x) == LGLSXP;
41 }
42 template <> inline bool is__simple<std::string>(SEXP x) {
43 return is_atomic(x) && TYPEOF(x) == STRSXP;
44 }
45 template <> inline bool is__simple<String>(SEXP x) {
46 return is_atomic(x) && TYPEOF(x) == STRSXP;
47 }
48 template <> inline bool is__simple<Rcomplex>(SEXP x) {
49 return is_atomic(x) && TYPEOF(x) == CPLXSXP;
50 }
51 template <> inline bool is__simple<CharacterVector>(SEXP x) {
52 return TYPEOF(x) == STRSXP;
53 }
54 template <> inline bool is__simple<CharacterMatrix>(SEXP x) {
55 return TYPEOF(x) == STRSXP && is_matrix(x);
56 }
57 template <> inline bool is__simple<RObject>(SEXP) {
58 return true;
59 }
60 template <> inline bool is__simple<IntegerVector>(SEXP x) {
61 return TYPEOF(x) == INTSXP;
62 }
63 template <> inline bool is__simple<ComplexVector>(SEXP x) {
64 return TYPEOF(x) == CPLXSXP;
65 }
66 template <> inline bool is__simple<RawVector>(SEXP x) {
67 return TYPEOF(x) == RAWSXP;
68 }
69 template <> inline bool is__simple<NumericVector>(SEXP x) {
70 return TYPEOF(x) == REALSXP;
71 }
72 template <> inline bool is__simple<LogicalVector>(SEXP x) {
73 return TYPEOF(x) == LGLSXP;
74 }
75 template <> inline bool is__simple<Language>(SEXP x) {
76 return TYPEOF(x) == LANGSXP;
77 }
78 template <> inline bool is__simple<DottedPair>(SEXP x) {
79 return (TYPEOF(x) == LANGSXP) || (TYPEOF(x) == LISTSXP);
80 }
81 template <> inline bool is__simple<List>(SEXP x) {
82 return TYPEOF(x) == VECSXP;
83 }
84 template <> inline bool is__simple<IntegerMatrix>(SEXP x) {
85 return TYPEOF(x) == INTSXP && is_matrix(x);
86 }
87 template <> inline bool is__simple<ComplexMatrix>(SEXP x) {
88 return TYPEOF(x) == CPLXSXP && is_matrix(x);
89 }
90 template <> inline bool is__simple<RawMatrix>(SEXP x) {
91 return TYPEOF(x) == RAWSXP && is_matrix(x);
92 }
93 template <> inline bool is__simple<NumericMatrix>(SEXP x) {
94 return TYPEOF(x) == REALSXP && is_matrix(x);
95 }
96 template <> inline bool is__simple<LogicalMatrix>(SEXP x) {
97 return TYPEOF(x) == LGLSXP && is_matrix(x);
98 }
99 template <> inline bool is__simple<GenericMatrix>(SEXP x) {
100 return TYPEOF(x) == VECSXP && is_matrix(x);
101 }
102
103
104 template <> inline bool is__simple<DataFrame>(SEXP x) {
105 if( TYPEOF(x) != VECSXP ) return false;
106 return Rf_inherits( x, "data.frame" );
107 }
108 template <> inline bool is__simple<WeakReference>(SEXP x) {
109 return TYPEOF(x) == WEAKREFSXP;
110 }
111 template <> inline bool is__simple<Symbol>(SEXP x) {
112 return TYPEOF(x) == SYMSXP;
113 }
114 template <> inline bool is__simple<S4>(SEXP x) {
115 return ::Rf_isS4(x);
116 }
117 template <> inline bool is__simple<Reference>(SEXP x) {
118 if( ! ::Rf_isS4(x) ) return false;
119 return ::Rf_inherits(x, "envRefClass" );
120 }
121 template <> inline bool is__simple<Promise>(SEXP x) {
122 return TYPEOF(x) == PROMSXP;
123 }
124 template <> inline bool is__simple<Pairlist>(SEXP x) {
125 return TYPEOF(x) == LISTSXP;
126 }
127 template <> inline bool is__simple<Function>(SEXP x) {
128 return TYPEOF(x) == CLOSXP || TYPEOF(x) == SPECIALSXP || TYPEOF(x) == BUILTINSXP;
129 }
130 template <> inline bool is__simple<Environment>(SEXP x) {
131 return TYPEOF(x) == ENVSXP;
132 }
133 template <> inline bool is__simple<Formula>(SEXP x) {
134 if( TYPEOF(x) != LANGSXP ) return false;
135 return Rf_inherits(x, "formula");
136 }
137
138 template <> inline bool is__simple<Date>(SEXP x) {
139 return is_atomic(x) && TYPEOF(x) == REALSXP && Rf_inherits(x, "Date");
140 }
141 template <> inline bool is__simple<Datetime>(SEXP x) {
142 return is_atomic(x) && TYPEOF(x) == REALSXP && Rf_inherits(x, "POSIXt");
143 }
144 template <> inline bool is__simple<DateVector>(SEXP x) {
145 return TYPEOF(x) == REALSXP && Rf_inherits(x, "Date");
146 }
147 template <> inline bool is__simple<DatetimeVector>(SEXP x) {
148 return TYPEOF(x) == REALSXP && Rf_inherits(x, "POSIXt");
149 }
150
151#ifndef RCPP_NO_MODULES
152
153 inline bool is_module_object_internal(SEXP obj, const char* clazz){
154 Environment env(obj);
155 SEXP sexp = env.get(".cppclass");
156 if (TYPEOF(sexp) != EXTPTRSXP) return false;
158 return xp->has_typeinfo_name(clazz);
159 }
160 template <typename T> bool is__module__object(SEXP x) {
161 if (!is__simple<S4>(x)) return false;
163 return is_module_object_internal(x, typeid(CLASS).name());
164 }
165
166#endif
167
168
169 } // namespace internal
170} // namespace Rcpp
171
172#endif
bool is__simple< LogicalVector >(SEXP x)
Definition is.h:72
bool is__simple< Symbol >(SEXP x)
Definition is.h:111
bool is__simple< int >(SEXP x)
Definition is.h:33
bool is__simple< CharacterVector >(SEXP x)
Definition is.h:51
bool is__simple< String >(SEXP x)
Definition is.h:45
bool is__simple< Reference >(SEXP x)
Definition is.h:117
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
Definition as.h:43
bool is__simple< ComplexMatrix >(SEXP x)
Definition is.h:87
bool is__simple< Datetime >(SEXP x)
Definition is.h:141
bool is__simple< CharacterMatrix >(SEXP x)
Definition is.h:54
bool is__simple< List >(SEXP x)
Definition is.h:81
bool is__simple< Environment >(SEXP x)
Definition is.h:130
bool is__simple< RObject >(SEXP)
Definition is.h:57
bool is__simple< DataFrame >(SEXP x)
Definition is.h:104
bool is__simple< Formula >(SEXP x)
Definition is.h:133
bool is__simple< DateVector >(SEXP x)
Definition is.h:144
bool is_matrix(SEXP x)
Definition is.h:29
bool is__simple< Pairlist >(SEXP x)
Definition is.h:124
bool is__simple< WeakReference >(SEXP x)
Definition is.h:108
bool is__simple< double >(SEXP x)
Definition is.h:36
bool is__simple< bool >(SEXP x)
Definition is.h:39
bool is__simple< std::string >(SEXP x)
Definition is.h:42
bool is__simple< IntegerMatrix >(SEXP x)
Definition is.h:84
bool is_atomic(SEXP x)
Definition is.h:28
bool is__simple< Function >(SEXP x)
Definition is.h:127
bool is__simple< DatetimeVector >(SEXP x)
Definition is.h:147
bool is__simple< NumericVector >(SEXP x)
Definition is.h:69
bool is__simple< IntegerVector >(SEXP x)
Definition is.h:60
bool is__simple< LogicalMatrix >(SEXP x)
Definition is.h:96
bool is__simple< RawVector >(SEXP x)
Definition is.h:66
bool is__simple< DottedPair >(SEXP x)
Definition is.h:78
bool is__simple< Language >(SEXP x)
Definition is.h:75
bool is__simple< Rcomplex >(SEXP x)
Definition is.h:48
bool is__simple< ComplexVector >(SEXP x)
Definition is.h:63
bool is__simple< Date >(SEXP x)
Definition is.h:138
bool is__simple< S4 >(SEXP x)
Definition is.h:114
bool is__simple< RawMatrix >(SEXP x)
Definition is.h:90
bool is_module_object_internal(SEXP obj, const char *clazz)
Definition is.h:153
bool is__simple< NumericMatrix >(SEXP x)
Definition is.h:93
bool is__simple< Promise >(SEXP x)
Definition is.h:121
bool is__simple< GenericMatrix >(SEXP x)
Definition is.h:99
bool is__module__object(SEXP x)
Definition is.h:160
Rcpp API.
Definition algo.h:28
Environment_Impl< PreserveStorage > Environment