FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp11/inst/include/cpp11/attribute_proxy.hpp at master · tmastny/cpp11 · GitHub
tmastny
/
cpp11
Public
forked from
r-lib/cpp11
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp11
/
inst
/
include
/
cpp11
/
attribute_proxy.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (36 loc) · 1.27 KB
Breadcrumbs
cpp11
/
inst
/
include
/
cpp11
/
attribute_proxy.hpp
Copy path
File metadata and controls
47 lines (36 loc) · 1.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
pragma
once
#
include
<
initializer_list
>
//
for initializer_list
#
include
<
string
>
//
for string, basic_string
#
include
"
cpp11/R.hpp
"
//
for SEXP, SEXPREC, Rf_install, PROTECT, Rf_...
#
include
"
cpp11/as.hpp
"
//
for as_sexp
#
include
"
cpp11/protect.hpp
"
//
for protect, safe, protect::function
namespace
cpp11
{
class
sexp
;
template
<
typename
T>
class
attribute_proxy
{
private:
const
T& parent_;
SEXP
symbol_;
public:
attribute_proxy
(
const
T& parent,
const
char
* index)
: parent_(parent), symbol_(safe[Rf_install](index)) {}
attribute_proxy
(
const
T& parent,
const
std::string& index)
: parent_(parent), symbol_(safe[Rf_install](index.c_str())) {}
attribute_proxy
(
const
T& parent,
SEXP
index) : parent_(parent), symbol_(index) {}
template
<
typename
C>
attribute_proxy&
operator
=(C rhs) {
SEXP
value =
PROTECT
(
as_sexp
(rhs));
Rf_setAttrib
(parent_.
data
(), symbol_, value);
UNPROTECT
(
1
);
return
*
this
;
}
template
<
typename
C>
attribute_proxy&
operator
=(std::initializer_list<C> rhs) {
SEXP
value =
PROTECT
(
as_sexp
(rhs));
Rf_setAttrib
(parent_.
data
(), symbol_, value);
UNPROTECT
(
1
);
return
*
this
;
}
operator
SEXP
()
const
{
return
safe[Rf_getAttrib](parent_.
data
(), symbol_); }
};
}
//
namespace cpp11
Back
|
FazBrowse Home
|
New Git URL