EnumValue-class: A class to represent a value of an enumerated constant

EnumValue-classR Documentation

A class to represent a value of an enumerated constant

Description

This class is intended to be used to represent a value that originates from an enumerated constant. The idea is that this value carries around the value and the symbolic name. Additionally, if an object of a enumerated type is expected, an integer or character string could be supplied and its value compared to a definition of the enumeration in R.

It is expected that users would create new classes derived from this one for each new enumeration type that is encountered. The definition of the enumerated constant values would be identified from the class name of the new class. See EnumValue.

Objects from the Class

Objects can be created by calls of the form new("EnumValue", ...) or via the function EnumValue with an instance of the appropriate target class specified.

Slots

.Data:

Object of class "integer", giving the value. This must have the associated name which makes it the symbolic constant.

Extends

Class "integer", from data part. Class "vector", by class "integer". Class "numeric", by class "integer".

Methods

show

signature(object = "EnumValue"): this takes care of displaying the value as a regular named integer giving the human-readable form and its value.

Author(s)

Duncan Temple Lang (duncan@r-project.org)

See Also

EnumValue

Examples


   # Define a new Enumeration class. 
 setClass("Color", contains = "EnumValue")
       # Define the enumeration definition table.
 ColorEnum = c(Red = 1, Green = 2, Blue = 3)
 storage.mode(ColorEnum) = "integer"

  # Set the coercion methods to take a number or a string 
  # to this class type.
 setAs("character", "Color",
         function(from)
            EnumValue(from, new("Color")))

 setAs("numeric", "Color",
         function(from)
            EnumValue(from, new("Color")))


   # Now we can use this class.
  as(1, "Color")
  as("Red", "Color")

  as("Blue", "Color")
 
    # These should give errors, so we enclose them in a call to try. 
  try(as("Orange", "Color"))
  try(as(20, "Color"))

omegahat/RDCOMClient documentation built on July 24, 2022, 5:45 a.m.