In the C++ source file below, in function glfw_get_monitors
how to set the class attribute of each element of the object monitor_ptrs
?
The line monitor_ptrs[i].attr("class") = "GLFWmonitor";
throws a compilation error:
‘Rcpp::Vector<19>::Proxy’ {aka ‘class Rcpp::internal::generic_proxy<19>’} has no member named ‘attr’
glfw_types.h
#ifndef RCPP_GLFW_TYPES_H
#define RCPP_GLFW_TYPES_H
#include <Rcpp.h>
#include <GLFW/glfw3.h>
void glfw_destroy_monitor(GLFWmonitor*);
// https://stackoverflow.com/questions/41210595/s4-object-with-a-pointer-to-a-c-struct
typedef Rcpp::XPtr<GLFWwindow, Rcpp::PreserveStorage, glfwDestroyWindow> GLFWwindow_ptr;
typedef Rcpp::XPtr<GLFWmonitor, Rcpp::PreserveStorage, glfw_destroy_monitor> GLFWmonitor_ptr;
#endif
C++ source file
#include "glfw_types.h"
using namespace Rcpp;
// [[Rcpp::export]]
GLFWmonitor_ptr glfw_get_primary_monitor() {
GLFWmonitor_ptr new_monitor = GLFWmonitor_ptr(glfwGetPrimaryMonitor(), true);
new_monitor.attr("class") = "GLFWmonitor";
return new_monitor;
}
// [[Rcpp::export]]
Rcpp::List glfw_get_monitors() {
int nr_monitors;
GLFWmonitor** monitors = glfwGetMonitors(&nr_monitors);
Rcpp::List monitor_ptrs(nr_monitors);
for(int i = 0; i < nr_monitors; i++) {
monitor_ptrs[i] = GLFWmonitor_ptr((GLFWmonitor*)monitors[i], true);
monitor_ptrs[i].attr("class") = "GLFWmonitor";
}
return monitor_ptrs;
}