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

Class SubsetProxy

inst/include/Rcpp/vector/Subsetter.h:33–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 int RHS_RTYPE, bool RHS_NA, typename RHS_T
32>
33class SubsetProxy {
34
35 typedef Vector<RTYPE, StoragePolicy> LHS_t;
36 typedef Vector<RHS_RTYPE, StoragePolicy> RHS_t;
37
38public:
39
40 SubsetProxy(LHS_t& lhs_, const RHS_t& rhs_):
41 lhs(lhs_), rhs(rhs_), lhs_n(lhs.size()), rhs_n(rhs.size()) {
42 get_indices( traits::identity< traits::int2type<RHS_RTYPE> >() );
43 }
44
45 SubsetProxy(const SubsetProxy& other):
46 lhs(other.lhs),
47 rhs(other.rhs),
48 lhs_n(other.lhs_n),
49 rhs_n(other.rhs_n),
50 indices(other.indices),
51 indices_n(other.indices_n) {}
52
53 // Enable e.g. x[y] = z
54 template <int OtherRTYPE, template <class> class OtherStoragePolicy>
55 SubsetProxy& operator=(const Vector<OtherRTYPE, OtherStoragePolicy>& other) {
56 R_xlen_t n = other.size();
57
58 if (n == 1) {
59 for (R_xlen_t i=0; i < indices_n; ++i) {
60 lhs[ indices[i] ] = other[0];
61 }
62 } else if (n == indices_n) {
63 for (R_xlen_t i=0; i < n; ++i) {
64 lhs[ indices[i] ] = other[i];
65 }
66 } else {
67 stop("index error");
68 }
69 return *this;
70 }
71
72 // Enable e.g. x[y] = 1;
73 // TODO: std::enable_if<primitive> with C++11
74 SubsetProxy& operator=(double other) {
75 for (R_xlen_t i=0; i < indices_n; ++i) {
76 lhs[ indices[i] ] = other;
77 }
78 return *this;
79 }
80
81 SubsetProxy& operator=(int other) {
82 for (R_xlen_t i=0; i < indices_n; ++i) {
83 lhs[ indices[i] ] = other;
84 }
85 return *this;
86 }
87
88 SubsetProxy& operator=(const char* other) {
89 for (R_xlen_t i=0; i < indices_n; ++i) {
90 lhs[ indices[i] ] = other;

Callers

nothing calls this directly

Calls 3

stopFunction · 0.85
wrapFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected