| 60325 |
ripley |
1 |
% File src/library/methods/man/stdRefClass.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
|
|
3 |
% Copyright 2010-2 R Core Team
|
|
|
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 52903 |
jmc |
6 |
\name{envRefClass-class}
|
| 52816 |
jmc |
7 |
\Rdversion{1.1}
|
|
|
8 |
\docType{class}
|
| 56186 |
murdoch |
9 |
\alias{envRefClass-class}
|
| 52903 |
jmc |
10 |
\alias{$,envRefClass-method}
|
|
|
11 |
\alias{$<-,envRefClass-method}
|
|
|
12 |
\alias{initialize,envRefClass-method}
|
| 52816 |
jmc |
13 |
|
| 52903 |
jmc |
14 |
\title{Class \code{"envRefClass"}}
|
| 52816 |
jmc |
15 |
\description{
|
|
|
16 |
Support Class to Implement R Objects using Reference Semantics
|
|
|
17 |
}
|
|
|
18 |
\section{NOTE:}{
|
|
|
19 |
The software described here is an initial version. The eventual goal
|
|
|
20 |
is to support reference-style classes with software in \R itself
|
|
|
21 |
or using inter-system interfaces. The current implementation (\R
|
|
|
22 |
version 2.12.0) is preliminary and subject to change, and currently
|
|
|
23 |
includes only the \R-only implementation. Developers are encouraged
|
|
|
24 |
to experiment with the software, but the description here is more than
|
|
|
25 |
usually subject to change.
|
|
|
26 |
}
|
|
|
27 |
\section{Purpose of the Class}{
|
|
|
28 |
This class implements basic reference-style semantics for \R{}
|
|
|
29 |
objects. Objects normally do not come directly from this class, but
|
|
|
30 |
from subclasses defined by a call to \code{\link{setRefClass}}.
|
|
|
31 |
The documentation below is technical background describing the implementation, but applications
|
|
|
32 |
should use the interface documented under \code{\link{setRefClass}},
|
|
|
33 |
in particular the \code{\$} operator and field accessor functions as
|
|
|
34 |
described there.
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
\section{A Basic Reference Class}{
|
|
|
38 |
The design of reference classes for \R{} divides those classes up
|
|
|
39 |
according to the mechanism used for implementing references, fields,
|
|
|
40 |
and class methods.
|
|
|
41 |
Each version of this mechanism is defined by a \emph{basic reference
|
|
|
42 |
class}, which must implement a set of methods and provide some
|
|
|
43 |
further information used by \code{\link{setRefClass}}.
|
|
|
44 |
|
|
|
45 |
The required methods are for operators \code{\$} and \code{\$<-} to
|
|
|
46 |
get and set a field in an object, and for \code{\link{initialize}} to
|
|
|
47 |
initialize objects.
|
|
|
48 |
|
|
|
49 |
To support these methods, the basic reference class needs to have some
|
|
|
50 |
implementation mechanism to store and retrieve data from fields in the
|
|
|
51 |
object.
|
|
|
52 |
The mechanism needs to be consistent with reference semantics; that
|
|
|
53 |
is, changes made to the contents of an object are global, seen by any
|
|
|
54 |
code accessing that object, rather than only local to the function
|
|
|
55 |
call where the change takes place.
|
| 52903 |
jmc |
56 |
As described below, class \code{envRefClass} implements reference
|
| 52816 |
jmc |
57 |
semantics through specialized use of \linkS4class{environment}
|
|
|
58 |
objects.
|
|
|
59 |
Other basic reference classes may use an interface to a language such
|
|
|
60 |
as Java or C++ using reference semantics for classes.
|
|
|
61 |
|
|
|
62 |
Usually, the \R user will be able to invoke class methods on the
|
|
|
63 |
class, using the \code{\$} operator. The basic reference class
|
|
|
64 |
method for \code{\$} needs to make this possible. Essentially, the
|
|
|
65 |
operator must return an \R function corresponding to the object and
|
|
|
66 |
the class method name.
|
|
|
67 |
|
|
|
68 |
Class methods may include an implementation of data abstraction, in
|
|
|
69 |
the sense that fields are accessed by \dQuote{get} and \dQuote{set}
|
|
|
70 |
methods. The basic reference class provides this facility by setting
|
|
|
71 |
the \code{"fieldAccessorGenerator"} slot in its definition to a
|
|
|
72 |
function of one variable.
|
|
|
73 |
This function will be called by \code{\link{setRefClass}} with the
|
|
|
74 |
vector of field names as arguments.
|
|
|
75 |
The generator function must return a list of defined accessor
|
|
|
76 |
functions.
|
|
|
77 |
An element corresponding to a get operation is invoked with no
|
|
|
78 |
arguments and should extract the corresponding field; an element for a
|
|
|
79 |
set operation will be invoked with a single argument, the value to be
|
|
|
80 |
assigned to the field.
|
|
|
81 |
The implementation needs to supply the object, since that is not an
|
|
|
82 |
argument in the method invocation.
|
| 52903 |
jmc |
83 |
The mechanism used currently by \code{envRefClass} is described below.
|
| 52816 |
jmc |
84 |
}
|
|
|
85 |
\section{Support Classes}{
|
|
|
86 |
Two virtual classes are supplied to test for reference objects:
|
|
|
87 |
\code{is(x, "refClass")} tests whether \code{x} comes from a class
|
|
|
88 |
defined using the reference class mechanism described here;
|
|
|
89 |
\code{is(x, "refObject")} tests whether the object has reference
|
|
|
90 |
semantics generally, including the previous classes and also classes
|
|
|
91 |
inheriting from the \R types with reference semantics, such as
|
|
|
92 |
\code{"environment"}.
|
|
|
93 |
|
|
|
94 |
Installed class methods are \code{"classMethodDefinition"} objects,
|
|
|
95 |
with slots that identify the name of the function as a class method
|
|
|
96 |
and the other class methods called from this method.
|
|
|
97 |
The latter information is determined heuristically when the class is
|
|
|
98 |
defined by using the \code{codetools} recommended package. This
|
|
|
99 |
package must be installed when reference classes are defined, but is
|
|
|
100 |
not needed in order to use existing reference classes.
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
\author{
|
|
|
104 |
John Chambers
|
|
|
105 |
}
|
|
|
106 |
\keyword{classes}
|