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

Class generic_name_proxy

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

Source from the content-addressed store, hash-verified

134
135 template <int RTYPE, template <class> class StoragePolicy>
136 class generic_name_proxy {
137 public:
138 typedef ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
139 generic_name_proxy( VECTOR& v, const std::string& name_) :
140 parent(v), name(name_){}
141 generic_name_proxy( const generic_name_proxy& other ) :
142 parent(other.parent), name(other.name){}
143 ~generic_name_proxy(){} ;
144
145 generic_name_proxy& operator=( SEXP rhs ){
146 set( rhs ) ;
147 return *this ;
148 }
149 generic_name_proxy& operator=( const generic_name_proxy& other){
150 set( other.get() ) ;
151 return *this ;
152 }
153
154 template <typename T>
155 generic_name_proxy& operator=( const T& rhs ){
156 set(Shield<SEXP>(wrap(rhs)));
157 return *this ;
158 }
159
160 // TODO: other operators +=, -=, ...
161
162 operator SEXP() const {
163 return get() ;
164 }
165
166 template <typename T>
167 operator T() const {
168 #if RCPP_DEBUG_LEVEL > 0
169 SEXP res = get() ;
170 RCPP_DEBUG_1( "generic_name_proxy::get() = <%p> ", res ) ;
171 return ::Rcpp::as<T>( res ) ;
172 #else
173 return ::Rcpp::as<T>( get() ) ;
174 #endif
175 }
176
177 private:
178 VECTOR& parent ;
179 std::string name;
180 void set( SEXP rhs ){
181 R_xlen_t index = 0 ;
182 try{
183 index = parent.offset(name) ;
184 parent[ index ] = rhs ; // #nocov
185 } catch( const index_out_of_bounds& ex ){
186 parent.push_back( rhs, name );
187 }
188 }
189 SEXP get() const {
190 return parent[ parent.offset(name) ];
191 }
192 } ;
193}

Callers

nothing calls this directly

Calls 3

getFunction · 0.85
wrapFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected