File: bindrcpp_types.h

package info (click to toggle)
r-cran-bindrcpp 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208 kB
  • sloc: cpp: 141; ansic: 57; sh: 13; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 2,381 bytes parent folder | download | duplicates (3)
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
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _bindrcpp_bindrcpp_types_H_
#define _bindrcpp_bindrcpp_types_H_

#include <RcppCommon.h>

#include <Rcpp.h>

namespace bindrcpp {

struct PAYLOAD { void* p; explicit PAYLOAD(void* p_) : p(p_) {}; };

typedef SEXP (*GETTER_FUNC_STRING_TYPED)(const Rcpp::String& name, bindrcpp::PAYLOAD payload);
typedef SEXP (*GETTER_FUNC_SYMBOL_TYPED)(const Rcpp::Symbol& name, bindrcpp::PAYLOAD payload);
typedef SEXP (*GETTER_FUNC_STRING_WRAPPED)(const Rcpp::String& name, Rcpp::List payload);
typedef SEXP (*GETTER_FUNC_SYMBOL_WRAPPED)(const Rcpp::Symbol& name, Rcpp::List payload);

typedef GETTER_FUNC_SYMBOL_TYPED GETTER_FUNC_SYMBOL;
typedef GETTER_FUNC_STRING_TYPED GETTER_FUNC_STRING;

}

namespace Rcpp {
  using namespace bindrcpp;

  template <> inline SEXP wrap(const PAYLOAD& payload) {
    return List::create(XPtr<PAYLOAD>(new PAYLOAD(payload)));
  }
  template <> inline SEXP wrap(const GETTER_FUNC_STRING_TYPED& fun) {
    return List::create(XPtr<GETTER_FUNC_STRING_TYPED>(new GETTER_FUNC_STRING_TYPED(fun)));
  }
  template <> inline SEXP wrap(const GETTER_FUNC_SYMBOL_TYPED& fun) {
    return List::create(XPtr<GETTER_FUNC_SYMBOL_TYPED>(new GETTER_FUNC_SYMBOL_TYPED(fun)));
  }
  template <> inline SEXP wrap(const GETTER_FUNC_STRING_WRAPPED& fun) {
    return List::create(XPtr<GETTER_FUNC_STRING_WRAPPED>(new GETTER_FUNC_STRING_WRAPPED(fun)));
  }
  template <> inline SEXP wrap(const GETTER_FUNC_SYMBOL_WRAPPED& fun) {
    return List::create(XPtr<GETTER_FUNC_SYMBOL_WRAPPED>(new GETTER_FUNC_SYMBOL_WRAPPED(fun)));
  }
  template <> inline PAYLOAD as(SEXP x) {
    List xl = x;
    XPtr<PAYLOAD> xpayload(static_cast<SEXP>(xl[0]));
    return *xpayload.get();
  }
  template <> inline GETTER_FUNC_STRING_TYPED as(SEXP x) {
    List xl = x;
    XPtr<GETTER_FUNC_STRING_TYPED> xfun(static_cast<SEXP>(xl[0]));
    return *xfun.get();
  }
  template <> inline GETTER_FUNC_SYMBOL_TYPED as(SEXP x) {
    List xl = x;
    XPtr<GETTER_FUNC_SYMBOL_TYPED> xfun(static_cast<SEXP>(xl[0]));
    return *xfun.get();
  }
  template <> inline GETTER_FUNC_STRING_WRAPPED as(SEXP x) {
    List xl = x;
    XPtr<GETTER_FUNC_STRING_WRAPPED> xfun(static_cast<SEXP>(xl[0]));
    return *xfun.get();
  }
  template <> inline GETTER_FUNC_SYMBOL_WRAPPED as(SEXP x) {
    List xl = x;
    XPtr<GETTER_FUNC_SYMBOL_WRAPPED> xfun(static_cast<SEXP>(xl[0]));
    return *xfun.get();
  }
}

#endif