RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
foo_rcpp_wrapper_definitions.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4  * Foo objects are wrapped into a trivial list. More complicated objects should either
5  * map to a similar native R type or possibly create their own S4 definitions.
6  */
7 
8 namespace Rcpp {
9  // Foo
10  template<> SEXP wrap(const Foo &foo) {
11  Rcpp::List list;
12 
13  list["name"] = foo.name;
14  list["a"] = foo.a;
15  list["b"] = foo.b;
16 
17  return Rcpp::wrap(list);
18  }
19  template<> Foo as(SEXP sexp) {
20  Rcpp::List list = Rcpp::as<Rcpp::List>(sexp);
21 
22  return Foo(
23  Rcpp::as<std::string>(list["name"]),
24  Rcpp::as<int>(list["a"]),
25  Rcpp::as<int>(list["b"])
26  );
27  }
28 }
29 
Definition: foo.h:17
std::string name
Definition: foo.h:22
SEXP wrap(const Bar &bar)
int32_t a
Definition: foo.h:23
int32_t b
Definition: foo.h:23
Bar as(SEXP sexp)