1 // cpp11 version: 0.3.1.1
2 // vendored on: 2021-08-11
5 #include <initializer_list> // for initializer_list
6 #include <string> // for string, basic_string
8 #include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_install, PROTECT, Rf_...
9 #include "cpp11/as.hpp" // for as_sexp
10 #include "cpp11/protect.hpp" // for protect, safe, protect::function
17 class attribute_proxy {
23 attribute_proxy(const T& parent, const char* index)
24 : parent_(parent), symbol_(safe[Rf_install](index)) {}
26 attribute_proxy(const T& parent, const std::string& index)
27 : parent_(parent), symbol_(safe[Rf_install](index.c_str())) {}
29 attribute_proxy(const T& parent, SEXP index) : parent_(parent), symbol_(index) {}
32 attribute_proxy& operator=(C rhs) {
33 SEXP value = PROTECT(as_sexp(rhs));
34 Rf_setAttrib(parent_.data(), symbol_, value);
40 attribute_proxy& operator=(std::initializer_list<C> rhs) {
41 SEXP value = PROTECT(as_sexp(rhs));
42 Rf_setAttrib(parent_.data(), symbol_, value);
47 operator SEXP() const { return safe[Rf_getAttrib](parent_.data(), symbol_); }