Rcpp Version 1.0.9
PreserveStorage.h
Go to the documentation of this file.
1 
2 // PreserveStorage.h: Rcpp R/C++ interface class library -- helper class
3 //
4 // Copyright (C) 2013 - 2020 Romain Francois
5 // Copyright (C) 2021 Romain Francois and IƱaki Ucar
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_PreserveStorage_h
23 #define Rcpp_PreserveStorage_h
24 
25 namespace Rcpp{
26 
27  template <typename CLASS>
29  public:
30 
31  PreserveStorage() : data(R_NilValue), token(R_NilValue){}
32 
35  data = R_NilValue;
36  token = R_NilValue;
37  }
38 
39  inline void set__(SEXP x){
40  if (data != x) {
41  data = x;
44  }
45 
46  // calls the update method of CLASS
47  // this is where to react to changes in the underlying SEXP
48  static_cast<CLASS&>(*this).update(data) ;
49  }
50 
51  inline SEXP get__() const {
52  return data ;
53  }
54 
55  inline SEXP invalidate__(){
56  SEXP out = data ;
58  data = R_NilValue ;
59  token = R_NilValue ;
60  return out ;
61  }
62 
63  template <typename T>
64  inline T& copy__(const T& other){
65  if( this != &other){
66  set__(other.get__());
67  }
68  return static_cast<T&>(*this) ;
69  }
70 
71  inline bool inherits(const char* clazz) const {
72  return ::Rf_inherits( data, clazz) ;
73  }
74 
75  inline operator SEXP() const { return data; }
76 
77  private:
78  SEXP data ;
79  SEXP token ;
80  } ;
81 
82 }
83 
84 #endif
T & copy__(const T &other)
bool inherits(const char *clazz) const
Rcpp API.
Definition: algo.h:28
SEXP Rcpp_PreciousPreserve(SEXP object)
Definition: RcppCommon.h:116
void Rcpp_PreciousRelease(SEXP token)
Definition: RcppCommon.h:120