|
| 1 | +# Generated by savvy: do not edit by hand |
| 2 | +# |
| 3 | +# Note: |
| 4 | +# This wrapper file is named as `000-wrappers.R` so that this file is loaded |
| 5 | +# first, which allows users to override the functions defined here (e.g., a |
| 6 | +# print() method for an enum). |
| 7 | + |
| 8 | +#' @useDynLib multiverse, .registration = TRUE |
| 9 | +#' @keywords internal |
| 10 | +NULL |
| 11 | + |
| 12 | +# Check class and extract the external pointer embedded in the environment |
| 13 | +.savvy_extract_ptr <- function(e, class) { |
| 14 | + if(is.null(e)) { |
| 15 | + return(NULL) |
| 16 | + } |
| 17 | + |
| 18 | + if(inherits(e, class)) { |
| 19 | + e$.ptr |
| 20 | + } else { |
| 21 | + msg <- paste0("Expected ", class, ", got ", class(e)[1]) |
| 22 | + stop(msg, call. = FALSE) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +# Prohibit modifying environments |
| 27 | + |
| 28 | +#' @export |
| 29 | +`$<-.savvy_multiverse__sealed` <- function(x, name, value) { |
| 30 | + class <- gsub("__bundle$", "", class(x)[1]) |
| 31 | + stop(class, " cannot be modified", call. = FALSE) |
| 32 | +} |
| 33 | + |
| 34 | +#' @export |
| 35 | +`[[<-.savvy_multiverse__sealed` <- function(x, i, value) { |
| 36 | + class <- gsub("__bundle$", "", class(x)[1]) |
| 37 | + stop(class, " cannot be modified", call. = FALSE) |
| 38 | +} |
| 39 | + |
| 40 | +#' Convert Input To Upper-Case |
| 41 | +#' |
| 42 | +#' @param x A character vector. |
| 43 | +#' @returns A character vector with upper case version of the input. |
| 44 | +#' @export |
| 45 | +`to_upper` <- function(`x`) { |
| 46 | + .Call(savvy_to_upper__impl, `x`) |
| 47 | +} |
| 48 | + |
| 49 | +#' Multiply Input By Another Input |
| 50 | +#' |
| 51 | +#' @param x An integer vector. |
| 52 | +#' @param y An integer to multiply. |
| 53 | +#' @returns An integer vector with values multiplied by `y`. |
| 54 | +#' @export |
| 55 | +`int_times_int` <- function(`x`, `y`) { |
| 56 | + .Call(savvy_int_times_int__impl, `x`, `y`) |
| 57 | +} |
| 58 | + |
| 59 | +### wrapper functions for Person |
| 60 | + |
| 61 | +`Person_set_name` <- function(self) { |
| 62 | + function(`name`) { |
| 63 | + invisible(.Call(savvy_Person_set_name__impl, `self`, `name`)) |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +`Person_name` <- function(self) { |
| 68 | + function() { |
| 69 | + .Call(savvy_Person_name__impl, `self`) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +`.savvy_wrap_Person` <- function(ptr) { |
| 74 | + e <- new.env(parent = emptyenv()) |
| 75 | + e$.ptr <- ptr |
| 76 | + e$`set_name` <- `Person_set_name`(ptr) |
| 77 | + e$`name` <- `Person_name`(ptr) |
| 78 | + |
| 79 | + class(e) <- c("Person", "savvy_multiverse__sealed") |
| 80 | + e |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +`Person` <- new.env(parent = emptyenv()) |
| 86 | + |
| 87 | +### associated functions for Person |
| 88 | + |
| 89 | +`Person`$`new` <- function() { |
| 90 | + .savvy_wrap_Person(.Call(savvy_Person_new__impl)) |
| 91 | +} |
| 92 | + |
| 93 | +`Person`$`associated_function` <- function() { |
| 94 | + .Call(savvy_Person_associated_function__impl) |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | +class(`Person`) <- c("Person__bundle", "savvy_multiverse__sealed") |
| 99 | + |
| 100 | +#' @export |
| 101 | +`print.Person__bundle` <- function(x, ...) { |
| 102 | + cat('Person') |
| 103 | +} |
| 104 | + |
0 commit comments