|
| 1 | +# |
| 2 | +# Copyright (c) TileDB Inc. under the MIT License |
| 3 | +# |
| 4 | + |
| 5 | +#' An S4 class for a TileDB Profile object |
| 6 | +#' |
| 7 | +#' @slot ptr An external pointer to the underlying implementation |
| 8 | +#' @exportClass tiledb_profile |
| 9 | +setClass("tiledb_profile", |
| 10 | + slots = list(ptr = "externalptr") |
| 11 | +) |
| 12 | + |
| 13 | +#' Raw display of a profile object |
| 14 | +#' |
| 15 | +#' This method uses the display method provided by the underlying library. |
| 16 | +#' |
| 17 | +#' @param object A profile object |
| 18 | +#' @export |
| 19 | +setMethod( |
| 20 | + "raw_dump", |
| 21 | + signature(object = "tiledb_profile"), |
| 22 | + definition = function(object) libtiledb_profile_dump(object@ptr) |
| 23 | +) |
| 24 | + |
| 25 | +#' Create a 'tiledb_profile' object |
| 26 | +#' |
| 27 | +#' @param name (optional) Name for the profile |
| 28 | +#' @param dir (optional) Directory to create the profile in |
| 29 | +#' @return A new 'tiledb_profile' object |
| 30 | +#' @export |
| 31 | +tiledb_profile <- function(name = NULL, dir = NULL) { |
| 32 | + stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) |
| 33 | + stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) |
| 34 | + ptr <- libtiledb_profile_new(name, dir) |
| 35 | + profile <- new("tiledb_profile", ptr = ptr) |
| 36 | + return(profile) |
| 37 | +} |
| 38 | + |
| 39 | +#' Load a saved 'tiledb_profile' object |
| 40 | +#' |
| 41 | +#' @param name (optional) Name of the profile to load |
| 42 | +#' @param dir (optional) Directory where the profile to load is saved |
| 43 | +#' @return The loaded 'tiledb_profile' object |
| 44 | +#' @export |
| 45 | +tiledb_profile_load <- function(name = NULL, dir = NULL) { |
| 46 | + stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) |
| 47 | + stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) |
| 48 | + ptr <- libtiledb_profile_load(name, dir) |
| 49 | + profile <- new("tiledb_profile", ptr = ptr) |
| 50 | + return(profile) |
| 51 | +} |
| 52 | + |
| 53 | +#' Remove a saved 'tiledb_profile' |
| 54 | +#' |
| 55 | +#' @param name (optional) Name of the profile to remove |
| 56 | +#' @param dir (optional) Directory where the profile to remove is saved |
| 57 | +#' @export |
| 58 | +tiledb_profile_remove <- function(name = NULL, dir = NULL) { |
| 59 | + stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) |
| 60 | + stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) |
| 61 | + libtiledb_profile_remove(name, dir) |
| 62 | + return(invisible(NULL)) |
| 63 | +} |
| 64 | + |
| 65 | +#' Get the name of a 'tiledb_profile' object |
| 66 | +#' |
| 67 | +#' @param profile A TileDB profile object |
| 68 | +#' @return The name of the 'tiledb_profile' object |
| 69 | +#' @export |
| 70 | +tiledb_profile_name <- function(profile) { |
| 71 | + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) |
| 72 | + name <- libtiledb_profile_name(profile@ptr) |
| 73 | + return(name) |
| 74 | +} |
| 75 | + |
| 76 | +#' Get the directory of a 'tiledb_profile' object |
| 77 | +#' |
| 78 | +#' @param profile A TileDB profile object |
| 79 | +#' @return The directory of the 'tiledb_profile' object |
| 80 | +#' @export |
| 81 | +tiledb_profile_dir <- function(profile) { |
| 82 | + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) |
| 83 | + dir <- libtiledb_profile_dir(profile@ptr) |
| 84 | + return(dir) |
| 85 | +} |
| 86 | + |
| 87 | +#' Set a parameter on the 'tiledb_profile' object |
| 88 | +#' |
| 89 | +#' @param profile A TileDB profile object |
| 90 | +#' @param param The key for the new parameter |
| 91 | +#' @param value The value for the new parameter |
| 92 | +#' @export |
| 93 | +tiledb_profile_set_param <- function(profile, param, value) { |
| 94 | + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) |
| 95 | + stopifnot(`The 'param' arugment must have character type` = is.character(param)) |
| 96 | + stopifnot(`The 'value' arugment must have character type` = is.character(value)) |
| 97 | + libtiledb_profile_set_param(profile@ptr, param, value) |
| 98 | + return(invisible(NULL)) |
| 99 | +} |
| 100 | + |
| 101 | +#' Get the value of a parameter set on the 'tiledb_profile' object |
| 102 | +#' |
| 103 | +#' @param profile A TileDB profile object |
| 104 | +#' @param param The key for the parameter to fetch |
| 105 | +#' @return The value of the requested parameter or NULL if no such parameter exists |
| 106 | +#' @export |
| 107 | +tiledb_profile_get_param <- function(profile, param) { |
| 108 | + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) |
| 109 | + stopifnot(`The 'param' arugment must have character type` = is.character(param)) |
| 110 | + value <- libtiledb_profile_get_param(profile@ptr, param) |
| 111 | + return(value) |
| 112 | +} |
| 113 | + |
| 114 | +#' Save the 'tiledb_profile' object |
| 115 | +#' |
| 116 | +#' This will save the 'tiledb_profile' with the name and directory set at creation. |
| 117 | +#' |
| 118 | +#' @param profile The 'tiledb_profile' object to save |
| 119 | +#' @export |
| 120 | +tiledb_profile_save <- function(profile) { |
| 121 | + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) |
| 122 | + libtiledb_profile_save(profile@ptr) |
| 123 | + return(invisible(NULL)) |
| 124 | +} |
0 commit comments