1 #ifndef Rcpp_NoProtectStorage_h 2 #define Rcpp_NoProtectStorage_h 3 4 namespace Rcpp{ 5 6 template <typename CLASS> 7 class NoProtectStorage { 8 public: 9 NoProtectStorage()10 NoProtectStorage() : data(R_NilValue){} 11 ~NoProtectStorage()12 ~NoProtectStorage(){ 13 data = R_NilValue; 14 } 15 set__(SEXP x)16 inline void set__(SEXP x){ 17 data = x ; 18 19 // calls the update method of CLASS 20 // this is where to react to changes in the underlying SEXP 21 static_cast<CLASS&>(*this).update(data) ; 22 } 23 get__()24 inline SEXP get__() const { 25 return data ; 26 } 27 invalidate__()28 inline SEXP invalidate__(){ 29 data = R_NilValue ; 30 return data ; 31 } 32 copy__(const CLASS & other)33 inline CLASS& copy__(const CLASS& other){ 34 if( this != &other){ 35 set__(other.get__()); 36 } 37 return static_cast<CLASS&>(*this) ; 38 } 39 inherits(const char * clazz)40 inline bool inherits(const char* clazz) const { 41 return ::Rf_inherits( data, clazz) ; 42 } 43 SEXP()44 inline operator SEXP() const { 45 return data; 46 } 47 48 private: 49 SEXP data ; 50 } ; 51 52 } 53 54 #endif 55