Tcl Library Source Code

Artifact [c933ef772d]
Login

Artifact c933ef772d6e18228d536dbe9329102e3c2fe696284e0a0aa6dfc2b35d9beb01:



<div class='fossil-doc' data-title='stooop - Simple Tcl Only Object Oriented Programming'>
<style>
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
</style>
 <hr> [
   <a href="../../../../toc.html">Main Table Of Contents</a>
| <a href="../../../toc.html">Table Of Contents</a>
| <a href="../../../../index.html">Keyword Index</a>
| <a href="../../../../toc0.html">Categories</a>
| <a href="../../../../toc1.html">Modules</a>
| <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">stooop(n) 4.4.1 tcllib &quot;Simple Tcl Only Object Oriented Programming&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>stooop - Object oriented extension.</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">DEBUGGING</a></li>
<li class="doctools_section"><a href="#section3">EXAMPLES</a></li>
<li class="doctools_section"><a href="#section4">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.3</b></li>
<li>package require <b class="pkgname">stooop <span class="opt">?4.4.1?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">::stooop::class</b> <i class="arg">name body</i></a></li>
<li><a href="#2"><b class="cmd">::stooop::new</b> <i class="arg">class</i> <span class="opt">?<i class="arg">arg arg ...</i>?</span></a></li>
<li><a href="#3"><b class="cmd">::stooop::delete</b> <i class="arg">object</i> <span class="opt">?<i class="arg">object ...</i>?</span></a></li>
<li><a href="#4"><b class="cmd">::stooop::virtual</b> <b class="const">proc</b> <i class="arg">name</i> {<b class="const">this</b> <span class="opt">?<i class="arg">arg arg ...</i>?</span>} <span class="opt">?<i class="arg">body</i>?</span></a></li>
<li><a href="#5"><b class="cmd">::stooop::classof</b> <i class="arg">object</i></a></li>
<li><a href="#6"><b class="cmd">::stooop::new</b> <i class="arg">object</i></a></li>
<li><a href="#7"><b class="cmd">::stooop::printObjects</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#8"><b class="cmd">::stooop::record</b></a></li>
<li><a href="#9"><b class="cmd">::stooop::report</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This package provides commands to extend Tcl in an object oriented
manner, using a familiar C++ like syntax and behaviour. Stooop only
introduces a few new commands: <b class="cmd"><a href="../../../../index.html#class">class</a></b>, <b class="cmd">new</b>, <b class="cmd">delete</b>,
<b class="cmd">virtual</b> and <b class="cmd">classof</b>. Along with a few coding conventions,
that is basically all you need to know to use stooop. Stooop is meant
to be as simple to use as possible.</p>
<p>This manual is very succinct and is to be used as a quick reminder for
the programmer, who should have read the thorough <a href="stooop_man.html">stooop_man.html</a>
HTML documentation at this point.</p>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">::stooop::class</b> <i class="arg">name body</i></a></dt>
<dd><p>This command creates a class. The body, similar in contents to a Tcl
namespace (which a class actually also is), contains member procedure
definitions. Member procedures can also be defined outside the class
body, by prefixing their name with <b class="const">class::</b>, as you would
proceed with namespace procedures.</p>
<dl class="doctools_definitions">
<dt><b class="cmd"><a href="../../../../index.html#proc">proc</a></b> <i class="arg">class</i> {<b class="const">this</b> <span class="opt">?<i class="arg">arg arg ...</i>?</span>} <span class="opt">?<i class="arg">base</i> {<span class="opt">?<i class="arg">arg arg ...</i>?</span>} ...?</span> <i class="arg">body</i></dt>
<dd><p>This is the constructor procedure for the class. It is invoked
following a <b class="cmd">new</b> invocation on the class. It must have the same
name as the class and a first argument named <b class="const">this</b>. Any number
of base classes specifications, including arguments to be passed to
their constructor, are allowed before the actual body of the
procedure.</p></dd>
<dt><b class="cmd"><a href="../../../../index.html#proc">proc</a></b> ~<i class="arg">class</i> {<b class="const">this</b>} <i class="arg">body</i></dt>
<dd><p>This is the destructor procedure for the class. It is invoked
following a <b class="cmd">delete</b> invocation. Its name must be the
concatenation of a single <b class="const">~</b> character followed by the class
name (as in C++). It must have a single argument named <b class="const">this</b>.</p></dd>
<dt><b class="cmd"><a href="../../../../index.html#proc">proc</a></b> <i class="arg">name</i> {<b class="const">this</b> <span class="opt">?<i class="arg">arg arg ...</i>?</span>} <i class="arg">body</i></dt>
<dd><p>This is a member procedure of the class, as its first argument is
named <b class="const">this</b>. It allows a simple access of member data for the
object referenced by <b class="const">this</b> inside the procedure. For example:</p>
<pre class="doctools_example">
   set ($this,data) 0
</pre>
</dd>
<dt><b class="cmd"><a href="../../../../index.html#proc">proc</a></b> <i class="arg">name</i> {<span class="opt">?<i class="arg">arg arg ...</i>?</span>} <i class="arg">body</i></dt>
<dd><p>This is a static (as in C++) member procedure of the class, as its
first argument is not named <b class="const">this</b>. Static (global) class data
can be accessed as in:</p>
<pre class="doctools_example">
   set (data) 0
</pre>
</dd>
<dt><b class="cmd"><a href="../../../../index.html#proc">proc</a></b> <i class="arg">class</i> {<b class="const">this copy</b>} <i class="arg">body</i></dt>
<dd><p>This is the optional copy procedure for the class. It must have the
same name as the class and exactly 2 arguments named <b class="const">this</b> and
<b class="const">copy</b>. It is invoked following a <b class="cmd">new</b> invocation on an
existing object of the class.</p></dd>
</dl></dd>
<dt><a name="2"><b class="cmd">::stooop::new</b> <i class="arg">class</i> <span class="opt">?<i class="arg">arg arg ...</i>?</span></a></dt>
<dd><p>This command is used to create an object. The first argument is the
class name and is followed by the arguments needed by the
corresponding class constructor. A unique identifier for the object
just created is returned.</p></dd>
<dt><a name="3"><b class="cmd">::stooop::delete</b> <i class="arg">object</i> <span class="opt">?<i class="arg">object ...</i>?</span></a></dt>
<dd><p>This command is used to delete one or several objects. It takes one or
more object identifiers as argument(s).</p></dd>
<dt><a name="4"><b class="cmd">::stooop::virtual</b> <b class="const">proc</b> <i class="arg">name</i> {<b class="const">this</b> <span class="opt">?<i class="arg">arg arg ...</i>?</span>} <span class="opt">?<i class="arg">body</i>?</span></a></dt>
<dd><p>The <b class="cmd">virtual</b> specifier may be used on member procedures to
achieve dynamic binding. A procedure in a base class can then be
redefined (overloaded) in the derived class(es). If the base class
procedure is invoked on an object, it is actually the derived class
procedure which is invoked, if it exists. If the base class procedure
has no body, then it is considered to be a pure virtual and the
derived class procedure is always invoked.</p></dd>
<dt><a name="5"><b class="cmd">::stooop::classof</b> <i class="arg">object</i></a></dt>
<dd><p>This command returns the class of the existing object passed as single
parameter.</p></dd>
<dt><a name="6"><b class="cmd">::stooop::new</b> <i class="arg">object</i></a></dt>
<dd><p>This command is used to create an object by copying an existing
object. The copy constructor of the corresponding class is invoked if
it exists, otherwise a simple copy of the copied object data members
is performed.</p></dd>
</dl>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">DEBUGGING</a></h2>
<dl class="doctools_definitions">
<dt>Environment variables</dt>
<dd><dl class="doctools_definitions">
<dt><b class="variable">STOOOPCHECKDATA</b></dt>
<dd><p>Setting this variable to any true value will cause stooop to check for
invalid member or class data access.</p></dd>
<dt><b class="variable">STOOOPCHECKPROCEDURES</b></dt>
<dd><p>Setting this variable to any true value will cause stooop to check for
invalid member procedure arguments and pure interface classes
instanciation.</p></dd>
<dt><b class="variable">STOOOPCHECKALL</b></dt>
<dd><p>Setting this variable to any true value will cause stooop to activate
both procedure and data member checking.</p></dd>
<dt><b class="variable">STOOOPCHECKOBJECTS</b></dt>
<dd><p>Setting this variable to any true value will cause stooop to activate
object checking. The following stooop namespace procedures then become
available for debugging: <b class="cmd">printObjects</b>, <b class="cmd"><a href="../../../../index.html#record">record</a></b> and
<b class="cmd"><a href="../report/report.html">report</a></b>.</p></dd>
<dt><b class="variable">STOOOPTRACEPROCEDURES</b></dt>
<dd><p>Setting this environment variable to either <b class="const">stdout</b>,
<b class="const">stderr</b> or a file name, activates procedure tracing. The
stooop library will then output to the specified channel 1 line of
informational text for each member procedure invocation.</p></dd>
<dt><b class="variable">STOOOPTRACEPROCEDURESFORMAT</b></dt>
<dd><p>Defines the trace procedures output format. Defaults to
<b class="const">&quot;class: %C, procedure: %p, object: %O, arguments: %a&quot;</b>.</p></dd>
<dt><b class="variable">STOOOPTRACEDATA</b></dt>
<dd><p>Setting this environment variable to either <b class="const">stdout</b>,
<b class="const">stderr</b> or a file name, activates data tracing. The stooop
library will then output to the specified channel 1 line of
informational text for each member data access.</p></dd>
<dt><b class="variable">STOOOPTRACEDATAFORMAT</b></dt>
<dd><p>Defines the trace data output format. Defaults to
<b class="const">&quot;class: %C, procedure: %p, array: %A, object: %O, member: %m, operation: %o, value: %v&quot;</b>.</p></dd>
<dt><b class="variable">STOOOPTRACEDATAOPERATIONS</b></dt>
<dd><p>When tracing data output, by default, all read, write and unsetting
accesses are reported, but the user can set this variable to any
combination of the letters <b class="const">r</b>, <b class="const">w</b>, and <b class="const">u</b> for
more specific tracing (please refer to the <b class="cmd"><a href="../../../../index.html#trace">trace</a></b> Tcl manual page
for more information).</p></dd>
<dt><b class="variable">STOOOPTRACEALL</b></dt>
<dd><p>Setting this environment variable to either <b class="const">stdout</b>,
<b class="const">stderr</b> or a file name, enables both procedure and data
tracing.</p></dd>
</dl></dd>
<dt><a name="7"><b class="cmd">::stooop::printObjects</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Prints an ordered list of existing objects, in creation order, oldest
first. Each output line contains the class name, object identifier and
the procedure within which the creation occurred. The optional pattern
argument (as in the Tcl <b class="cmd">string match</b> command) can be used to
limit the output to matching class names.</p></dd>
<dt><a name="8"><b class="cmd">::stooop::record</b></a></dt>
<dd><p>When invoked, a snapshot of all existing stooop objects is
taken. Reporting can then be used at a later time to see which objects
were created or deleted in the interval.</p></dd>
<dt><a name="9"><b class="cmd">::stooop::report</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Prints the created and deleted objects since the <b class="cmd">::stooop::record</b>
procedure was invoked last. If present, the pattern argument limits
the output to matching class names.</p></dd>
</dl>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">EXAMPLES</a></h2>
<p>Please see the full HTML documentation in <a href="stooop_man.html">stooop_man.html</a>.</p>
</div>
<div id="section4" class="doctools_section"><h2><a name="section4">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>stooop</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#c_">C++</a>, <a href="../../../../index.html#class">class</a>, <a href="../../../../index.html#object">object</a>, <a href="../../../../index.html#object_oriented">object oriented</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Programming tools</p>
</div>
</div>