| 5 | |
| 6 | template <typename CLASS> |
| 7 | class NoProtectStorage { |
| 8 | public: |
| 9 | |
| 10 | NoProtectStorage() : data(R_NilValue){} |
| 11 | |
| 12 | ~NoProtectStorage(){ |
| 13 | data = R_NilValue; |
| 14 | } |
| 15 | |
| 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 | |
| 24 | inline SEXP get__() const { |
| 25 | return data ; |
| 26 | } |
| 27 | |
| 28 | inline SEXP invalidate__(){ |
| 29 | data = R_NilValue ; |
| 30 | return data ; |
| 31 | } |
| 32 | |
| 33 | inline CLASS& copy__(const CLASS& other){ |
| 34 | if( this != &other){ |
| 35 | set__(other.get__()); |
| 36 | } |
| 37 | return static_cast<CLASS&>(*this) ; |
| 38 | } |
| 39 | |
| 40 | inline bool inherits(const char* clazz) const { |
| 41 | return ::Rf_inherits( data, clazz) ; |
| 42 | } |
| 43 | |
| 44 | inline operator SEXP() const { |
| 45 | return data; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | SEXP data ; |
| 50 | } ; |
| 51 | |
| 52 | } |
| 53 | |