comparison BiodbObject.R @ 6:f86fec07f392 draft default tip

planemo upload commit c397cd8a93953798d733fd62653f7098caac30ce
author prog
date Fri, 22 Feb 2019 16:04:22 -0500
parents fb9c0409d85c
children
comparison
equal deleted inserted replaced
5:fb9c0409d85c 6:f86fec07f392
1 ##########################
2 # CLASS DECLARATION {{{1 #
3 ##########################
4
5 BiodbObject <- methods::setRefClass("BiodbObject", fields = list( .observers = "ANY" ))
6
7 ########################
8 # ABSTRACT METHOD {{{1 #
9 ########################
10
11 BiodbObject$methods( .abstract.method = function() {
12
13 class <- class(.self)
14 method <- sys.call(length(sys.calls()) - 1)
15 method <- sub('^[^$]*\\$([^(]*)\\(.*$', '\\1()', method)
16
17 stop(paste("Method", method, "is not implemented in", class, "class."))
18 })
19
20 ######################
21 # ADD OBSERVERS {{{1 #
22 ######################
23
24 BiodbObject$methods( addObservers = function(obs) {
25
26 # Check types of observers
27 if ( ( ! is.list(obs) && ! inherits(obs, "BiodbObserver")) || (is.list(obs) && any( ! vapply(obs, function(o) inherits(o, "BiodbObserver"), FUN.VALUE = TRUE))))
28 stop("Observers must inherit from BiodbObserver class.")
29
30 # Add observers to current list
31 .observers <<- if (is.null(.self$.observers)) c(obs) else c(.self$.observers, obs)
32 })