File tree Expand file tree Collapse file tree 5 files changed +80
-21
lines changed
Expand file tree Collapse file tree 5 files changed +80
-21
lines changed Original file line number Diff line number Diff line change 1+ 2014-09-02 Kevin Ushey <
[email protected] >
2+
3+ * inst/include/Rcpp/api/meat/proxy.h: Finish meat reintroduction + tests
4+ * inst/unitTests/runit.wrap.R: Idem
5+ * inst/unitTests/cpp/wrap.cpp: Idem
6+ * inst/include/Rcpp/proxy/FieldProxy.h: Idem
7+
182014-08-13 Kevin Ushey <
[email protected] >
29
310 * inst/include/Rcpp/api/meat/meat.h: Reintroduce meat
Original file line number Diff line number Diff line change @@ -154,6 +154,13 @@ namespace Rcpp {
154154 return *this ;
155155 }
156156
157+ template <typename CLASS>
158+ template <typename T>
159+ typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
160+ DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator =(const traits::named_object<T>& rhs) {
161+ return set (wrap (rhs.object ), rhs.name );
162+ }
163+
157164 template <typename CLASS>
158165 template <typename T>
159166 DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator T () const {
@@ -166,6 +173,36 @@ namespace Rcpp {
166173 return as<T>(get ());
167174 }
168175
176+ // Field proxies
177+ template <typename CLASS>
178+ typename FieldProxyPolicy<CLASS>::FieldProxy&
179+ FieldProxyPolicy<CLASS>::FieldProxy::operator =(const FieldProxyPolicy<CLASS>::FieldProxy& rhs) {
180+ if (this != &rhs) set (rhs.get ());
181+ return *this ;
182+ }
183+
184+ template <typename CLASS>
185+ template <typename T>
186+ typename FieldProxyPolicy<CLASS>::FieldProxy&
187+ FieldProxyPolicy<CLASS>::FieldProxy::operator =(const T& rhs) {
188+ SEXP tmp = PROTECT (wrap (rhs));
189+ set (tmp);
190+ UNPROTECT (1 );
191+ return *this ;
192+ }
193+
194+ template <typename CLASS>
195+ template <typename T>
196+ FieldProxyPolicy<CLASS>::FieldProxy::operator T () const {
197+ return as<T>(get ());
198+ }
199+
200+ template <typename CLASS>
201+ template <typename T>
202+ FieldProxyPolicy<CLASS>::const_FieldProxy::operator T () const {
203+ return as<T>(get ());
204+ }
205+
169206}
170207
171208#endif
Original file line number Diff line number Diff line change @@ -29,24 +29,12 @@ class FieldProxyPolicy {
2929 FieldProxy ( CLASS& v, const std::string& name) :
3030 parent (v), field_name(name) {}
3131
32- FieldProxy& operator =(const FieldProxy& rhs){
33- if ( this != &rhs ) set ( rhs.get () ) ;
34- return *this ;
35- }
32+ FieldProxy& operator =(const FieldProxy& rhs);
3633
37- template <typename T> FieldProxy& operator =(const T& rhs) {
38- SEXP tmp = PROTECT ( wrap (rhs) );
39- set (tmp);
40- UNPROTECT (1 );
41- return *this ;
42- }
34+ template <typename T> FieldProxy& operator =(const T& rhs);
4335
44- template <typename T> operator T () const {
45- return as<T>( get () );
46- }
47- inline operator SEXP () const {
48- return get () ;
49- }
36+ template <typename T> operator T () const ;
37+ inline operator SEXP () const { return get (); }
5038
5139 private:
5240 CLASS& parent;
@@ -68,9 +56,7 @@ class FieldProxyPolicy {
6856 const_FieldProxy ( const CLASS& v, const std::string& name) :
6957 parent (v), field_name(name) {}
7058
71- template <typename T> operator T () const {
72- return as<T>( get () );
73- }
59+ template <typename T> operator T () const ;
7460 inline operator SEXP () const {
7561 return get () ;
7662 }
Original file line number Diff line number Diff line change 1919// You should have received a copy of the GNU General Public License
2020// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
2121
22+ // Testing 'wrap', 'as' with custom class -- see
23+ // https://github.com/RcppCore/Rcpp/issues/165
24+ template <typename T>
25+ class Bar {
26+ public:
27+ Bar (T t) : t(t) {}
28+ ~Bar () {}
29+ T t;
30+ };
31+
32+ #include < RcppCommon.h>
33+ namespace Rcpp {
34+ template <typename T> SEXP wrap (const Bar<T> &b);
35+ }
36+
2237#include < Rcpp.h>
23- using namespace Rcpp ;
38+
39+ template <typename T> SEXP Rcpp::wrap (const Bar<T> &b) {
40+ return Rcpp::wrap (b.t );
41+ }
42+
43+ // [[Rcpp::export]]
44+ Bar<int > test_wrap_custom_class () {
45+ Bar<int > b (42 );
46+ return b;
47+ }
48+
49+ using namespace Rcpp ;
2450
2551// [[Rcpp::export]]
2652IntegerVector map_string_int (){
@@ -255,4 +281,3 @@ SEXP vector_Foo(){
255281 vec[1 ] = Foo ( 3 ) ;
256282 return wrap (vec) ;
257283}
258-
Original file line number Diff line number Diff line change @@ -183,5 +183,9 @@ if (.runThisTest) {
183183 )
184184 }
185185
186+ test.wrap.custom.class <- function () {
187+ checkEquals(test_wrap_custom_class(), 42 )
188+ }
189+
186190}
187191
You can’t perform that action at this time.
0 commit comments