22//
33// is.h: Rcpp R/C++ interface class library -- is implementations
44//
5- // Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
5+ // Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
66//
77// This file is part of Rcpp.
88//
2222#ifndef Rcpp_api_meat_is_h
2323#define Rcpp_api_meat_is_h
2424
25- namespace Rcpp {
26- namespace internal {
25+ namespace Rcpp {
26+ namespace internal {
2727
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 ;
3232 }
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;
3535 }
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;
3838 }
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;
4141 }
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;
4444 }
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;
4747 }
4848 template <> inline bool is__simple<CharacterVector>(SEXP x) {
4949 return TYPEOF (x) == STRSXP;
@@ -52,111 +52,111 @@ namespace internal{
5252 return TYPEOF (x) == STRSXP && is_matrix (x);
5353 }
5454 template <> inline bool is__simple<RObject>(SEXP) {
55- return true ;
55+ return true ;
5656 }
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;
5959 }
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;
6262 }
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;
6565 }
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;
6868 }
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;
7171 }
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;
7474 }
75- template <> inline bool is__simple<DottedPair>( SEXP x ) {
75+ template <> inline bool is__simple<DottedPair>(SEXP x) {
7676 return (TYPEOF (x) == LANGSXP) || (TYPEOF (x) == LISTSXP);
7777 }
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;
8080 }
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);
8383 }
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);
8686 }
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);
8989 }
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);
9292 }
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);
9595 }
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);
9898 }
9999
100100
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" );
104104 }
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;
107107 }
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;
110110 }
111- template <> inline bool is__simple<S4>( SEXP x ) {
111+ template <> inline bool is__simple<S4>(SEXP x) {
112112 return ::Rf_isS4 (x);
113113 }
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" );
117117 }
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;
120120 }
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;
123123 }
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;
126126 }
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;
129129 }
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" ) ;
133133 }
134134
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" ) ;
137137 }
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" ) ;
140140 }
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" ) ;
143143 }
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" ) ;
146146 }
147147
148148 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 ()) ;
156156 }
157157
158158
159- } // namespace internal
159+ } // namespace internal
160160} // namespace Rcpp
161161
162162#endif
0 commit comments