Skip to content

Commit e7e87ec

Browse files
Add copy constructor and assignment operator for XPtr (#330)
1 parent ae9118d commit e7e87ec

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
* `xml_find_all.xml_node()` fails more informatively the `xpath` parameter is the wrong type (@michaelchirico)
1010

11+
* `XPtr` gets explicit copy constructor and assignment operator definitions, which were two missing components of the [Rule of three](https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)) (@michaelchirico)
12+
1113
# xml2 1.3.2
1214

1315
* `read_html()` and `read_xml()` now error if passed strings of length greater than one (#121)

inst/include/xml2_types.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ template <typename T> class XPtr {
2121
data_ = R_MakeExternalPtr((void *) p, R_NilValue, R_NilValue);
2222
R_PreserveObject(data_);
2323
}
24+
25+
XPtr(const XPtr<T> &old) {
26+
data_ = old.data_;
27+
R_PreserveObject(data_);
28+
}
29+
30+
XPtr& operator=(const XPtr<T> &other) {
31+
R_PreserveObject(other.data_);
32+
if (data_ != NULL) {
33+
R_ReleaseObject(data_);
34+
}
35+
data_ = other.data_;
36+
return *this;
37+
}
2438

2539
operator SEXP() const { return data_; }
2640

0 commit comments

Comments
 (0)