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

Class XPtr

inst/include/Rcpp/XPtr.h:61–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 #endif
60>
61class XPtr :
62 public StoragePolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
63 public SlotProxyPolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
64 public AttributeProxyPolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
65 public TagProxyPolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
66 public ProtectedProxyPolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
67 public RObjectMethods< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >
68{
69public:
70
71 typedef StoragePolicy<XPtr> Storage;
72
73 /**
74 * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
75 *
76 * @param xp external pointer to wrap
77 */
78 explicit XPtr(SEXP x) { checked_set(x); };
79
80 /**
81 * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
82 *
83 * @param xp external pointer to wrap
84 * @param tag tag to assign to external pointer
85 * @param prot protected data to assign to external pointer
86 */
87 explicit XPtr(SEXP x, SEXP tag, SEXP prot) {
88 checked_set(x);
89 R_SetExternalPtrTag(x, tag);
90 R_SetExternalPtrProtected(x, prot);
91 };
92
93 /**
94 * creates a new external pointer wrapping the dumb pointer p.
95 *
96 * @param p dumb pointer to some object
97 * @param set_delete_finalizer if set to true, a finalizer will
98 * be registered for the external pointer. The finalizer
99 * is called when the xp is garbage collected. The finalizer
100 * is merely a call to the delete operator or the pointer
101 * so you need to make sure the pointer can be "delete" d
102 * this way (has to be a C++ object)
103 */
104 explicit XPtr(T* p, bool set_delete_finalizer = true,
105 SEXP tag = R_NilValue, SEXP prot = R_NilValue) {
106 RCPP_DEBUG_2("XPtr(T* p = <%p>, bool set_delete_finalizer = %s, SEXP tag = R_NilValue, SEXP prot = R_NilValue)", p, (set_delete_finalizer ? "true" : "false"))
107 Storage::set__(R_MakeExternalPtr((void*)p , tag, prot));
108 if (set_delete_finalizer) {
109 setDeleteFinalizer(); // #nocov
110 }
111 }
112
113 XPtr(const XPtr& other) {
114 Storage::copy__(other);
115 }
116
117 XPtr& operator=(const XPtr& other) {
118 Storage::copy__(other);

Callers

nothing calls this directly

Calls 1

getFunction · 0.85

Tested by

no test coverage detected