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

Class string_name_proxy

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

Source from the content-addressed store, hash-verified

81
82 template <int RTYPE, template <class> class StoragePolicy>
83 class string_name_proxy{
84 public:
85 typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
86 typedef const char* iterator ;
87 typedef const char& reference ;
88
89 string_name_proxy( VECTOR& v, const std::string& name_) :
90 parent(v), name(name_){} ;
91 string_name_proxy( const string_name_proxy& other ) :
92 parent(other.parent), name(other.name){} ;
93 ~string_name_proxy(){} ;
94
95 string_name_proxy& operator=( const std::string& rhs ){
96 set( rhs ) ;
97 return *this ;
98 }
99 string_name_proxy& operator=( const string_name_proxy& other){
100 set( other.get() ) ;
101 return *this ;
102 }
103
104 operator char* () const {
105 return get() ;
106 }
107
108 operator SEXP() const {
109 return ::Rf_mkString(get()) ;
110 }
111
112 inline iterator begin() { return get() ; }
113 inline iterator end(){ return begin() + size() ; }
114 inline reference operator[]( R_xlen_t i ){ return *( get() + i ) ; }
115 inline R_xlen_t size(){ return strlen( get() ) ; }
116
117 private:
118 VECTOR& parent ;
119 std::string name;
120 void set( const std::string& rhs ){
121 R_xlen_t index = 0 ;
122 try{
123 index = parent.offset(name) ;
124 parent[ index ] = rhs ;
125 } catch( const index_out_of_bounds& ex ){
126 parent.push_back( rhs, name );
127 }
128 }
129 char* get() const {
130 return parent[ parent.offset(name) ];
131 }
132
133 } ;
134
135 template <int RTYPE, template <class> class StoragePolicy>
136 class generic_name_proxy {

Callers

nothing calls this directly

Calls 2

getFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected