@@ -37,19 +37,54 @@ struct NoDelete {
3737 inline void operator ()(T* ptr){};
3838};
3939
40+ namespace arrow {
41+ namespace r {
42+ struct symbols {
43+ static SEXP units;
44+ static SEXP xp;
45+ };
46+ }
47+ }
48+
4049namespace Rcpp {
50+ namespace internal {
51+
52+ template <typename Pointer>
53+ Pointer r6_to_smart_pointer (SEXP self) {
54+ return reinterpret_cast <Pointer>(EXTPTR_PTR (Rf_findVarInFrame (self, arrow::r::symbols::xp)));
55+ }
56+
57+ }
58+
59+ template <typename T>
60+ class ConstReferenceSmartPtrInputParameter {
61+ public:
62+ using const_reference = const T&;
63+
64+ ConstReferenceSmartPtrInputParameter (SEXP self) :
65+ ptr (internal::r6_to_smart_pointer<const T*>(self))
66+ {}
67+
68+ inline operator const_reference (){ return *ptr; }
69+
70+ private:
71+ const T* ptr;
72+ };
73+
4174namespace traits {
4275
76+ template <typename T>
77+ struct input_parameter <const std::shared_ptr<T>&> {
78+ typedef typename Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<T>> type ;
79+ } ;
80+
4381struct wrap_type_shared_ptr_tag {};
4482
4583template <typename T>
4684struct wrap_type_traits <std::shared_ptr<T>> {
4785 using wrap_category = wrap_type_shared_ptr_tag;
4886};
4987
50- template <typename T>
51- class Exporter <std::shared_ptr<T>>;
52-
5388} // namespace traits
5489namespace internal {
5590
@@ -69,26 +104,6 @@ RCPP_EXPOSED_ENUM_NODECL(arrow::StatusCode)
69104RCPP_EXPOSED_ENUM_NODECL (arrow::io::FileMode::type)
70105
71106namespace Rcpp {
72- namespace traits {
73-
74- template <typename T>
75- class Exporter <std::shared_ptr<T>> {
76- public:
77- Exporter (SEXP self) : xp(extract_xp(self)) {}
78-
79- inline std::shared_ptr<T> get () { return *Rcpp::XPtr<std::shared_ptr<T>>(xp); }
80-
81- private:
82- SEXP xp;
83-
84- SEXP extract_xp (SEXP self) {
85- static SEXP symb_xp = Rf_install (" .:xp:." );
86- return Rf_findVarInFrame (self, symb_xp);
87- }
88- };
89-
90- } // namespace traits
91-
92107namespace internal {
93108
94109template <typename T>
@@ -150,9 +165,5 @@ class RBuffer : public MutableBuffer {
150165 Vec vec_;
151166};
152167
153- struct symbols {
154- static SEXP units;
155- };
156-
157168} // namespace r
158169} // namespace arrow
0 commit comments