Skip to content

Commit 700faa2

Browse files
committed
Merge branch 'feature/reintroduce-proxy-meat'
Conflicts: ChangeLog
2 parents a86ab1f + e006552 commit 700faa2

File tree

13 files changed

+289
-102
lines changed

13 files changed

+289
-102
lines changed

ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
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+
18
2014-09-02 Dirk Eddelbuettel <[email protected]>
29

310
* inst/include/Rcpp/vector/Vector.h: Reversing change from Aug 30: the
@@ -24,6 +31,17 @@
2431
packages stressing that any combined work linking to the GPL-ed R will
2532
also be under the terms of the GNU General Public License.
2633

34+
2014-08-13 Kevin Ushey <[email protected]>
35+
36+
* inst/include/Rcpp/api/meat/meat.h: Reintroduce meat
37+
* inst/include/Rcpp/api/meat/proxy.h: Idem
38+
* inst/include/Rcpp/proxy/AttributeProxy.h: Idem
39+
* inst/include/Rcpp/proxy/Binding.h: Idem
40+
* inst/include/Rcpp/proxy/NamesProxy.h: Idem
41+
* inst/include/Rcpp/proxy/SlotProxy.h: Idem
42+
* inst/include/Rcpp/proxy/TagProxy.h: Idem
43+
* inst/include/Rcpp/proxy/proxy.h: Idem
44+
2745
2014-08-06 Christian Authmann <[email protected]>
2846

2947
* inst/include/Rcpp/InternalFunctionWithStdFunction.h: Extend the

inst/include/Rcpp/api/meat/meat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <Rcpp/api/meat/S4.h>
3232
#include <Rcpp/api/meat/Environment.h>
3333

34+
#include <Rcpp/api/meat/proxy.h>
35+
3436
#include <Rcpp/api/meat/DottedPairImpl.h>
3537
#include <Rcpp/api/meat/StretchyList.h>
3638
#include <Rcpp/api/meat/Vector.h>

inst/include/Rcpp/api/meat/proxy.h

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// proxy.h: Rcpp R/C++ interface class library -- proxy meat
4+
//
5+
// Copyright (C) 2014 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
#ifndef RCPP_API_MEAT_PROXY_H
22+
#define RCPP_API_MEAT_PROXY_H
23+
24+
// NOTE: Implementing this as 'meat' is necessary as it allows user-defined
25+
// classes writing their own overloads of 'wrap', 'as' to function correctly!
26+
namespace Rcpp {
27+
28+
// AttributeProxy
29+
template <typename CLASS>
30+
template <typename T>
31+
typename AttributeProxyPolicy<CLASS>::AttributeProxy&
32+
AttributeProxyPolicy<CLASS>::AttributeProxy::operator=(const T& rhs) {
33+
set( wrap(rhs) );
34+
return *this;
35+
}
36+
37+
template <typename CLASS>
38+
template <typename T>
39+
AttributeProxyPolicy<CLASS>::AttributeProxy::operator T() const {
40+
return as<T>(get());
41+
}
42+
43+
template <typename CLASS>
44+
AttributeProxyPolicy<CLASS>::AttributeProxy::operator SEXP() const {
45+
return get();
46+
}
47+
48+
template <typename CLASS>
49+
template <typename T>
50+
AttributeProxyPolicy<CLASS>::const_AttributeProxy::operator T() const {
51+
return as<T>(get());
52+
}
53+
54+
template <typename CLASS>
55+
AttributeProxyPolicy<CLASS>::const_AttributeProxy::operator SEXP() const {
56+
return get();
57+
}
58+
59+
// NamesProxy
60+
template <typename CLASS>
61+
template <typename T>
62+
typename NamesProxyPolicy<CLASS>::NamesProxy&
63+
NamesProxyPolicy<CLASS>::NamesProxy::operator=(const T& rhs) {
64+
set( wrap(rhs) );
65+
return *this;
66+
}
67+
68+
template <typename CLASS>
69+
template <typename T>
70+
NamesProxyPolicy<CLASS>::NamesProxy::operator T() const {
71+
return as<T>( get() );
72+
}
73+
74+
template <typename CLASS>
75+
template <typename T>
76+
NamesProxyPolicy<CLASS>::const_NamesProxy::operator T() const {
77+
return as<T>( get() );
78+
}
79+
80+
// SlotProxy
81+
template <typename CLASS>
82+
template <typename T>
83+
typename SlotProxyPolicy<CLASS>::SlotProxy&
84+
SlotProxyPolicy<CLASS>::SlotProxy::operator=(const T& rhs) {
85+
set(wrap(rhs));
86+
return *this;
87+
}
88+
89+
template <typename CLASS>
90+
template <typename T>
91+
SlotProxyPolicy<CLASS>::SlotProxy::operator T() const {
92+
return as<T>(get());
93+
}
94+
95+
// TagProxy
96+
template <typename CLASS>
97+
template <typename T>
98+
typename TagProxyPolicy<CLASS>::TagProxy&
99+
TagProxyPolicy<CLASS>::TagProxy::operator=(const T& rhs) {
100+
set( wrap(rhs) );
101+
return *this;
102+
}
103+
104+
template <typename CLASS>
105+
template <typename T>
106+
TagProxyPolicy<CLASS>::TagProxy::operator T() const {
107+
return as<T>(get());
108+
}
109+
110+
template <typename CLASS>
111+
TagProxyPolicy<CLASS>::TagProxy::operator SEXP() const {
112+
return get();
113+
}
114+
115+
template <typename CLASS>
116+
template <typename T>
117+
TagProxyPolicy<CLASS>::const_TagProxy::operator T() const {
118+
return as<T>(get());
119+
}
120+
121+
template <typename CLASS>
122+
TagProxyPolicy<CLASS>::const_TagProxy::operator SEXP() const {
123+
return get();
124+
}
125+
126+
// Binding
127+
template <typename CLASS>
128+
template <typename T>
129+
typename BindingPolicy<CLASS>::Binding&
130+
BindingPolicy<CLASS>::Binding::operator=(const T& rhs) {
131+
set(wrap(rhs));
132+
return *this;
133+
}
134+
135+
template <typename CLASS>
136+
template <typename T>
137+
BindingPolicy<CLASS>::Binding::operator T() const {
138+
return as<T>(get());
139+
}
140+
141+
template <typename CLASS>
142+
template <typename T>
143+
BindingPolicy<CLASS>::const_Binding::operator T() const {
144+
return as<T>(get());
145+
}
146+
147+
// DottedPairProxy
148+
template <typename CLASS>
149+
template <typename T>
150+
typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
151+
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator=(const T& rhs) {
152+
set(wrap(rhs));
153+
return *this;
154+
}
155+
156+
template <typename CLASS>
157+
template <typename T>
158+
typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
159+
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator=(const traits::named_object<T>& rhs) {
160+
return set(wrap(rhs.object), rhs.name);
161+
}
162+
163+
template <typename CLASS>
164+
template <typename T>
165+
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator T() const {
166+
return as<T>(get());
167+
}
168+
169+
template <typename CLASS>
170+
template <typename T>
171+
DottedPairProxyPolicy<CLASS>::const_DottedPairProxy::operator T() const {
172+
return as<T>(get());
173+
}
174+
175+
// FieldProxy
176+
template <typename CLASS>
177+
typename FieldProxyPolicy<CLASS>::FieldProxy&
178+
FieldProxyPolicy<CLASS>::FieldProxy::operator=(const FieldProxyPolicy<CLASS>::FieldProxy& rhs) {
179+
if (this != &rhs) set(rhs.get());
180+
return *this;
181+
}
182+
183+
template <typename CLASS>
184+
template <typename T>
185+
typename FieldProxyPolicy<CLASS>::FieldProxy&
186+
FieldProxyPolicy<CLASS>::FieldProxy::operator=(const T& rhs) {
187+
SEXP tmp = PROTECT(wrap(rhs));
188+
set(tmp);
189+
UNPROTECT(1);
190+
return *this;
191+
}
192+
193+
template <typename CLASS>
194+
template <typename T>
195+
FieldProxyPolicy<CLASS>::FieldProxy::operator T() const {
196+
return as<T>(get());
197+
}
198+
199+
template <typename CLASS>
200+
template <typename T>
201+
FieldProxyPolicy<CLASS>::const_FieldProxy::operator T() const {
202+
return as<T>(get());
203+
}
204+
205+
}
206+
207+
#endif

inst/include/Rcpp/proxy/AttributeProxy.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,11 @@ class AttributeProxyPolicy {
3535
return *this ;
3636
}
3737

38-
template <typename T> AttributeProxy& operator=(const T& rhs) {
39-
set( wrap( rhs ) );
40-
return *this;
41-
}
38+
template <typename T> AttributeProxy& operator=(const T& rhs);
4239

43-
template <typename T> operator T() const {
44-
return as<T>( get() );
45-
}
40+
template <typename T> operator T() const;
4641

47-
inline operator SEXP() const {
48-
return get() ;
49-
}
42+
inline operator SEXP() const;
5043

5144
private:
5245
CLASS& parent;
@@ -65,12 +58,8 @@ class AttributeProxyPolicy {
6558
const_AttributeProxy( const CLASS& v, const std::string& name)
6659
: parent(v), attr_name(Rf_install(name.c_str())){}
6760

68-
template <typename T> operator T() const {
69-
return as<T>( get() );
70-
}
71-
inline operator SEXP() const {
72-
return get() ;
73-
}
61+
template <typename T> operator T() const;
62+
inline operator SEXP() const;
7463

7564
private:
7665
const CLASS& parent;

inst/include/Rcpp/proxy/Binding.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,10 @@ class BindingPolicy {
5050
return *this ;
5151
}
5252

53-
template <typename WRAPPABLE> Binding& operator=(const WRAPPABLE& rhs) {
54-
set( wrap(rhs) );
55-
return *this;
56-
}
57-
template <typename T> operator T() const {
58-
return as<T>( get() );
59-
}
53+
template <typename WRAPPABLE>
54+
Binding& operator=(const WRAPPABLE& rhs);
55+
56+
template <typename T> operator T() const;
6057

6158
private:
6259

@@ -86,9 +83,7 @@ class BindingPolicy {
8683
inline bool exists() const {
8784
return env.exists(name) ;
8885
}
89-
template <typename T> operator T() const {
90-
return as<T>( get() );
91-
}
86+
template <typename T> operator T() const;
9287

9388
private:
9489

inst/include/Rcpp/proxy/DottedPairProxy.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,20 @@ class DottedPairProxyPolicy {
3333
node = x ;
3434
}
3535

36-
DottedPairProxy& operator=(const DottedPairProxy& rhs){
36+
DottedPairProxy& operator=(const DottedPairProxy& rhs) {
3737
return set(rhs.get());
3838
}
39-
DottedPairProxy& operator=(SEXP rhs){
39+
DottedPairProxy& operator=(SEXP rhs) {
4040
return set(rhs) ;
4141
}
4242

4343
template <typename T>
44-
DottedPairProxy& operator=(const T& rhs) {
45-
return set( wrap(rhs) );
46-
}
44+
DottedPairProxy& operator=(const T& rhs);
4745

4846
template <typename T>
49-
DottedPairProxy& operator=(const traits::named_object<T>& rhs) {
50-
return set( wrap(rhs.object), rhs.name ) ;
51-
}
47+
DottedPairProxy& operator=(const traits::named_object<T>& rhs);
5248

53-
template <typename T> operator T() const {
54-
return as<T>( get() );
55-
}
49+
template <typename T> operator T() const;
5650

5751
inline SEXP get() const {
5852
return CAR(node);
@@ -84,9 +78,7 @@ class DottedPairProxyPolicy {
8478
node = x ;
8579
}
8680

87-
template <typename T> operator T() const {
88-
return as<T>( get() );
89-
}
81+
template <typename T> operator T() const;
9082

9183
inline SEXP get() const {
9284
return CAR(node);

inst/include/Rcpp/proxy/FieldProxy.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)