-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathReference.h
More file actions
56 lines (45 loc) · 1.52 KB
/
Reference.h
File metadata and controls
56 lines (45 loc) · 1.52 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
#ifndef Rcpp_Reference_h
#define Rcpp_Reference_h
namespace Rcpp{
template <typename Storage>
class Reference_Impl {
RCPP_API_IMPL(Reference_Impl)
inline void set(SEXP x){
if( ! ::Rf_isS4(x) ){
stop("not an S4 object");
}
data = x ;
}
/**
* Creates an reference object of the requested class.
*
* @param klass name of the target reference class
* @throw reference_creation_error if klass does not map to a known S4 class
*/
Reference_Impl( const std::string& klass ) :
data( R_do_new_object(R_do_MAKE_CLASS(klass.c_str())) )
{
check(klass) ;
}
Reference_Impl( const char* klass ) :
data( R_do_new_object(R_do_MAKE_CLASS(klass)) )
{
check(klass) ;
}
bool is( const std::string& clazz) {
return derives_from( Rf_getAttrib(data, R_ClassSymbol), clazz );
}
inline FieldProxy<Reference_Impl> operator[](const std::string& s){
return field(*this,s) ;
}
inline const FieldProxy<Reference_Impl> operator[](const std::string& s) const{
return field(*this,s) ;
}
private:
void check(const char* klass ){
if (!inherits(data, klass))
stop("error creating S4 object") ;
}
} ;
} // namespace Rcpp
#endif