| 24 | |
| 25 | template <typename T> |
| 26 | class ChildVector : public T { |
| 27 | |
| 28 | public: |
| 29 | |
| 30 | ChildVector(SEXP data_, SEXP parent_, R_xlen_t i_): |
| 31 | T(data_), |
| 32 | parent(parent_), |
| 33 | i(i_) {} |
| 34 | |
| 35 | ChildVector(const ChildVector& other): |
| 36 | T(wrap(other)), |
| 37 | parent(other.parent), |
| 38 | i(other.i) {} |
| 39 | |
| 40 | inline ChildVector& operator=(const ChildVector& other) { |
| 41 | if (this != &other) { |
| 42 | this->set__(other); |
| 43 | if (parent != NULL && !Rf_isNull(parent)) { |
| 44 | SET_VECTOR_ELT(parent, i, other); |
| 45 | } |
| 46 | } |
| 47 | return *this; |
| 48 | } |
| 49 | |
| 50 | inline ChildVector& operator=(const T& other) { |
| 51 | this->set__(other); |
| 52 | if (parent != NULL && !Rf_isNull(parent)) { |
| 53 | SET_VECTOR_ELT(parent, i, other); |
| 54 | } |
| 55 | return *this; |
| 56 | } |
| 57 | |
| 58 | template <typename U> |
| 59 | inline ChildVector& operator=(const U& other) { |
| 60 | Shield<SEXP> wrapped( wrap(other) ); |
| 61 | T vec = as<T>(wrapped); |
| 62 | this->set__(vec); |
| 63 | if (parent != NULL && !Rf_isNull(parent)) { |
| 64 | SET_VECTOR_ELT(parent, i, vec); |
| 65 | } |
| 66 | return *this; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | SEXP parent; |
| 71 | R_xlen_t i; |
| 72 | }; |
| 73 | |
| 74 | } // namespace Rcpp |
| 75 | |