Rcpp Version 0.12.12
Shield.h
Go to the documentation of this file.
1 // Copyright (C) 2013 Romain Francois and Kevin Ushey
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__protection_Shield_h
19 #define Rcpp__protection_Shield_h
20 
21 namespace Rcpp{
22 
23  inline SEXP Rcpp_protect(SEXP x){
24  if( x != R_NilValue ) PROTECT(x) ;
25  return x ;
26  }
27 
28  template <typename T>
29  class Shield{
30  public:
31  Shield( SEXP t_) : t(Rcpp_protect(t_)){}
33  if( t != R_NilValue ) UNPROTECT(1) ;
34  }
35 
36  operator SEXP() const { return t; }
37  SEXP t ;
38 
39  private:
40  Shield( const Shield& ) ;
41  Shield& operator=( const Shield& ) ;
42  } ;
43 
44 
45 
46 }
47 
48 #endif
SEXP Rcpp_protect(SEXP x)
Definition: Shield.h:23
Shield & operator=(const Shield &)
Shield(SEXP t_)
Definition: Shield.h:31
Rcpp API.
Definition: algo.h:28
SEXP t
Definition: Shield.h:37