OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [doc/] [itcl_class.n] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: $Id: itcl_class.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
8
'\"
9
.so man.macros
10
.TH itcl_class n 3.0 itcl "[incr\ Tcl]"
11
.BS
12
'\" Note:  do not modify the .SH NAME line immediately below!
13
.SH NAME
14
itcl_class \- create a class of objects (obsolete)
15
.SH SYNOPSIS
16
\fBitcl_class \fIclassName\fR \fB{
17
.br
18
    \fBinherit \fIbaseClass\fR ?\fIbaseClass\fR...?
19
.br
20
    \fBconstructor \fIargs\fR ?\fIinit\fR? \fIbody\fR
21
.br
22
    \fBdestructor \fIbody\fR
23
.br
24
    \fBmethod \fIname args body\fR
25
.br
26
    \fBproc \fIname args body\fR
27
.br
28
    \fBpublic \fIvarName\fR ?\fIinit\fR? ?\fIconfig\fR?
29
.br
30
    \fBprotected \fIvarName\fR ?\fIinit\fR?
31
.br
32
    \fBcommon \fIvarName\fR ?\fIinit\fR?
33
.br
34
\fB}\fR
35
.sp
36
\fIclassName objName\fR ?\fIargs...\fR?
37
.br
38
\fIclassName\fR \fB#auto\fR ?\fIargs...\fR?
39
.br
40
\fIclassName\fR \fB::\fR \fIproc\fR ?\fIargs...\fR?
41
.sp
42
\fIobjName method\fR ?\fIargs...\fR?
43
.sp
44
\fICommands available within class methods/procs:\fR
45
.br
46
\fBglobal \fIvarName\fR ?\fIvarName...\fR?
47
.br
48
\fBprevious \fIcommand\fR ?\fIargs...\fR?
49
.br
50
\fBvirtual \fIcommand\fR ?\fIargs...\fR?
51
.BE
52
 
53
.SH DESCRIPTION
54
.PP
55
This command is considered obsolete, but is retained for
56
backward-compatibility with earlier versions of \fB[incr\ Tcl]\fR.
57
It has been replaced by the \fBclass\fR command, which should
58
be used for any new development.
59
 
60
.TP
61
\fBitcl_class \fIclassName definition\fR
62
Provides the definition for a class named \fIclassName\fR.  If
63
\fIclassName\fR is already defined, then this command returns
64
an error.  If the class definition is successfully parsed,
65
\fIclassName\fR becomes a command in the current namespace
66
context, handling the
67
creation of objects and providing access to class scope.
68
The class \fIdefinition\fR
69
is evaluated as a series of Tcl statements that define
70
elements within the class.  In addition to the usual
71
commands, the following class definition commands are recognized:
72
.RS
73
.TP
74
\fBinherit \fIbaseClass\fR ?\fIbaseClass\fR...?
75
Declares one or more base classes, causing the current class to
76
inherit their characteristics.  Classes must have been defined by
77
a previous \fBitcl_class\fR command, or must be available to the
78
auto-loading facility (see "AUTO-LOADING" below).  A single class
79
definition can contain no more than one \fBinherit\fR command.
80
.RS
81
.LP
82
When the same member name appears in two or more base classes,
83
the base class that appears first in the \fBinherit\fR list takes
84
precedence.  For example, if classes "Foo" and "Bar" both contain
85
the member "x", then the "\fBinherit\fR" statement:
86
.CS
87
inherit Foo Bar
88
.CE
89
allows "Foo::x" to be accessed simply as "x" but forces "Bar::x" (and
90
all other inherited members named "x") to be referenced with their
91
explicit "\fIclass\fR::\fImember\fR" name.
92
.RE
93
.TP
94
\fBconstructor \fIargs\fR ?\fIinit\fR? \fIbody\fR
95
Declares the argument list and body used for the constructor, which
96
is automatically invoked whenever an object is created.  Before
97
.VS
98
the \fIbody\fR is executed, the optional \fIinit\fR statement is
99
used to invoke any base class constructors that require arguments.
100
Variables in the \fIargs\fR specification can be accessed in the
101
\fIinit\fR code fragment, and passed to base class constructors.
102
After evaluating the \fIinit\fR statement, any base class
103
constructors that have not been executed are invoked without
104
arguments.  This ensures that all base classes are fully
105
constructed before the constructor \fIbody\fR is executed.
106
.VE
107
If construction is successful, the constructor always returns
108
the object name\-regardless of how the \fIbody\fR is defined\-and
109
the object name becomes a command in the current namespace context.
110
If construction fails, an error message is returned.
111
.TP
112
\fBdestructor \fIbody\fR
113
Declares the body used for the destructor, which is automatically invoked
114
whenever an object is deleted.  If the destructor is successful, the object
115
data is destroyed and the object name is removed as a command from the
116
interpreter.  If destruction fails, an error message is returned
117
and the object remains.
118
.RS
119
.LP
120
.VS
121
When an object is destroyed, all destructors in a class hierarchy
122
are invoked in order from most- to least-specific.  This is the
123
order that the classes are reported by the "\fBinfo heritage\fR"
124
command, and it is exactly the opposite of the default constructor
125
order.
126
.VE
127
.RE
128
.TP
129
\fBmethod \fIname args body\fR
130
Declares a method called \fIname\fR with an argument list \fIargs\fR
131
and a \fIbody\fR of Tcl statements.  A method is just like the usual
132
Tcl "proc" except that it has transparent access to
133
.VS
134
object-specific variables, as well as
135
.VE
136
common variables.  Within the class scope, a method can be invoked
137
like any other command\-simply by using its name.  Outside of the
138
class scope, the method name must be prefaced by an object
139
name.  Methods in a base class that are redefined in the current class
140
or hidden by another base class can be explicitly scoped using the
141
"\fIclass\fR::\fImethod\fR" syntax.
142
.TP
143
\fBproc \fIname args body\fR
144
Declares a proc called \fIname\fR with an argument list \fIargs\fR
145
and a \fIbody\fR of Tcl statements.  A proc is similar to a method,
146
except that it can be invoked without referring to a specific object,
147
and therefore has access only to common variables\-not
148
.VS
149
to object-specific variables declared with the \fBpublic\fR
150
and \fBprotected\fR commands.
151
.VE
152
Within the class scope, a proc can be invoked
153
like any other command\-simply by using its name.  In any other
154
namespace context, the proc is invoked using a qualified name
155
like "\fIclassName\fB::\fIproc\fR".
156
Procs in a base class that are redefined in the current
157
class, or hidden by another base class, can also be accessed
158
via their qualified name.
159
.TP
160
\fBpublic \fIvarName\fR ?\fIinit\fR? ?\fIconfig\fR?
161
Declares a public variable named \fIvarName\fR.  Public variables are
162
visible in methods within the scope of their class and any derived class.
163
In addition, they can be modified outside of the class scope using the special
164
"config" formal argument (see "ARGUMENT LISTS" above).  If the optional
165
\fIinit\fR is specified, it is used as the initial value of the variable
166
when a new object is created.  If the optional \fIconfig\fR command
167
is specified,
168
it is invoked whenever a public variable is modified via the "config"
169
formal argument; if the \fIconfig\fR command returns an error, the
170
public variable is reset to its value before configuration, and the
171
method handling the configuration returns an error.
172
.TP
173
\fBprotected \fIvarName\fR ?\fIinit\fR?
174
Declares a protected variable named \fIvarName\fR.  Protected variables
175
are visible in methods within the scope of their class and any derived class,
176
but cannot
177
be modified outside of the class scope.  If the optional \fIinit\fR
178
is specified, it is used as the initial value of the variable when a new
179
object is created.  Initialization forces the variable to be a simple
180
scalar value; uninitialized variables, on the other hand, can be used
181
as arrays.  All objects have a built-in protected variable named
182
"this" which is initialized to the instance name for the object.
183
.TP
184
\fBcommon \fIvarName\fR ?\fIinit\fR?
185
Declares a common variable named \fIvarName\fR.  Common variables are
186
shared among all objects in a class.  They are visible in methods and
187
procs in the scope of their class and any derived class, but cannot be
188
modified outside of the class scope.
189
If the optional \fIinit\fR is specified, it is used as the
190
initial value of the variable.  Initialization forces the variable to be
191
a simple scalar value; uninitialized variables, on the other hand, can
192
be used as arrays.
193
.RS
194
.LP
195
Once a common variable has been declared, it can be configured using
196
ordinary Tcl code within the class definition.  This facility is
197
particularly useful when the initialization of the variable is
198
non-trivial\-when the variable contains an array of values, for example:
199
.CS
200
itcl_class Foo {
201
     .
202
     .
203
    common boolean
204
    set boolean(true) 1
205
    set boolean(false) 0
206
}
207
.CE
208
.RE
209
.RE
210
 
211
.SH CLASS USAGE
212
.PP
213
When a class definition has been loaded (or made available to the
214
auto-loader), the class name can be used as a command.
215
.TP
216
\fIclassName objName\fR ?\fIargs...\fR?
217
Creates a new object in class \fIclassName\fR with the name \fIobjName\fR.
218
Remaining arguments are passed to the constructor.  If construction is
219
successful, the object name is returned and this name becomes a command
220
in the current namespace context.  Otherwise, an error is returned.
221
.TP
222
\fIclassName\fR #auto ?\fIargs...\fR?
223
Creates a new object in class \fIclassName\fR with an automatically
224
generated name.  Names are of the form \fIclassName\fR,
225
.VS
226
where the \fIclassName\fR part is modified to start with a lowercase
227
letter.  In class "Toaster", for example, the "\fB#auto\fR" specification
228
would produce names toaster0, toaster1, etc.  Remaining arguments are
229
.VE
230
passed to the constructor.  If construction is successful, the object
231
name is returned and this name becomes a command in the current
232
namespace context.  Otherwise, an error is returned.
233
.TP
234
\fIclassName\fR  ::  \fIproc\fR ?\fIargs...\fR?
235
Used outside of the class scope to invoke a class proc named \fIproc\fR.
236
Class procs are like ordinary Tcl procs, except that they are executed
237
in the scope of the class and therefore have transparent
238
access to common data members.
239
.RS
240
.LP
241
.VS
242
Notice that, unlike any other scope qualifier in \fB[incr\ Tcl]\fR, the "::"
243
shown above is surrounded by spaces.  This is unnecessary with the
244
new namespace facility, and is considered obsolete.  The capability
245
is still supported, however, to provide backward-compatibility with
246
earlier versions.
247
.VE
248
.RE
249
 
250
.SH OBJECT USAGE
251
.TP
252
\fIobjName method\fR ?\fIargs...\fR?
253
Invokes a method named \fImethod\fR to operate on the specified object.
254
Remaining arguments are passed to the method.  The method name can
255
be "constructor", "destructor", any method name appearing in the
256
class definition, or any of the following built-in methods.
257
.SH BUILT-IN METHODS
258
.TP
259
\fIobjName\fR \fBisa \fIclassName\fR
260
Returns non-zero if the given \fIclassName\fR can be found in the
261
object's heritage, and zero otherwise.
262
.TP
263
\fIobjName\fR \fBdelete\fR
264
Invokes the destructor associated with an object.
265
If the destructor is successful, data associated with the object is
266
deleted and \fIobjName\fR is removed as a command from the
267
interpreter.  Returns the empty string, regardless of the destructor
268
body.
269
.RS
270
.LP
271
.VS
272
The built-in \fBdelete\fR method has been replaced by the
273
"\fBdelete object\fR" command in the global namespace, and
274
is considered obsolete.  The capability is still supported,
275
however, to provide backward-compatibility with earlier versions.
276
.VE
277
.RE
278
.TP
279
\fIobjName\fR \fBinfo \fIoption\fR ?\fIargs...\fR?
280
Returns information related to the class definition or to
281
a particular object named \fIobjName\fR.
282
The \fIoption\fR parameter includes the following things, as well as
283
the options recognized by the usual Tcl "info" command:
284
.RS
285
.TP
286
\fIobjName\fR \fBinfo class\fR
287
.VS
288
Returns the name of the most-specific class for object \fIobjName\fR.
289
.VE
290
.TP
291
\fIobjName\fR \fBinfo inherit\fR
292
Returns the list of base classes as they were defined in the
293
"\fBinherit\fR" command, or an empty string if this class
294
has no base classes.
295
.TP
296
\fIobjName\fR \fBinfo heritage\fR
297
Returns the current class name and the entire list of base classes in
298
the order that they are traversed for member lookup and object
299
destruction.
300
.TP
301
\fIobjName\fR \fBinfo method\fR ?\fImethodName\fR? ?\fB-args\fR? ?\fB-body\fR?
302
With no arguments, this command returns a list of all class methods.
303
If \fImethodName\fR is specified, it returns information for a specific method.
304
If neither of the optional \fB-args\fR or \fB-body\fR flags is specified,
305
a complete method definition is returned as a list of three elements
306
including the method name, argument list and body.  Otherwise, the
307
requested information is returned without the method name.
308
If the \fImethodName\fR is not recognized, an empty string is returned.
309
.TP
310
\fIobjName\fR \fBinfo proc\fR ?\fIprocName\fR? ?\fB-args\fR? ?\fB-body\fR?
311
With no arguments, this command returns a list of all class procs.
312
If \fIprocName\fR is specified, it returns information for a specific proc.
313
If neither of the optional \fB-args\fR or \fB-body\fR flags is specified,
314
a complete proc definition is returned as a list of three elements
315
including the proc name, argument list and body.  Otherwise, the
316
requested information is returned without the proc name.
317
If the \fIprocName\fR is not recognized, an empty string is returned.
318
.TP
319
\fIobjName\fR \fBinfo public\fR ?\fIvarName\fR? ?\fB-init\fR? ?\fB-value\fR? ?\fB-config\fR?
320
With no arguments, this command returns a list of all public variables.
321
If \fIvarName\fR is specified, it returns information for a specific public
322
variable.
323
If none of the optional \fB-init\fR, \fB-value\fR or \fB-config\fR flags
324
are specified, all available information is returned as a list of four
325
elements including the variable name, initial value, current value,
326
and configuration commands.  Otherwise, the requested information is
327
returned without the variable name.
328
If the \fIvarName\fR is not recognized, an empty string is returned.
329
.TP
330
\fIobjName\fR \fBinfo protected\fR ?\fIvarName\fR? ?\fB-init\fR? ?\fB-value\fR?
331
With no arguments, this command returns a list of all protected variables.
332
If \fIvarName\fR is specified, it returns information for a specific protected
333
variable.
334
If neither of the optional \fB-init\fR or \fB-value\fR flags is specified,
335
all available information is returned as a list of three elements
336
including the variable name, initial value and current value.
337
Otherwise, the requested information is returned without the variable name.
338
If the \fIvarName\fR is not recognized, an empty string is returned.
339
.TP
340
\fIobjName\fR \fBinfo common\fR ?\fIvarName\fR? ?\fB-init\fR? ?\fB-value\fR?
341
With no arguments, this command returns a list of all common variables.
342
If \fIvarName\fR is specified, it returns information for a specific common
343
variable.
344
If neither of the optional \fB-init\fR or \fB-value\fR flags is specified,
345
all available information is returned as a list of three elements
346
including the variable name, initial value and current value.
347
Otherwise, the requested information is returned without the variable name.
348
If the \fIvarName\fR is not recognized, an empty string is returned.
349
.RE
350
.SH OTHER BUILT-IN COMMANDS
351
The following commands are also available within the scope of each class.
352
They cannot be accessed from outside of the class as proper methods or
353
procs; rather, they are useful inside the class when implementing its
354
functionality.
355
.TP
356
\fBglobal \fIvarName\fR ?\fIvarName...\fR?
357
Creates a link to one or more global variables in the current
358
namespace context.  Global variables can also be accessed in
359
other namespaces by including namespace qualifiers in \fIvarName\fR.
360
This is useful when communicating with Tk widgets that rely on global
361
variables.
362
.TP
363
\fBprevious \fIcommand\fR ?\fIargs...\fR?
364
Invokes \fIcommand\fR in the scope of the most immediate base class
365
.VS
366
(i.e., the "previous" class) for the object.  For classes using single
367
.VE
368
inheritance, this facility can be used to avoid hard-wired base class
369
references of the form "\fIclass\fR::\fIcommand\fR", making code easier
370
to maintain.  For classes using multiple inheritance, the utility of
371
this function is dubious.
372
If the class at the relevant scope has no base class, an error is returned.
373
.TP
374
\fBvirtual \fIcommand\fR ?\fIargs...\fR?
375
.VS
376
Invokes \fIcommand\fR in the scope of the most-specific class for the
377
object.  The methods within a class are automatically virtual; whenever
378
an unqualified method name is used, it always refers to the most-specific
379
implementation for that method.  This function provides a way of
380
evaluating code fragments in a base class that have access to the
381
most-specific object information.  It is useful, for example, for
382
creating base classes that can capture and save an object's state.
383
It inverts the usual notions of object-oriented programming, however,
384
and should therefore be used sparingly.
385
.VE
386
 
387
.SH AUTO-LOADING
388
.PP
389
Class definitions need not be loaded explicitly; they can be loaded as
390
needed by the usual Tcl auto-loading facility.  Each directory containing
391
class definition files should have an accompanying "tclIndex" file.
392
Each line in this file identifies a Tcl procedure or \fB[incr\ Tcl]\fR
393
class definition and the file where the definition can be found.
394
.PP
395
For example, suppose a directory contains the definitions for classes
396
"Toaster" and "SmartToaster".  Then the "tclIndex" file for this
397
directory would look like:
398
.CS
399
# Tcl autoload index file, version 2.0 for [incr Tcl]
400
# This file is generated by the "auto_mkindex" command
401
# and sourced to set up indexing information for one or
402
# more commands.  Typically each line is a command that
403
# sets an element in the auto_index array, where the
404
# element name is the name of a command and the value is
405
# a script that loads the command.
406
 
407
set auto_index(::Toaster) "source $dir/Toaster.itcl"
408
set auto_index(::SmartToaster) "source $dir/SmartToaster.itcl"
409
.PP
410
The \fBauto_mkindex\fR command is used to automatically
411
generate "tclIndex" files.
412
.CE
413
The auto-loader must be made aware of this directory by appending
414
the directory name to the "auto_path" variable.  When this is in
415
place, classes will be auto-loaded as needed when used in an
416
application.
417
 
418
.SH KEYWORDS
419
class, object, object-oriented

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.