Rcpp Version 1.0.9
S4.h
Go to the documentation of this file.
1 // Copyright (C) 2013 Romain Francois
2 //
3 // This file is part of Rcpp.
4 //
5 // Rcpp is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // Rcpp is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef Rcpp_api_meat_S4_h
19 #define Rcpp_api_meat_S4_h
20 
21 namespace Rcpp{
22 
23  template <template <class> class StoragePolicy>
24  bool S4_Impl<StoragePolicy>::is( const std::string& clazz) const {
26 
27  // simple test for exact match
28  if( ! clazz.compare( cl[0] ) ) return true ;
29 
30  try{
31  SEXP containsSym = Rf_install("contains");
32  Shield<SEXP> classDef( R_getClassDef(CHAR(Rf_asChar(cl))) ) ;
33  CharacterVector res( Rf_getAttrib( R_do_slot( classDef, containsSym), R_NamesSymbol));
34 
35  return any( res.begin(), res.end(), clazz.c_str() ) ;
36  } catch( ... ){
37  // we catch eval_error and also not_compatible when
38  // contains is NULL
39  }
40  return false ;
41  }
42 
43 
44 }
45 
46 #endif
AttributeProxy attr(const std::string &name)
Rcpp API.
Definition: algo.h:28
Vector< STRSXP > CharacterVector
Definition: instantiation.h:34
bool any(InputIterator first, InputIterator last, const T &value)
Definition: algo.h:89
bool is(SEXP x)
Definition: is.h:53