Skip to content

Commit

Permalink
Add copy constructor and assignment operator for XPtr (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Feb 1, 2021
1 parent ae9118d commit e7e87ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

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

* `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)

# xml2 1.3.2

* `read_html()` and `read_xml()` now error if passed strings of length greater than one (#121)
Expand Down
14 changes: 14 additions & 0 deletions inst/include/xml2_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ template <typename T> class XPtr {
data_ = R_MakeExternalPtr((void *) p, R_NilValue, R_NilValue);
R_PreserveObject(data_);
}

XPtr(const XPtr<T> &old) {
data_ = old.data_;
R_PreserveObject(data_);
}

XPtr& operator=(const XPtr<T> &other) {
R_PreserveObject(other.data_);
if (data_ != NULL) {
R_ReleaseObject(data_);
}
data_ = other.data_;
return *this;
}

operator SEXP() const { return data_; }

Expand Down

0 comments on commit e7e87ec

Please sign in to comment.