-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathNode.h
More file actions
111 lines (81 loc) · 2.65 KB
/
Copy pathNode.h
File metadata and controls
111 lines (81 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef Rcpp_Node_h
#define Rcpp_Node_h
namespace Rcpp{
class Node {
public:
Node( SEXP data_ ) : data(data_){}
Node next() const {
return CDR(data) ;
}
bool last() const {
return CDR(data) == R_NilValue ;
}
inline SEXP get() const {
return data;
}
class ValueProxy : public GenericProxy<ValueProxy> {
public:
ValueProxy( Node& node_ ) : node(node_){}
ValueProxy& operator=( const ValueProxy& rhs){
if(this != &rhs) set( rhs.get() ) ;
return *this ;
}
template <typename T>
ValueProxy& operator=( const T& rhs) {
return set( wrap(rhs) ) ;
}
template <typename T>
operator T() const {
return as<T>(get());
}
private:
Node& node ;
inline SEXP get() const {
return CAR(node.get()) ;
}
inline ValueProxy& set( SEXP x){
SETCAR(node.get(), x) ;
return *this ;
}
} ;
inline ValueProxy value() {
return ValueProxy(*this) ;
}
inline const ValueProxy value() const {
return ValueProxy(const_cast<Node&>(*this)) ;
}
class TagProxy : public GenericProxy<TagProxy> {
public:
TagProxy( Node& node_ ) : node(node_){}
TagProxy& operator=( const TagProxy& rhs){
if(this != &rhs) set( rhs.get() ) ;
return *this ;
}
template <typename T>
TagProxy& operator=( const T& rhs){
return set( Symbol(rhs) ) ;
}
inline operator SEXP() const {
return get() ;
}
private:
Node& node ;
inline SEXP get() const {
return TAG(node.get()) ;
}
inline TagProxy& set(SEXP x){
SET_TAG(node.get(), x) ;
return *this ;
}
} ;
inline TagProxy tag() {
return TagProxy( *this ) ;
}
inline const TagProxy tag() const {
return TagProxy( const_cast<Node&>(*this) ) ;
}
private:
SEXP data ;
} ;
}
#endif