File: Environment.cpp

package info (click to toggle)
rcpp 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,480 kB
  • sloc: cpp: 27,436; ansic: 7,778; sh: 53; makefile: 2
file content (176 lines) | stat: -rw-r--r-- 4,146 bytes parent folder | download | duplicates (7)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
//
// Environment.cpp: Rcpp R/C++ interface class library -- Environment unit tests
//
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
// Rcpp is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.

#include <Rcpp.h>
using namespace Rcpp ;

// [[Rcpp::export]]
SEXP runit_ls( Environment env ){
    return env.ls(true) ;
}

// [[Rcpp::export]]
SEXP runit_ls2( Rcpp::Environment env){
    return env.ls(false) ;
}

// [[Rcpp::export]]
SEXP runit_get( Environment env, std::string name){
    return env.get( name ) ;
}

// [[Rcpp::export]]
SEXP runit_get_symbol( Environment env, Symbol name){
    return env.get( name ) ;
}

// [[Rcpp::export]]
SEXP runit_find( Environment env, std::string name){
    return env.find( name ) ;
}

// [[Rcpp::export]]
SEXP runit_find_symbol( Environment env, Symbol name){
    return env.find( name ) ;
}

// [[Rcpp::export]]
bool runit_exists( Environment env, std::string st){
    return env.exists( st ) ;
}

// [[Rcpp::export]]
bool runit_assign( Environment env, std::string st, SEXP object ){
    return env.assign(st, object) ;
}

// [[Rcpp::export]]
void runit_islocked( Environment env ){
    env.assign( "x1", 1 ) ;
    env.assign( "x2", 10.0 ) ;
    env.assign( "x3", std::string( "foobar" ) ) ;
    env.assign( "x4", "foobar" ) ;
    std::vector< std::string > aa(2) ; aa[0] = "foo" ; aa[1] = "bar" ;
    env.assign( "x5", aa ) ;
}

// [[Rcpp::export]]
bool runit_bindingIsActive( Environment env, std::string st ){
    return env.bindingIsActive(st) ;
}

// [[Rcpp::export]]
bool runit_bindingIsLocked( Environment env, std::string st ){
    return env.bindingIsLocked(st) ;
}

// [[Rcpp::export]]
void runit_notanenv( SEXP x){
    Environment env(x) ;
}

// [[Rcpp::export]]
void runit_lockbinding( Environment env, std::string st){
    env.lockBinding( st ) ;
}

// [[Rcpp::export]]
void runit_unlockbinding( Environment env, std::string st){
    env.unlockBinding( st ) ;
}

// [[Rcpp::export]]
Environment runit_globenv(){
    return Rcpp::Environment::global_env();
}

// [[Rcpp::export]]
Environment runit_emptyenv(){
    return Rcpp::Environment::empty_env();
}

// [[Rcpp::export]]
Environment runit_baseenv(){
    return Rcpp::Environment::base_env();
}

// [[Rcpp::export]]
Environment runit_namespace( std::string st){
    return Environment::namespace_env(st);
}

// [[Rcpp::export]]
Environment runit_env_SEXP(SEXP env){
    return Environment( env ) ;
}

// [[Rcpp::export]]
Environment runit_env_string( std::string st ){
    return Environment( st ) ;
}

// [[Rcpp::export]]
Environment runit_env_int( int pos ){
    return Environment( pos ) ;
}

// [[Rcpp::export]]
Environment runit_parent( Environment env ){
    return env.parent() ;
}

// [[Rcpp::export]]
bool runit_remove(Environment env, std::string name ){
    bool res = env.remove( name ) ;
    return wrap( res ) ;
}

// [[Rcpp::export]]
List runit_square( Environment e ){
    List out(3) ;
    out[0] = e["x"] ;
    e["y"] = 2 ;
    out[1] = e["y"] ;
    e["x"] = "foo";
    out[2] = e["x"] ;
    return out ;
}

// [[Rcpp::export]]
Environment runit_Rcpp(){
    return Environment::Rcpp_namespace() ;
}

// [[Rcpp::export]]
Environment runit_child(){
    Environment global_env = Environment::global_env() ;
    return global_env.new_child(false) ;
}

// [[Rcpp::export]]
Environment runit_new_env_default() {
    return Rcpp::new_env();
}

// [[Rcpp::export]]
Environment runit_new_env_parent(SEXP env) {
    return Rcpp::new_env(env);
}