34 template <
typename T,
void Finalizer(T*) >
36 if (TYPEOF(p) != EXTPTRSXP)
39 T* ptr = (T*) R_ExternalPtrAddr(p);
46 R_ClearExternalPtr(p);
53 template <
class>
class StoragePolicy = PreserveStorage,
54 void Finalizer(T*) = standard_delete_finalizer<T>,
55 #ifdef RCPP_USE_FINALIZE_ON_EXIT
56 bool finalizeOnExit =
true
58 bool finalizeOnExit =
false
62 public StoragePolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
63 public SlotProxyPolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
65 public TagProxyPolicy< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >,
67 public RObjectMethods< XPtr<T,StoragePolicy, Finalizer, finalizeOnExit> >
89 R_SetExternalPtrTag(x,
tag);
90 R_SetExternalPtrProtected(x,
prot);
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) {
114 Storage::copy__(other);
118 Storage::copy__(other);
127 return (T*)(R_ExternalPtrAddr(Storage::get__()));
140 return get() == NULL;
149 throw ::Rcpp::exception(
"external pointer is not valid");
170 R_RegisterCFinalizerEx(Storage::get__(), finalizer_wrapper<T,Finalizer>,
171 (Rboolean) finalizeOnExit);
191 finalizer_wrapper<T,Finalizer>(Storage::get__());
195 inline operator T*() {
203 if (TYPEOF(x) != EXTPTRSXP) {
204 const char* fmt =
"Expecting an external pointer: [type=%s].";
205 throw ::Rcpp::not_compatible(fmt, Rf_type2char(TYPEOF(x)));
void setDeleteFinalizer()
static void unspecified_bool_true()
XPtr(T *p, bool set_delete_finalizer=true, SEXP tag=R_NilValue, SEXP prot=R_NilValue)
XPtr(SEXP x, SEXP tag, SEXP prot)
StoragePolicy< XPtr > Storage
void(* unspecified_bool_type)()
XPtr & operator=(const XPtr &other)
#define RCPP_DEBUG_2(fmt, M1, M2)
#define RCPP_DEBUG_3(fmt, M1, M2, M3)
#define DEMANGLE(__TYPE__)
void standard_delete_finalizer(T *obj)
void finalizer_wrapper(SEXP p)