'\"
'\" Copyright (c) 1990 The Regents of the University of California.
'\" All rights reserved.
'\"
'\" Permission is hereby granted, without written agreement and without
'\" license or royalty fees, to use, copy, modify, and distribute this
'\" documentation for any purpose, provided that the above copyright
'\" notice and the following two paragraphs appear in all copies.
'\"
'\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
'\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
'\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
'\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'\"
'\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
'\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
'\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
'\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
'\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
'\" 
.\" The definitions below are for supplemental macros used in Tcl/Tk
.\" manual entries.
.\"
.\" .HS name section [date [version]]
.\"	Replacement for .TH in other man pages.  See below for valid
.\"	section names.
.\"
.\" .AP type name in/out [indent]
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
.\"	and indent is equivalent to second arg of .IP (shouldn't ever be
.\"	needed;  use .AS below instead)
.\"
.\" .AS [type [name]]
.\"	Give maximum sizes of arguments for setting tab stops.  Type and
.\"	name are examples of largest possible arguments that will be passed
.\"	to .AP later.  If args are omitted, default tab stops are used.
.\"
.\" .BS
.\"	Start box enclosure.  From here until next .BE, everything will be
.\"	enclosed in one large box.
.\"
.\" .BE
.\"	End of box enclosure.
.\"
.\" .VS
.\"	Begin vertical sidebar, for use in marking newly-changed parts
.\"	of man pages.
.\"
.\" .VE
.\"	End of vertical sidebar.
.\"
.\" .DS
.\"	Begin an indented unfilled display.
.\"
.\" .DE
.\"	End of indented unfilled display.
.\"
'\"	# Heading for Tcl/Tk man pages
.de HS
.ds ^3 \\0
.if !"\\$3"" .ds ^3 \\$3
.if '\\$2'cmds'       .TH \\$1 1 \\*(^3 \\$4
.if '\\$2'lib'        .TH \\$1 3 \\*(^3 \\$4
.if '\\$2'tcldp'         .TH \\$1 n \\*(^3 Tcl-DP "Tcl-DP Commands"
.if '\\$2'tcldpc'         .TH \\$1 3 \\*(^3 Tcl-DP "Tcl-DP Library Procedures"
.if '\\$2'tcldpcmds'         .TH \\$1 1 \\*(^3 Tcl-DP "Tcl-DP Applications"
.if '\\$2'tcldpintro'         .TH \\$1 n \\*(^3 Tcl-DP "Introduction to Tcl-DP"
.if t .wh -1.3i ^B
.nr ^l \\n(.l
.ad b
..
'\"	# Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ie !"\\$3"" \{\
.ta \\n()Au \\n()Bu
\&\\$1	\\fI\\$2\\fP	(\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
'\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
'\"	# BS - start boxed text
'\"	# ^y = starting y location
'\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
'\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
'\"	# VS - start vertical sidebar
'\"	# ^Y = starting y location
'\"	# ^v = 1 (for troff;  for nroff this doesn't matter)
.de VS
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
'\"	# VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
'\"	# Special macro to handle page bottom:  finish off current
'\"	# box/sidebar if in box/sidebar mode, then invoked standard
'\"	# page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\"	Draw three-sided box if this is the box's first page,
.\"	draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
'\"	# DS - begin display
.de DS
.RS
.nf
.sp
..
'\"	# DE - end display
.de DE
.fi
.RE
.sp .5
..
.HS dp_object tcldp
.BS
.SH NAME
.LP 
dp_objectCreateProc, dp_objectExists, dp_objectFree, dp_objectConfigure
.dp
dp_objectSlot, dp_objectSlotSet, dp_objectSlotAppend, dp_objectSlots 
.dp
  \- dp_object manipulation using Tcl scripting
.SH SYNOPSIS
\fBdp_objectCreateProc\fR \fIclass\fR \fIobject\fR
.br
\fBdp_objectExists\fR \fIobject\fR
.br
\fBdp_objectSlots\fR \fIobject\fR
.br
\fBdp_objectFree\fR \fIobject\fR
.br
\fBdp_objectSlot\fR \fIobject\fR \fIslot\fR
.br
\fBdp_objectSlotSet\fR \fIobject\fR \fIslot\fR \fIvalue\fR
.br
\fBdp_objectSlotAppend\fR \fIobject\fR \fIslot\fR \fIvalue\fR
.br
\fBdp_objectConfigure\fR \fIclass\fR \fIobject\fR \fIoptions\fR
.BE
.SH DESCRIPTION
.LP

A procedural object is a Tcl procedure that represents an object.
The utility commands described in this man page allow one to
easily implement procedural objects using Tcl scripting only.

A procedural object is usually implemented in C (e.g., as a C
struct) for speed but has a Tcl access interface.  For example,
Tk implements its widget classes in C but provides Tcl interfaces
to access those widgets.  Tk uses a procedure to represent each
widget instance.

The first argument of one of these procedural objects is a method
selector.  In other words, if \fIobject\fR is the name of a
procedural object:

\fIobject\fB \fImethod\fR ?\fIargs ...\fR?

If you use the utility procedures described in this man page to
implement a procedural object, that object will have a class and
may have slots.  The class of the object determines what methods
the object will respond to.  No class inheritance is supported.
.SH COMMANDS 
.TP 
\fBdp_objectCreateProc \fIclass\fR \fIobject\fR

This command creates a new Tcl procedure to represent a new \fIobject\fR.
The new procedure will have the name \fIobject\fR and have the given
\fIclass\fR.
.TP
\fBdp_objectExists \fIobject\fR

This command returns 1 if a procedural object named \fIobject\fR
exists in the interpreter and returns 0 otherwise.
.TP
\fBdp_objectFree \fIobject\fR

This command frees up the resources associated with the
\fIobject\fR, which should have been created with
dp_objectCreateProc.  After using dp_objectFree on an
\fIobject\fR, no more references to that \fIobject\fR or its slots
should be made.
.TP
\fBdp_objectSlots \fIobject\fR

This command returns a list of the slots of the procedural
\fIobject\fR, which should have been created with
dp_objectCreateProc.
.TP
\fBdp_objectSlot \fIobject\fR \fIslot\fR

This command returns the value of a \fIslot\fR of the procedural
\fIobject\fR, which should have been created with
dp_objectCreateProc.
.TP
\fBdp_objectSlotSet \fIobject\fR \fIslot\fR \fIvalue\fR

This command sets the \fIvalue\fR of a \fIslot\fR of the
\fIobject\fR, which should have been created with
dp_objectCreateProc.  If \fIslot\fR is not yet a slot of the
\fIobject\fR, this command will make \fIslot\fR a slot of the
object.  Thus, slots can be dynamically added to objects created
using dp_objectCreateProc.  A \fIslot\fR may not be an array.
.TP
\fBdp_objectSlotAppend \fIobject\fR \fIslot\fR \fIvalue\fR

This command uses lappend to append the given \fIvalue\fR
to the current value of the \fIslot\fR of the \fIobject\fR, which
should have been created with dp_objectCreateProc.  If
\fIslot\fR is not yet a slot of the \fIobject\fR, this command
will make \fIslot\fR a slot of the object.  Thus, slots can be
dynamically added to objects created using
dp_objectCreateProc.
.TP
\fBdp_objectConfigure \fIclass\fR \fIobject\fR ?\fIoptions\fR?

This command provides a Tk "configure" style of slot access for
the procedural \fIobject\fR, which should have been created using
dp_objectCreateProc.  (See example usage below.)  The argument
\fIclass\fR should be the class of the \fIobject\fR.  The
optional \fIoptions\fR argument can be used in the following
three formats:

\fBdp_objectConfigure \fIclass\fR \fIobject\fR ?\fI-slot\fR?
.br
\fBdp_objectConfigure \fIclass\fR \fIobject\fR ?\fI-slot val -slot val ...\fR?
.br
\fBdp_objectConfigure \fIclass\fR \fIobject\fR
.br

The first format of dp_objectConfigure retrieves the
configuration entry for a given \fIslot\fR.  A configuration
entry for a \fIslot\fR is a triplet of the format of \fI{-slot
default value}\fR, where \fI-slot\fR is the slot name prepended
with a hyphen, \fIdefault\fR is the default value for the
\fIslot\fR, and \fIvalue\fR is the current value of the
\fIslot\fR.  (Note that this configuration entry format for slots
is different than the configuration entry format of Tk widget
options.)

The second format of dp_objectConfigure sets the current
values of several \fIslot\fRs of an \fIobject\fR.  

The third format of dp_objectConfigure retrieves the
configuration entries of all the slots of the \fIobject\fR.

Note that to use dp_objectConfigure, you must prepend a hyphen
('-') to each slot name.  (e.g., "slot" becomes "-slot".)  This
was designed for pseudo-compatability with the Tk style of widget
option configuration, since widget options in Tk are all prefixed
with a '-'.  Also, any slot names, \fIslot\fR, should be fully
specified and not abbreviated.
.SH "CLASSES AND METHODS"
.LP

The command dp_objectCreateProc creates a new Tcl procedure whose
name is \fIobject\fR to represent a new procedural object.  
You may invoke various methods on the procedural \fIobject\fR,
using the following general form:
.DS C
\fIobject method \fR?\fIarg0 arg1 ...\fR?
.DE

The \fImethod\fR argument and the \fIclass\fR of the \fIobject\fR
determine the method invoked.
.LP
Methods for classes are specified using the following form:
.DS C
proc \fIclass\fR.\fImethod\fR {\fIself arg0 ... argN\fR} {
   ...method body...
}
.DE

The first argument \fIself\fR is required in the method
specification.  The \fIself\fR argument is set to the name of the
\fIobject\fR that the \fImethod\fR will get called upon.
.SH EXAMPLE
.LP
The following is a simple example of using the above commands to
create a procedural object using Tcl scripting only:
.DS C
# Define point creator.
#
proc makePoint {aPoint args} {
   eval dp_objectCreateProc point $aPoint;
   dp_objectSlotSet $aPoint x 0;
   dp_objectSlotSet $aPoint y 0;
   eval $aPoint configure $args
   return $aPoint;
}

# Define methods of point class.
#
proc point.configure {aPoint args} {
   eval dp_objectConfigure point $aPoint $args;
}

proc point.slot-value {aPoint slot} {
  dp_objectSlot $aPoint $slot;
}

proc point.destroy {aPoint slot} {
  dp_objectFree $aPoint $slot;
}

proc point.draw {aPoint} {
   set x [dp_objectSlot $aPoint x];
   set y [dp_objectSlot $aPoint y];
   dot $x $y;
}

# Instatiate a point and test it out.
#
makePoint p;			# Makes the point
p configure -x 10 -y 20;	# sets the value to (10,20)
p configure -x;			# returns {-x {} 10}
p configure;			# returns {{-x {} 10} {-y {} 20}}
p slot-value x;			# returns 10
p draw;				# calls "dot 10 20"
dp_objectExists p;		# returns 1
dp_objectExists p1;		# returns 0
p destroy;			# destroys the object
.DE
.SH KEYWORDS
object, method, class, slots, associative arrays, configure, options,
prototyping
.SH AUTHOR
Brian Smith (bsmith@cs.berkeley.edu)
.br
Steve Yen (syen@cs.berkeley.edu)
.br
Stephen Tu (tus@roger-rabbit.cs.berkeley.edu)
