-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathReference.h
More file actions
52 lines (41 loc) · 1.6 KB
/
Reference.h
File metadata and controls
52 lines (41 loc) · 1.6 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
#ifndef Rcpp_Reference_h
#define Rcpp_Reference_h
#include <Rcpp/S4.h>
#include <Rcpp/exceptions.h>
namespace Rcpp{
template < template <class> class StoragePolicy >
class Reference_Impl :
public S4_Impl<StoragePolicy>,
public FieldProxyPolicy<Reference_Impl<StoragePolicy>>
{
public:
using Base = S4_Impl<StoragePolicy> ;
using Storage = typename Base::Storage ;
/**
* checks that x is an S4 object of a reference class and wrap it.
*
* @param x must be an S4 object of some reference class
*/
Reference_Impl(SEXP x) : Base(x){}
template <typename T>
Reference_Impl(const T& object ) : Reference(wrap(object)){}
Reference_Impl& operator=( SEXP other ) {
Storage::set__( other ) ;
return *this ;
}
/**
* 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 ){
// using callback to R as apparently R_do_new_object always makes the same environment
SEXP newSym = Rf_install("new");
Shield<SEXP> call = Rf_lang2( newSym, Rf_mkString( klass.c_str() ) ) ;
Storage::set__( Rcpp_eval( call ) ) ;
}
Reference_Impl( const char* klass ) : Reference(std::string(klass)){}
} ;
} // namespace Rcpp
#endif