Rcpp Version 0.10.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
Environment.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Environment.h: Rcpp R/C++ interface class library -- access R environments
4 //
5 // Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
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 
22 #ifndef Rcpp_Environment_h
23 #define Rcpp_Environment_h
24 
25 #include <Rcpp/RObject.h>
26 
27 namespace Rcpp{
28 
29  class Environment: public RObject{
30  public:
31 
36  class Binding {
37  public:
44  Binding( Environment& env, const std::string& name) ;
45 
49  bool active() const ;
50 
54  bool locked() const ;
55 
59  bool exists() const ;
60 
64  void lock( ) ;
65 
69  void unlock() ;
70 
71  /* lvalue uses */
72 
85  Binding& operator=(const Binding& rhs) ;
86 
97  Binding& operator=(SEXP rhs) ;
98 
115  template <typename WRAPPABLE> Binding& operator=(const WRAPPABLE& rhs) ;
116 
117  /* rvalue */
125  template <typename T> operator T() const ;
126 
127 
128  private:
133 
137  std::string name ;
138  } ;
139 
147  const Binding operator[]( const std::string& name) const ;
148 
152  Binding operator[](const std::string& name) ;
153 
154  friend class Binding ;
155 
156  Environment() ;
157 
163  Environment(SEXP x);
164 
168  Environment(const Environment& other);
169 
173  Environment& operator=(const Environment& other);
174 
180  Environment( const std::string& name );
181 
188  Environment( int pos );
189 
193  ~Environment() ;
194 
203  SEXP ls(bool all) const ;
204 
212  SEXP get(const std::string& name) const ;
213 
221  SEXP find( const std::string& name) const;
222 
231  bool exists( const std::string& name ) const ;
232 
244  bool assign( const std::string& name, SEXP x ) const;
245 
254  template <typename WRAPPABLE>
255  bool assign( const std::string& name, const WRAPPABLE& x) const ;
256 
261  bool isLocked() const ;
262 
266  bool remove( const std::string& name );
267 
273  void lock(bool bindings) ;
274 
281  void lockBinding(const std::string& name);
282 
289  void unlockBinding(const std::string& name);
290 
299  bool bindingIsLocked(const std::string& name) const;
300 
310  bool bindingIsActive(const std::string& name) const;
311 
315  bool is_user_database() const ;
316 
320  static Environment global_env();
321 
325  static Environment empty_env();
326 
330  static Environment base_env();
331 
335  static Environment base_namespace();
336 
340  static Environment Rcpp_namespace();
341 
349  static Environment namespace_env(const std::string& );
350 
354  Environment parent() const;
355 
359  Environment new_child(bool hashed) ;
360 
361  };
362 
363 } // namespace Rcpp
364 
365 #endif