R/query_ranges.R

# TileDB Storage Platform API
#
# TileDB Storage Platform REST API
#
# The version of the OpenAPI document: 2.2.19
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title QueryRanges
#'
#' @description QueryRanges Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field layout  \link{Layout} [optional]
#'
#' @field ranges  list( \link{array[numeric]} ) [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
QueryRanges <- R6::R6Class(
  'QueryRanges',
  public = list(
    `layout` = NULL,
    `ranges` = NULL,
    initialize = function(
        `layout`=NULL, `ranges`=NULL, ...
    ) {
      local.optional.var <- list(...)
      if (!is.null(`layout`)) {
        stopifnot(R6::is.R6(`layout`))
        self$`layout` <- `layout`
      }
      if (!is.null(`ranges`)) {
        stopifnot(is.vector(`ranges`), length(`ranges`) != 0)
        # MANUAL EDIT AFTER OPENAPI AUTOGEN
        # See comments just below this for why.
        #sapply(`ranges`, function(x) stopifnot(R6::is.R6(x)))
        self$`ranges` <- `ranges`
      }
    },
    toJSON = function() {
      QueryRangesObject <- list()
      if (!is.null(self$`layout`)) {
        QueryRangesObject[['layout']] <-
          self$`layout`$toJSON()
      }
      if (!is.null(self$`ranges`)) {
        # MANUAL EDIT AFTER OPENAPI AUTOGEN
        #
        # The user/library-level interface is a list of two-column matrices,
        # e.g. 'list(cbind(1,2), cbind(3,4))'. Input to this function is marked
        # as a list of array of numeric.
        #
        # The autogen code generates a check that the list slots must be R6
        # classes; in fact they must *not* be.
        #
        # Here we flatten the list of two-column matrices elementwise to a list
        # of even-length vectors (start end start end start end ...), then
        # serialize them to a language-independent JSON representation like
        # '[[1,2],[3,4]]'. (The same is done in Python by the TileDB-Cloud-Py
        # library.)
        #
        # Context: some items in the TileDB R array UDF API are encoded as
        # R-serialized and shared between the client (us) and the server-side
        # UDF-executor R code, with zero inspection by the REST-server code:
        # e.g. the UDF code itself, and the results. The query-ranges, however,
        # are also decoded and processed by the REST server itself -- hence the
        # particular and careful language-independent handling for query
        # ranges.
        listOfEvenLengthVectors <- lapply(self$ranges, function(e) as.vector(e))
        QueryRangesObject[['ranges']] <- jsonlite::toJSON(listOfEvenLengthVectors, auto_unbox=TRUE)
      }

      QueryRangesObject
    },
    fromJSON = function(QueryRangesJson) {
      QueryRangesObject <- jsonlite::fromJSON(QueryRangesJson)
      if (!is.null(QueryRangesObject$`layout`)) {
        # MANUAL EDIT AFTER OPENAPI AUTOGEN
        # Layout$new does not accept having zero arguments.
        layoutObject <- Layout$new(QueryRangesObject$layout)
        layoutObject$fromJSON(jsonlite::toJSON(QueryRangesObject$layout, auto_unbox = TRUE, digits = NA))
        self$`layout` <- layoutObject
      }
      if (!is.null(QueryRangesObject$`ranges`)) {
        self$`ranges` <- ApiClient$new()$deserializeObj(QueryRangesObject$`ranges`, "array[array[numeric]]", loadNamespace("tiledbcloud"))
      }
      self
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`layout`)) {
        sprintf(
        '"layout":
        %s
        ',
        jsonlite::toJSON(self$`layout`$toJSON(), auto_unbox=TRUE, digits = NA)
        )},
        if (!is.null(self$`ranges`)) {
        sprintf(
        '"ranges":
        %s
',
        jsonlite::toJSON(self$`ranges`)
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(QueryRangesJson) {
      QueryRangesObject <- jsonlite::fromJSON(QueryRangesJson)
      self$`layout` <- Layout$new()$fromJSON(jsonlite::toJSON(QueryRangesObject$layout, auto_unbox = TRUE, digits = NA))
      # MANUAL EDIT AFTER OPENAPI AUTOGEN
      #self$`ranges` <- ApiClient$new()$deserializeObj(QueryRangesObject$`ranges`, "array[array[numeric]]", loadNamespace("tiledbcloud"))
      self$`ranges` <- unserialize(as.raw(fromJSON(QueryRangesObject$`ranges`)))
      self
    }
  )
)
TileDB-Inc/TileDB-Cloud-R documentation built on July 18, 2024, 3:33 p.m.