File: PreserveStorage.h

package info (click to toggle)
rcpp 1.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,364 kB
  • sloc: ansic: 43,980; cpp: 40,120; sh: 53; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef Rcpp_PreserveStorage_h
#define Rcpp_PreserveStorage_h

namespace Rcpp{

    template <typename CLASS>
    class PreserveStorage {
    public:

        PreserveStorage() : data(R_NilValue){}

        ~PreserveStorage(){
            Rcpp_ReleaseObject(data) ;
            data = R_NilValue;
        }

        inline void set__(SEXP x){
            data = Rcpp_ReplaceObject(data, x) ;

            // calls the update method of CLASS
            // this is where to react to changes in the underlying SEXP
            static_cast<CLASS&>(*this).update(data) ;
        }

        inline SEXP get__() const {
            return data ;
        }

        inline SEXP invalidate__(){
            SEXP out = data ;
            data = R_NilValue ;
            return out ;
        }

        template <typename T>
        inline T& copy__(const T& other){
            if( this != &other){
                set__(other.get__());
            }
            return static_cast<T&>(*this) ;
        }

        inline bool inherits(const char* clazz) const {
            return ::Rf_inherits( data, clazz) ;
        }

        inline operator SEXP() const { return data; }

    private:
        SEXP data ;
    } ;

}

#endif