File: RspDirective%2CIF-THEN-ELSE.R

package info (click to toggle)
r-cran-r.rsp 0.46.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,472 kB
  • sloc: javascript: 612; tcl: 304; sh: 18; makefile: 16
file content (95 lines) | stat: -rw-r--r-- 2,841 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
###########################################################################/**
# @RdocClass RspIfDirective
# @alias RspElseDirective
# @alias RspEndifDirective
# @alias RspIfdefDirective
# @alias RspIfndefDirective
# @alias RspIfeqDirective
# @alias RspIfneqDirective
#
# @title "The RspIfDirective class"
#
# \description{
#  @classhierarchy
#
#  An RspIfDirective is an @see "RspDirective" that will include or
#  exclude all @see "RspConstruct":s until the next @see "RspEndifDirective"
#  based on the preprocessing value of the particular if clause.
#  Inclusion/exclusion can be reversed via an @see "RspElseDirective".
# }
#
# @synopsis
#
# \arguments{
#   \item{value}{A @character string.}
#   \item{...}{Arguments passed to the constructor of @see "RspDirective".}
# }
#
# \section{Fields and Methods}{
#  @allmethods
# }
#
# @author
#
# @keyword internal
#*/###########################################################################
setConstructorS3("RspIfDirective", function(value="if", ...) {
  this <- extend(RspDirective(value, ...), "RspIfDirective")
  if (!missing(value)) {
    requireAttributes(this, c("test"))

    # Test aliases
    test <- getAttribute(this, "test")
    map <- c(
      "==" = "equal-to",
      "!=" = "not-equal-to",
      ">"  = "greater-than",
      ">=" = "greater-than-or-equal-to",
      "<"  = "less-than",
      "<=" = "less-than-or-equal-to"
    )
    testA <- map[test]
    if (!is.na(testA)) {
      this <- setAttribute(this, "test", testA)
    }
  }
  this
})

setConstructorS3("RspElseDirective", function(value="else", ...) {
  extend(RspDirective(value, ...), "RspElseDirective")
})

setConstructorS3("RspEndifDirective", function(value="endif", ...) {
  extend(RspDirective(value, ...), "RspEndifDirective")
})


# Alias: <%@ifeq ...%> => <%@if test="equals" ...%>
setConstructorS3("RspIfeqDirective", function(value="if", ...) {
  extend(RspIfDirective(value, test="equal-to", ...), "RspIfeqDirective")
})

# Alias: <%@ifneq ...%> => <%@if test="equals" negate="TRUE", ...%>
setConstructorS3("RspIfneqDirective", function(value="if", ...) {
  this <- extend(RspIfeqDirective(value, ...), "RspIfneqDirective")
  # Negate the 'test' result
  negate <- !getAttribute(this, "negate", FALSE)
  this <- setAttribute(this, "negate", negate)
  this
})


# Alias: <%@ifdef ...%> => <%@if test="exists" ...%>
setConstructorS3("RspIfdefDirective", function(value="if", ...) {
  extend(RspIfDirective(value, test="exists", ...), "RspIfeqDirective")
})

# Alias: <%@ifndef ...%> => <%@if test="exists" negate="TRUE", ...%>
setConstructorS3("RspIfndefDirective", function(value="if", ...) {
  this <- extend(RspIfdefDirective(value, ...), "RspIfneqDirective")
  # Negate the 'test' result
  negate <- !getAttribute(this, "negate", FALSE)
  this <- setAttribute(this, "negate", negate)
  this
})