[Rcpp-devel] Exporting C++ enums to R
Sameer D'Costa
sameerdcosta at gmail.com
Mon Aug 5 22:40:02 CEST 2013
Hi,
I have an enum defined in a C++ library that I would like to export to R. I
saw some references to enums in pkg/Rcpp/inst/include/Rcpp/module/Module.h
but I could not find any examples of enums being used. Through trial and
error I figured out that I could create a dummy class and add the enum to
that (see code below). Can I export the enum directly? I saw references
to RCPP_EXPOSED_ENUM but I could not figure out how to use that macro. Any
help or pointers to examples where enums are used would be appreciated.
Regards,
Sameer
#include "Rcpp.h"
using namespace Rcpp;
class Dummy {
int x;
int get_x() {return x;}
};
enum MyEnum {ENUM0, ENUM1, ENUM2};
RCPP_MODULE(EnumMod) {
class_<Dummy>("EnumMod")
.default_constructor()
;
enum_<MyEnum, Dummy>("EnumType")
.value("Enum0", ENUM0)
.value("Enum1", ENUM1)
.value("Enum2", ENUM2)
;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130805/5f7b756f/attachment.html>
More information about the Rcpp-devel
mailing list