FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp11/inst/include/cpp11/environment.hpp at main · r-lib/cpp11 · GitHub
r-lib
/
cpp11
Public
Notifications
You must be signed in to change notification settings
Fork
52
Star
225
Code
Issues
51
Pull requests
8
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp11
/
inst
/
include
/
cpp11
/
environment.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (42 loc) · 1.6 KB
Breadcrumbs
cpp11
/
inst
/
include
/
cpp11
/
environment.hpp
Copy path
File metadata and controls
56 lines (42 loc) · 1.6 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
48
49
50
51
52
53
54
55
56
#
pragma
once
#
include
<
string
>
//
for string, basic_string
#
include
"
cpp11/R.hpp
"
//
for SEXP, SEXPREC, Rf_install, r_env_get...
#
include
"
cpp11/as.hpp
"
//
for as_sexp
#
include
"
cpp11/protect.hpp
"
//
for protect, protect::function, safe, unwin...
#
include
"
cpp11/sexp.hpp
"
//
for sexp
namespace
cpp11
{
class
environment
{
private:
sexp env_;
class
proxy
{
SEXP
parent_;
SEXP
name_;
public:
proxy
(
SEXP
parent,
SEXP
name) : parent_(parent), name_(name) {}
template
<
typename
T>
proxy&
operator
=(T value) {
safe[Rf_defineVar](name_,
as_sexp
(value), parent_);
return
*
this
;
}
operator
SEXP
()
const
{
return
safe[detail::r_env_get](parent_, name_); };
operator
sexp
()
const
{
return
SEXP
(); };
};
public:
environment
(
SEXP
env) : env_(env) {}
environment
(sexp env) : env_(env) {}
proxy
operator
[](
const
SEXP
name)
const
{
return
{env_, name}; }
proxy
operator
[](
const
char
* name)
const
{
return
operator
[](safe[Rf_install](name)); }
proxy
operator
[](
const
std::string& name)
const
{
return
operator
[](name.
c_str
()); }
bool
exists
(
SEXP
name)
const
{
return
safe[detail::r_env_has](env_, name); }
bool
exists
(
const
char
* name)
const
{
return
exists
(safe[Rf_install](name)); }
bool
exists
(
const
std::string& name)
const
{
return
exists
(name.
c_str
()); }
void
remove
(
SEXP
name) {
PROTECT
(name);
R_removeVarFromFrame
(name, env_);
UNPROTECT
(
1
);
}
void
remove
(
const
char
* name) {
remove
(safe[Rf_install](name)); }
R_xlen_t
size
()
const
{
return
Rf_xlength
(env_); }
operator
SEXP
()
const
{
return
env_; }
};
}
//
namespace cpp11
Back
|
FazBrowse Home
|
New Git URL