MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / simple_name_proxy

Class simple_name_proxy

inst/include/Rcpp/vector/proxy.h:28–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27 template <int RTYPE, template <class> class StoragePolicy>
28 class simple_name_proxy {
29 public:
30 typedef ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
31 typedef typename ::Rcpp::traits::storage_type<RTYPE>::type CTYPE ;
32
33 simple_name_proxy( VECTOR& v, const std::string& name_) :
34 parent(v), name(name_){} ;
35 simple_name_proxy( const simple_name_proxy& other ) :
36 parent(other.parent), name(other.name){} ;
37 ~simple_name_proxy() {} ;
38
39 simple_name_proxy& operator=( CTYPE rhs ){
40 set( rhs ) ;
41 return *this ;
42 }
43 simple_name_proxy& operator=( const simple_name_proxy& other){
44 set( other.get() ) ;
45 return *this ;
46 }
47
48 template <typename T>
49 simple_name_proxy& operator=( const T& rhs ){
50 set( caster<T,CTYPE>(rhs) ) ;
51 return *this ;
52 }
53
54 // TODO: other operators +=, -=, ...
55
56 operator CTYPE() const {
57 return get() ;
58 }
59
60 // this helps wrap, for example : wrap( x["foo"] )
61 operator SEXP() const {
62 return ::Rcpp::wrap(get()) ;
63 }
64
65 private:
66 VECTOR& parent ;
67 std::string name;
68 void set( CTYPE rhs ){
69 R_xlen_t index = 0 ;
70 try{
71 index = parent.offset(name) ;
72 parent[ index ] = rhs ;
73 } catch( const index_out_of_bounds& ex ){
74 parent.push_back( rhs, name );
75 }
76 }
77 CTYPE get() const {
78 return parent[ parent.offset(name) ];
79 }
80 } ;
81
82 template <int RTYPE, template <class> class StoragePolicy>
83 class string_name_proxy{

Callers

nothing calls this directly

Calls 3

getFunction · 0.85
wrapFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected