File: MediaCache-class.R

package info (click to toggle)
r-cran-restfulr 0.0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: ansic: 67; sh: 13; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
### =========================================================================
### MediaCache objects
### -------------------------------------------------------------------------

### Just environments that only store Media objects

setClass("MediaCache", contains = "environment")

MediaCache <- function() {
  new("MediaCache", new.env(parent = emptyenv()))
}

setMethod("$<-", "MediaCache", function(x, name, value) {
  x[[name]] <- value
  x
})

setMethod("[[<-", "MediaCache", function(x, i, j, ..., value) {
  if (!missing(j))
    warning("argument 'j' is ignored")
  assign(i, value, x)
  x
})

setGeneric("assign",
           function (x, value, pos = -1, envir = as.environment(pos),
                     inherits = FALSE, immediate = TRUE)
           standardGeneric("assign"),
           signature = c("x", "value"))

setMethod("assign", "MediaCache",
          function (x, value, pos = -1, envir = as.environment(pos),
                    inherits = FALSE, immediate = TRUE)
          {
            if (!is(value, "Media"))
              stop("MediaCache only permits Media storage")
            callNextMethod()
          })

purge <- function(x) {
  rm(list=ls(x), envir=x)
  x
}