Rcpp Version 1.0.14
Loading...
Searching...
No Matches
Binding.h
Go to the documentation of this file.
1// Copyright (C) 2013 Romain Francois
2//
3// This file is part of Rcpp.
4//
5// Rcpp is free software: you can redistribute it and/or modify it
6// under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 2 of the License, or
8// (at your option) any later version.
9//
10// Rcpp is distributed in the hope that it will be useful, but
11// WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
17
18#ifndef Rcpp_proxy_EnvironmentBinding_h
19#define Rcpp_proxy_EnvironmentBinding_h
20
21namespace Rcpp{
22
23template <typename EnvironmentClass>
25public:
26
27 class Binding : public GenericProxy<Binding> {
28 public:
29 Binding( EnvironmentClass& env_, const std::string& name_) :
30 env(env_), name(name_){}
31
32 inline bool active() const {
33 return env.bindingIsActive(name) ;
34 }
35 inline bool locked() const {
36 return env.bindingIsLocked(name) ;
37 }
38 inline bool exists() const {
39 return env.exists(name) ;
40 }
41 void lock() {
42 env.lockBinding(name) ;
43 }
44 void unlock(){
45 env.unlockBinding(name) ;
46 }
48 if( *this != rhs )
49 set( rhs.get() ) ;
50 return *this ;
51 }
52
53 template <typename WRAPPABLE>
55
56 template <typename T> operator T() const;
57
58 private:
59
60 SEXP get() const {
61 return env.get( name ) ;
62 }
63
64 void set( SEXP x){
65 env.assign(name, x ) ;
66 }
67
69 std::string name ;
70 } ;
71
72 class const_Binding : public GenericProxy<const_Binding> {
73 public:
74 const_Binding( const EnvironmentClass& env_, const std::string& name_) :
75 env(env_), name(name_){}
76
77 inline bool active() const {
78 return env.bindingIsActive(name) ;
79 }
80 inline bool locked() const {
81 return env.bindingIsLocked(name) ;
82 }
83 inline bool exists() const {
84 return env.exists(name) ;
85 }
86 template <typename T> operator T() const;
87
88 private:
89
90 SEXP get() const {
91 return env.get( name ) ;
92 }
93
95 std::string name ;
96 } ;
97
98 const_Binding operator[]( const std::string& name) const {
99 return const_Binding( static_cast<const EnvironmentClass&>(*this), name ) ;
100 }
101 Binding operator[](const std::string& name){
102 return Binding( static_cast<EnvironmentClass&>(*this), name ) ;
103 }
104
105} ;
106
107
108}
109#endif
Binding(EnvironmentClass &env_, const std::string &name_)
Definition Binding.h:29
Binding & operator=(const Binding &rhs)
Definition Binding.h:47
EnvironmentClass & env
Definition Binding.h:68
Binding & operator=(const WRAPPABLE &rhs)
const EnvironmentClass & env
Definition Binding.h:94
const_Binding(const EnvironmentClass &env_, const std::string &name_)
Definition Binding.h:74
const_Binding operator[](const std::string &name) const
Definition Binding.h:98
Binding operator[](const std::string &name)
Definition Binding.h:101
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151