1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
|
<html><head>
<title>nx::Class - </title>
<link rel="stylesheet" href="man.css" type="text/css">
</head>
<! -- Generated from file 'Class.man' by tcllib/doctools with format 'html'
-->
<! -- Copyright © 2014 Stefan Sobernig <stefan.sobernig@wu.ac.at>, Gustaf Neumann <gustaf.neumann@wu.ac.at>; available under the Creative Commons Attribution 3.0 Austria license (CC BY 3.0 AT).
-->
<! -- CVS: $Id$ nx::Class.3
-->
<body><div class="doctools">
<h1 class="title">nx::Class(3) 2.0 Class ""</h1>
<div id="name" class="section"><h2><a name="name">Name</a></h2>
<p>nx::Class - API reference of the base-metaclass of the NX objectsystem</p>
</div>
<div id="toc" class="section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="toc">
<li class="section"><a href="#toc">Table Of Contents</a></li>
<li class="section"><a href="#synopsis">Synopsis</a></li>
<li class="section"><a href="#section1">Description</a></li>
<li class="section"><a href="#section2">Configuration Options for Instances of nx::Class</a></li>
<li class="section"><a href="#section3">Methods for Instances of nx::Class</a></li>
<li class="section"><a href="#section4">Object Life Cycle</a></li>
<li class="section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="synopsis">
<ul class="syntax">
<li><a href="#1"><b class="cmd">nx::Class</b> <b class="method">create</b> <i class="arg">cls</i> <span class="opt">?<b class="option">-superclasses</b> <i class="arg">superClassNames</i>?</span> <span class="opt">?<b class="option">-mixins</b> <i class="arg">mixinSpec</i>?</span> <span class="opt">?<b class="option">-filters</b> <i class="arg">filterSpec</i>?</span> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i> ...?</span> <span class="opt">?<i class="arg">initBlock</i>?</span></a></li>
<li><a href="#2"><b class="cmd">nx::Class</b> <b class="method">new</b> <span class="opt">?<b class="option">-superclasses</b> <i class="arg">superClassNames</i>?</span> <span class="opt">?<b class="option">-mixins</b> <i class="arg">mixinSpec</i>?</span> <span class="opt">?<b class="option">-filters</b> <i class="arg">filterSpec</i>?</span> <span class="opt">?<i class="arg">initBlock</i>?</span></a></li>
<li><a href="#3"><i class="arg">cls</i> <span class="opt">?<b class="method">public</b> | <b class="method">private</b> | <b class="method">protected</b>?</span> <b class="method"> alias</b> <i class="arg">methodName</i> <span class="opt">?<b class="option">-returns</b> <i class="arg">valueChecker</i>?</span> <span class="opt">?<b class="option">-frame</b> <b class="const">object</b> | <b class="const">method</b>?</span> <i class="arg">cmdName</i></a></li>
<li><a href="#4"><i class="arg">cls</i> <b class="method">create</b> <i class="arg">instanceName</i> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i> <i class="arg">option</i> <i class="arg">value</i> ...?</span></a></li>
<li><a href="#5"><i class="arg">cls</i> <b class="method">delete</b> <i class="arg">feature</i> <i class="arg">arg</i></a></li>
<li><a href="#6"><i class="arg">cls</i> <b class="const"></b> <b class="method">filters</b> <i class="arg">submethod</i> <span class="opt">?<i class="arg">arg</i> ...?</span></a></li>
<li><a href="#7"><i class="arg">cls</i> <span class="opt">?<b class="method">public</b> | <b class="method">protected</b> | <b class="method">private</b>?</span> <b class="method"> forward</b> <i class="arg">methodName</i> <span class="opt">?<b class="option">-prefix</b> <i class="arg">prefixName</i>?</span> <span class="opt">?<b class="option">-frame</b> <b class="const">object</b>?</span> <span class="opt">?<b class="option">-returns</b> <i class="arg">valueChecker</i>?</span> <span class="opt">?<b class="option">-verbose</b>?</span> <span class="opt">?<i class="arg">target</i>?</span> <span class="opt">?<i class="arg">arg</i> ...?</span></a></li>
<li><a href="#8"><i class="arg">cls</i> <b class="method">info heritage</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#9"><i class="arg">cls</i> <b class="method">info instances</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#10"><i class="arg">cls</i> <b class="method">info mixinof</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<b class="option">-scope</b> <i class="arg">option</i>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#11"><i class="arg">cls</i> <b class="method">info subclasses</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<b class="option">-dependent</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#12"><i class="arg">cls</i> <b class="method">info superclasses</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#13"><i class="arg">cls</i> <b class="method">info info</b> <span class="opt">?<b class="option">-asList</b>?</span></a></li>
<li><a href="#14"><i class="arg">cls</i> <b class="method">info filters</b> <span class="opt">?<b class="option">-guards</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#15"><i class="arg">cls</i> <b class="method">info method</b> <i class="arg">option</i> <i class="arg">methodName</i></a></li>
<li><a href="#16"><i class="arg">cls</i> <b class="method">info methods</b> <span class="opt">?<b class="option">-callprotection</b> <i class="arg">level</i>?</span> <span class="opt">?<b class="option">-type</b> <i class="arg">methodType</i>?</span> <span class="opt">?<b class="option">-path</b>?</span> <span class="opt">?<i class="arg">namePattern</i>?</span></a></li>
<li><a href="#17"><i class="arg">cls</i> <b class="method">info mixins</b> <span class="opt">?<b class="option">-guards</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#18"><i class="arg">cls</i> <b class="method">info slots</b> <span class="opt">?<b class="option">-type</b> <i class="arg">className</i>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#19"><i class="arg">cls</i> <b class="method">info variables</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#20"><i class="arg">cls</i> <span class="opt">?<b class="method">public</b> | <b class="method">protected</b> | <b class="method">private</b>?</span> <b class="method"> method</b> <i class="arg">name</i> <i class="arg">parameters</i> <span class="opt">?<b class="option">-checkalways</b>?</span> <span class="opt">?<b class="option">-returns</b> <i class="arg">valueChecker</i>?</span> <i class="arg">body</i></a></li>
<li><a href="#21"><i class="arg">cls</i> <b class="method"> mixins</b> <i class="arg">submethod</i> <span class="opt">?<i class="arg">arg</i> ...?</span></a></li>
<li><a href="#22"><i class="arg">cls</i> <b class="method">new</b> <span class="opt">?<b class="option">-childof</b> <i class="arg">parentName</i>?</span> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i> <i class="arg">option</i> <i class="arg">value</i> ...?</span></a></li>
<li><a href="#23"><i class="arg">cls</i> <b class="method">property</b> <span class="opt">?<b class="option">-accessor</b> <b class="const">public</b> | <b class="const">protected</b> | <b class="const">private</b>?</span> <span class="opt">?<b class="option">-configurable</b> <i class="arg">trueFalse</i>?</span> <span class="opt">?<b class="option">-incremental</b>?</span> <span class="opt">?<b class="option">-class</b> <i class="arg">className</i>?</span> <i class="arg">spec</i> <span class="opt">?<i class="arg">initBlock</i>?</span></a></li>
<li><a href="#24"><i class="arg">cls</i> <b class="method">require</b> <span class="opt">?<b class="method">public</b> | <b class="method">protected</b> | <b class="method">private</b>?</span> <b class="method"> method</b> <i class="arg">methodName</i></a></li>
<li><a href="#25"><i class="arg">cls</i> <b class="method">variable</b> <span class="opt">?<b class="option">-accessor</b> <b class="const">public</b> | <b class="const">protected</b> | <b class="const">private</b>?</span> <span class="opt">?<b class="option">-incremental</b>?</span> <span class="opt">?<b class="option">-class</b> <i class="arg">className</i>?</span> <span class="opt">?<b class="option">-configurable</b> <i class="arg">trueFalse</i>?</span> <span class="opt">?<b class="option">-initblock</b> <i class="arg">script</i>?</span> <i class="arg">spec</i> <span class="opt">?<i class="arg">defaultValue</i>?</span></a></li>
</ul>
</div>
</div>
<div id="section1" class="section"><h2><a name="section1">Description</a></h2>
<p><b class="cmd">nx::Class</b> is the base metaclass of the NX object
system. All classes (e.g. <em>cls</em>) are (direct or indirect)
instances of <b class="cmd">nx::Class</b>. Therefore, the methods provided by <b class="cmd">nx::Class</b> are
available to all classes. A class <em>cls</em> which does
not have <b class="cmd">nx::Class</b> as its direct or indirect superclass is
referred to as an <em>application class</em>. By default, when
instantiating a new class from <b class="cmd">nx::Class</b>, it becomes an
application class with <b class="cmd">nx::Object</b> being set as its superclass. A
class <em>cls</em> which is explicitly declared as a (direct or
indirect) subclass of <b class="cmd">nx::Class</b> is referred to as a <em>metaclass</em>, that
is, its instances will become classes as well. In other words, a
metaclass instantiates and subclasses <b class="cmd">nx::Class</b> at the same
time.</p>
<pre class="example">
+---------+
| ::nx::* |
+---------+--------------------------------------Y
| |
| instance of |
| .-------. |
| +--------'+ instance of +----------+ |
| | |<....................| | |
| | Class | | Object | |
| | |....................>| | |
| +---------+ subclass of +-----+----+ |
| ^ ^ ^ |
\...|...|................................|......./
| | |
| |subclass.....(xor)......subclass|
| |of +-----------+ of|
| |.........| |..........|
| (metaclass) | /cls/ | (application class)
|.............| |
instance of +-----------+
</pre>
<p>Classes can be created in the following ways:</p>
<dl class="definitions">
<dt><a name="1"><b class="cmd">nx::Class</b> <b class="method">create</b> <i class="arg">cls</i> <span class="opt">?<b class="option">-superclasses</b> <i class="arg">superClassNames</i>?</span> <span class="opt">?<b class="option">-mixins</b> <i class="arg">mixinSpec</i>?</span> <span class="opt">?<b class="option">-filters</b> <i class="arg">filterSpec</i>?</span> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i> ...?</span> <span class="opt">?<i class="arg">initBlock</i>?</span></a></dt>
<dd><p>To create a class having the explicit name <i class="arg">cls</i>, use <b class="method">create</b>.</p></dd>
<dt><a name="2"><b class="cmd">nx::Class</b> <b class="method">new</b> <span class="opt">?<b class="option">-superclasses</b> <i class="arg">superClassNames</i>?</span> <span class="opt">?<b class="option">-mixins</b> <i class="arg">mixinSpec</i>?</span> <span class="opt">?<b class="option">-filters</b> <i class="arg">filterSpec</i>?</span> <span class="opt">?<i class="arg">initBlock</i>?</span></a></dt>
<dd><p>To create a class having an automatically assigned, implicit name, use <b class="method">new</b>.</p></dd>
</dl>
<p>The configuration options for direct and indirect instances of <b class="cmd">nx::Class</b>,
which can be passed when calling <b class="method">create</b> and <b class="method">new</b>, are
documented in the subsequent section.</p>
</div>
<div id="section2" class="section"><h2><a name="section2">Configuration Options for Instances of nx::Class</a></h2>
<p>Configuration options can be used for configuring objects during
their creation by passing the options as non-positional arguments into calls
of <b class="method">new</b> and <b class="method">create</b> (see <b class="cmd">nx::Class</b>). An
existing object can be queried for its current configuration using
<b class="method">cget</b> and it can be re-configured using <b class="method">configure</b>.</p>
<dl class="options">
<dt><b class="option">-superclasses</b> <span class="opt">?<i class="arg">superClassNames</i>?</span></dt>
<dd><p>If <i class="arg">superClassNames</i> is not specified, returns the superclasses of
the class. If provided, the class becomes the subclass of <i class="arg">superClassNames</i>.</p></dd>
<dt><b class="option">-filters</b> <span class="opt">?<i class="arg">filterSpecs</i>?</span></dt>
<dd><p>Retrieves the list of filter methods currently active on instances of
the class, if <i class="arg">filterSpecs</i> is not set. Otherwise, activates a
list of filter methods for the instances of the class. Filters are
returned or set in terms of a list of filter specifications.</p></dd>
<dt><b class="option">-mixins</b> <span class="opt">?<i class="arg">mixinSpecs</i>?</span></dt>
<dd><p>Returns the list of mixin classes currently active on
instances of the class, if <i class="arg">mixinSpecs</i> is not specified. Otherwise, the class
is extended by the list of mixin classes provided by <i class="arg">mixinSpecs</i>.
mixin classes are returned or set in terms of a list of mixin specifications.</p></dd>
</dl>
<p>The configuration options provided by <b class="cmd">nx::Object</b> are equally
available because an application class <i class="arg">cls</i> is an indirect
instance of <b class="cmd">nx::Object</b>.</p>
</div>
<div id="section3" class="section"><h2><a name="section3">Methods for Instances of nx::Class</a></h2>
<dl class="commands">
<dt><b class="cmd">alias</b></dt>
<dd><dl class="definitions">
<dt><a name="3"><i class="arg">cls</i> <span class="opt">?<b class="method">public</b> | <b class="method">private</b> | <b class="method">protected</b>?</span> <b class="method"> alias</b> <i class="arg">methodName</i> <span class="opt">?<b class="option">-returns</b> <i class="arg">valueChecker</i>?</span> <span class="opt">?<b class="option">-frame</b> <b class="const">object</b> | <b class="const">method</b>?</span> <i class="arg">cmdName</i></a></dt>
<dd><p>Define an alias method for the given class. The
resulting method registers a pre-existing Tcl command <i class="arg">cmdName</i>
under the (alias) name <i class="arg">methodName</i> with the class. If <i class="arg">cmdName</i> refers
to another <b class="method">method</b>, the corresponding argument
should be a valid method handle. If a Tcl command (e.g., a
<b class="cmd">proc</b>), the argument should be a fully qualified Tcl command
name. If aliasing a subcommand (e.g., <b class="cmd">array exists</b>) of a Tcl namespace ensemble (e.g., <b class="cmd">array</b>), <i class="arg">cmdName</i> must hold the fully qualified subcommand name (and not the ensemble name of
the subcommand).</p>
<p>As for a regular <b class="method">class method</b>, <b class="option">-returns</b>
allows for setting a value checker on the values returned by
the aliased command <i class="arg">cmdName</i>.</p>
<p>When creating an alias method for
a <em>C-implemented</em> Tcl command (i.e., command defined using the
Tcl/NX C-API), <b class="option">-frame</b> sets the scope
for variable references used in the aliased command. If the provided
value is <b class="const">object</b>, then variable references will be resolved in the
context of the called object, i.e., the object upon which the alias method is
invoked, as if they were object variables. There is no need for using
the colon-prefix notation for identifying object variables. If the
value is <b class="const">method</b>, then the aliased command will be executed as a regular method call. The command is aware of its called-object context; i.e., it can resolve <b class="cmd">::nx::self</b>. In addition, the alias method has access to the method-call context (e.g., <b class="cmd">nx::next</b>). If <b class="option">-frame</b> is omitted, and by default, the variable references will resolve in the context of the caller of the alias method.</p></dd>
</dl></dd>
<dt><b class="cmd">__class_configureparameter</b></dt>
<dd><dl class="definitions">
<dt><i class="arg">cls</i> <b class="method">__class_configureparameter</b></dt>
<dd><p>Computes and returns the configuration options available for <i class="arg">cls</i> instances, to be consumed as method-parameter specification by <b class="method">configure</b>.</p></dd>
</dl></dd>
<dt><b class="cmd">create</b></dt>
<dd><dl class="definitions">
<dt><a name="4"><i class="arg">cls</i> <b class="method">create</b> <i class="arg">instanceName</i> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i> <i class="arg">option</i> <i class="arg">value</i> ...?</span></a></dt>
<dd><p>This factory method creates an instance <i class="arg">instanceName</i> of <i class="arg">cls</i>
and returns <i class="arg">instanceName</i>.</p>
<pre class="example">
% nx::Class create AClass {
:method init args {
next
}; # initialization method for instances of 'AClass'
}; # defines a class 'AClass' being an instance of 'nx::Class'
::AClass
% ::AClass create anInstance; # defines an object 'anInstance' being an instance of 'AClass'
::anInstance
% ::anInstance info class
::AClass
% ::AClass info class
::nx::Class
</pre>
<p><b class="method">create</b> accepts the configuration options <i class="arg">option</i>
available for this instance, such as those defined by properties of
<i class="arg">cls</i> (see <b class="method">property</b>).</p>
<p>Note that <b class="method">create</b> is called internally when defining an
instance of <i class="arg">cls</i> using <b class="method">new</b>.</p>
<p>By calling <b class="method">create</b> on <b class="cmd">nx::Class</b> itself, the created
instance will become a new application class <i class="arg">instanceName</i> on
which <b class="method">create</b> can also be applied (i.e., it can be
instantiated). If the so-created class has <b class="cmd">::nx::Class</b> its
direct or indirect superclass, <i class="arg">instanceName</i> is referred to as a
metaclass; that is, a class whose instances are again
classes.</p></dd>
</dl></dd>
<dt><b class="cmd">delete</b></dt>
<dd><dl class="definitions">
<dt><a name="5"><i class="arg">cls</i> <b class="method">delete</b> <i class="arg">feature</i> <i class="arg">arg</i></a></dt>
<dd><p>This method serves as the equivalent to Tcl's <b class="cmd">rename</b> for
removing structural (properties, variables) and behavioral features
(methods) of the class:</p></dd>
<dt><i class="arg">cls</i> <b class="method">delete property</b> <i class="arg">propertyName</i></dt>
<dd></dd>
<dt><i class="arg">cls</i> <b class="method">delete variable</b> <i class="arg">variableName</i></dt>
<dd></dd>
<dt><i class="arg">cls</i> <b class="method">delete method</b> <i class="arg">methodName</i></dt>
<dd><p>Removes a property <i class="arg">propertyName</i>, variable <i class="arg">variableName</i>,
and method <i class="arg">methodName</i>, respectively, previously defined for the
scope of the class.</p>
<p><b class="method">delete method</b> can be equally used for removing regular methods (see <b class="method"> method</b>), an alias method (see <b class="method"> alias</b>), and a forwarder method (see <b class="method"> forward</b>).</p></dd>
</dl></dd>
<dt><b class="cmd">filters</b></dt>
<dd><dl class="definitions">
<dt><a name="6"><i class="arg">cls</i> <b class="const"></b> <b class="method">filters</b> <i class="arg">submethod</i> <span class="opt">?<i class="arg">arg</i> ...?</span></a></dt>
<dd><p>Accesses and modifies the list of methods which are registered as
filters with <i class="arg">cls</i> using a specific setter or getter
<i class="arg">submethod</i>:</p>
<dl class="definitions">
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters add</b> <i class="arg">spec</i> <span class="opt">?<i class="arg">index</i>?</span></dt>
<dd><p>Inserts a single filter into the current list of filters of <i class="arg">cls</i>. Using <i class="arg">index</i>, a position in the existing list of filters for inserting the new filter can be set. If
omitted, <i class="arg">index</i> defaults to the list head (0).</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters clear</b></dt>
<dd><p>Removes all filters from <i class="arg">cls</i> and returns the list of removed filters. Clearing
is equivalent to passing an empty list for <i class="arg">filterSpecList</i> to
<b class="const">class</b> <b class="method">filter set</b>.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters delete</b> <span class="opt">?<b class="option">-nocomplain</b>?</span> <i class="arg">specPattern</i></dt>
<dd><p>Removes a single filter from the current list of filters of
<i class="arg">cls</i> whose spec matches <i class="arg">specPattern</i>. <i class="arg">specPattern</i> can
contain special matching chars (see <b class="cmd">string match</b>). <b class="const">class</b> <b class="method">filters delete</b> will
throw an error if there is no matching filter, unless
<b class="option">-nocomplain</b> is set.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters get</b></dt>
<dd><p>Returns the list of current filter specifications registered for <i class="arg">cls</i>.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters guard</b> <i class="arg">methodName</i> <span class="opt">?<i class="arg">expr</i>?</span></dt>
<dd><p>If <i class="arg">expr</i> is specified, registers a guard expression <i class="arg">expr</i> with a filter <i class="arg">methodName</i>. This requires that the filter <i class="arg">methodName</i> has been previously set using <b class="const"></b> <b class="method">filters set</b> or added using
<b class="const"></b> <b class="method">filters add</b>. <i class="arg">expr</i> must be a valid Tcl expression (see
<b class="cmd">expr</b>). An empty string for <i class="arg">expr</i> will clear the currently registered
guard expression for filter <i class="arg">methodName</i>.</p>
<p>If <i class="arg">expr</i> is omitted, returns the guard expression set on the
filter <i class="arg">methodName</i> defined for <i class="arg">cls</i>. If none
is available, an empty string will be returned.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters methods</b> <span class="opt">?<i class="arg">pattern</i>?</span></dt>
<dd><p>If <i class="arg">pattern</i> is omitted, returns all filter names which are
defined by <i class="arg">cls</i>. By specifying <i class="arg">pattern</i>, the returned
filters can be limited to those whose names match <i class="arg">patterns</i> (see
<b class="cmd">string match</b>).</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">filters set</b> <i class="arg">filterSpecList</i></dt>
<dd><p><i class="arg">filterSpecList</i> takes a list of filter specs, with each spec being itself either a
one-element or a two-element list: <i class="arg">methodName</i> ?-guard <i class="arg">guardExpr</i>?. <i class="arg">methodName</i> identifies
an existing method of <i class="arg">cls</i> which becomes
registered as a filter. If having three elements, the third
element <i class="arg">guardExpr</i> will be stored as a guard expression of the
filter. This guard expression must be a valid Tcl expression
(see <b class="cmd">expr</b>). <i class="arg">expr</i> is evaluated when <i class="arg">cls</i> receives a message to determine whether the
filter should intercept the message. Guard expressions
allow for realizing context-dependent or conditional filter
composition.</p></dd>
</dl>
<p>Every <i class="arg">methodName</i> in a <i class="arg">spec</i> must resolve to an existing method in
the scope of the class. To
access and to manipulate the list of filters of <i class="arg">cls</i>,
<b class="method">cget</b>|<b class="method">configure</b> <b class="option">-filters</b> can also be used.</p></dd>
</dl></dd>
<dt><b class="cmd">forward</b></dt>
<dd><dl class="definitions">
<dt><a name="7"><i class="arg">cls</i> <span class="opt">?<b class="method">public</b> | <b class="method">protected</b> | <b class="method">private</b>?</span> <b class="method"> forward</b> <i class="arg">methodName</i> <span class="opt">?<b class="option">-prefix</b> <i class="arg">prefixName</i>?</span> <span class="opt">?<b class="option">-frame</b> <b class="const">object</b>?</span> <span class="opt">?<b class="option">-returns</b> <i class="arg">valueChecker</i>?</span> <span class="opt">?<b class="option">-verbose</b>?</span> <span class="opt">?<i class="arg">target</i>?</span> <span class="opt">?<i class="arg">arg</i> ...?</span></a></dt>
<dd><p>Define a forward method for the given class. The
definition of a forward method registers a predefined, but
changeable list of forwarder arguments under the (forwarder) name <i class="arg">methodName</i>. Upon
calling the forward method, the forwarder
arguments are evaluated as a Tcl command call. That is, if present, <i class="arg">target</i>
is interpreted as a Tcl command (e.g., a Tcl <b class="cmd">proc</b> or an object)
and the remainder of the forwarder arguments <i class="arg">arg</i> as arguments passed into
this command. The actual method arguments to the invocation of the
forward method itself are appended to the list of forwarder
arguments.
If <i class="arg">target</i> is omitted, the value of <i class="arg">methodName</i> is
implicitly set and used as <i class="arg">target</i>. This way, when providing a
fully-qualified Tcl command name as <i class="arg">methodName</i> without <i class="arg">target</i>, the
unqualified <i class="arg">methodName</i> (<b class="cmd">namespace tail</b>) is used as the
forwarder name; while the fully-qualified one serves as the <i class="arg">target</i>.</p>
<p>As for a regular <b class="method"> method</b>, <b class="option">-returns</b> allows
for setting a value checker on the values returned by the
resulting Tcl command call. When passing <b class="const">object</b> to <b class="option">-frame</b>, the
resulting Tcl command is evaluated in the context of the object
receiving the forward method call. This way, variable names
used in the resulting execution of a command become resolved as
object variables.</p>
<p>The list of forwarder arguments <i class="arg">arg</i> can contain as its elements
a mix of literal values and placeholders. Placeholders are prefixed
with a percent symbol (%) and substituted for concrete values upon
calling the forward method. These placeholders allow for
constructing and for manipulating the arguments to be passed into the
resulting command call on the fly:</p>
<ul class="itemized">
<li><p><b class="const">%method</b> becomes substituted for the name of the forward method, i.e. <i class="arg">methodName</i>.</p></li>
<li><p><b class="const">%self</b> becomes substituted for the name of the object receiving the call of the forward method.</p></li>
<li><p><b class="const">%1</b> becomes substituted for the first method argument passed to the call of forward method. This requires, in turn, that <em>at least</em> one argument is passed along with the method call.</p>
<p>Alternatively, <b class="const">%1</b> accepts an optional argument <i class="arg">defaults</i>: {<b class="const">%1</b> <i class="arg">defaults</i>}.
<i class="arg">defaults</i> must be a valid Tcl list of two elements. For the first
element, <b class="const">%1</b> is substituted when there is no first method
argument which can be consumed by <b class="const">%1</b>. The second element is
inserted upon availability of a first method argument with the
consumed argument being appended right after the second list
element. This placeholder is typically used to define a pair of
getter/setter methods.</p></li>
<li><p>{<b class="const">%@</b><i class="arg">index</i> <i class="arg">value</i>} becomes substituted for the
specified <i class="arg">value</i> at position <i class="arg">index</i> in the
forwarder-arguments list, with <i class="arg">index</i> being either a positive
integer, a negative integer, or the literal value <b class="const">end</b> (such as
in Tcl's <b class="cmd">lindex</b>). Positive integers specify a list position
relative to the list head, negative integers give a position relative
to the list tail. Indexes for positioning placeholders in the definition of a
forward method are evaluated from left to right and should be
used in ascending order.</p>
<p>Note that <i class="arg">value</i> can be a literal or any of the placeholders
(e.g., <b class="const">%method</b>, <b class="const">%self</b>). Position prefixes are
exempted, they are evaluated as <b class="const">%</b><i class="arg">cmdName</i>-placeholders in this context.</p></li>
<li><p>{<b class="const">%argclindex</b> <i class="arg">list</i>} becomes substituted for the
<em>n</em>th element of the provided <i class="arg">list</i> , with <em>n</em>
corresponding to the number of method arguments passed to the forward method call.</p></li>
<li><p><b class="const">%%</b> is substituted for a single, literal percent symbol (%).</p></li>
<li><p><b class="const">%</b><i class="arg">cmdName</i> is substituted for the value returned
from executing the Tcl command <i class="arg">cmdName</i>. To pass arguments to <i class="arg">cmdName</i>, the placeholder should be wrapped into a Tcl <b class="cmd">list</b>: {<b class="const">%</b><i class="arg">cmdName</i> <span class="opt">?<i class="arg">arg</i> ...?</span>}.</p>
<p>Consider using fully-qualified Tcl command names for <i class="arg">cmdName</i> to
avoid possible name conflicts with the predefined placeholders, e.g.,
<b class="const">%self</b> vs. %<b class="cmd">::nx::self</b>.</p></li>
</ul>
<p>To disambiguate the names of subcommands or methods, which potentially
become called by a forward method, a prefix <i class="arg">prefixName</i>
can be set using <b class="option">-prefix</b>. This prefix is prepended
automatically to the argument following <i class="arg">target</i> (i.e., a second
argument), if present. If missing, <b class="option">-prefix</b> has no
effect on the forward method call.</p>
<p>To inspect and to debug the conversions performed by the above
placeholders, setting the switch <b class="option">-verbose</b>
will have the command list to be executed (i.e., after substitution)
printed using <b class="cmd">::nsf::log</b> (debugging level: <b class="const">notice</b>) upon
calling the forward method.</p></dd>
</dl></dd>
<dt><b class="cmd">info</b></dt>
<dd><p>A collection of introspection submethods on the structural features (e.g.
configuration options, superclasses) and the behavioral features (e.g.
methods, filters) provided by <i class="arg">cls</i> to its instances.</p>
<dl class="definitions">
<dt><a name="8"><i class="arg">cls</i> <b class="method">info heritage</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is omitted, returns the list of object names of all the direct and indirect
superclasses and <em>per-class</em> mixin classes of <i class="arg">cls</i>, in
their order of precedence, which are active for instances of <i class="arg">cls</i>. If
<i class="arg">pattern</i> is specified, only superclasses and mixin classes whose names
match <i class="arg">pattern</i> will be listed (see <b class="cmd">string match</b>).</p></dd>
<dt><a name="9"><i class="arg">cls</i> <b class="method">info instances</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is not specified, returns a list of the object names
of all the direct instances of <i class="arg">cls</i>. If the switch
<b class="option">-closure</b> is set, indirect instances are also returned. A
direct instance is created by using <b class="method">create</b> or <b class="method">new</b> on
<i class="arg">cls</i>, an indirect instance was created from a direct or indirect
subclass of <i class="arg">cls</i>. If <i class="arg">pattern</i> is specified, only instances
whose names match <i class="arg">pattern</i> will be listed (see <b class="cmd">string match</b>).</p></dd>
<dt><a name="10"><i class="arg">cls</i> <b class="method">info mixinof</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<b class="option">-scope</b> <i class="arg">option</i>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is not specified, returns a list of the object names
of all the objects for which <i class="arg">cls</i> is active as a
direct mixin class. If the switch
<b class="option">-closure</b> is set, objects which have <i class="arg">cls</i> as an indirect
mixin class are also returned. If <i class="arg">pattern</i> is
specified, only objects whose names match <i class="arg">pattern</i> will
be listed (see <b class="cmd">string match</b>). Valid values of <i class="arg">option</i> are
<b class="const">all</b>, <b class="const">object</b>, and <b class="const">class</b>. Passing <b class="const">object</b>
will have only objects returned which have <i class="arg">cls</i> as <em>per-object</em>
mixin class. Passing <b class="const">class</b> will have only classes
returned which have <i class="arg">cls</i> as <em>per-class</em> mixin class. <b class="const">all</b> (the
default) will have contained both in the returned list.</p></dd>
<dt><a name="11"><i class="arg">cls</i> <b class="method">info subclasses</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<b class="option">-dependent</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is not specified, returns a list of the object names
of the direct subclasses of <i class="arg">cls</i>. If the switch <b class="option">-closure</b> is
set, indirect subclasses are also returned. If the switch <b class="option">-dependent</b> is on, indirect subclasses introduced by mixin class relations of subclasses of <i class="arg">cls</i> are also reported. <b class="option">-closure</b> and <b class="option">-dependent</b> are mutually exclusive. If <i class="arg">pattern</i> is specified, only subclasses whose names match <i class="arg">pattern</i> will be listed (see <b class="cmd">string match</b>).</p></dd>
<dt><a name="12"><i class="arg">cls</i> <b class="method">info superclasses</b> <span class="opt">?<b class="option">-closure</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is not specified, returns a list of the object names
of all direct superclasses of <i class="arg">cls</i>. If the switch <b class="option">-closure</b> is
set, indirect superclasses will also be returned. If <i class="arg">pattern</i> is specified, only superclasses whose names match <i class="arg">pattern</i> will be listed (see <b class="cmd">string match</b>).</p></dd>
<dt><a name="13"><i class="arg">cls</i> <b class="method">info info</b> <span class="opt">?<b class="option">-asList</b>?</span></a></dt>
<dd><p>Returns the available submethods of the <b class="method">info</b> method ensemble for
<i class="arg">cls</i>, either as a pretty-printed string or as a
Tcl list (if the switch <b class="option">-asList</b> is set) for further
processing.</p></dd>
<dt><a name="14"><i class="arg">cls</i> <b class="method">info filters</b> <span class="opt">?<b class="option">-guards</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is omitted, returns all filter names which are
defined by <i class="arg">cls</i>. By turning on the switch <b class="option">-guards</b>, the
corresponding guard expressions, if any, are also
reported along with each filter as a three-element list: <i class="arg">filterName</i> -guard
<i class="arg">guardExpr</i>. By specifying <i class="arg">pattern</i>, the
returned filters can be limited to those whose names match <i class="arg">patterns</i> (see
<b class="cmd">string match</b>).</p></dd>
<dt><a name="15"><i class="arg">cls</i> <b class="method">info method</b> <i class="arg">option</i> <i class="arg">methodName</i></a></dt>
<dd><p>This introspection submethod provides access to the details
of <i class="arg">methodName</i> provided by <i class="arg">cls</i>. Permitted values for
<i class="arg">option</i> are:</p>
<ul class="itemized">
<li><p><b class="const">args</b> returns a list containing the parameter names of
<i class="arg">methodName</i>, in order of the method-parameter specification.</p></li>
<li><p><b class="const">body</b> returns the body script of <i class="arg">methodName</i>.</p></li>
<li><p><b class="const">definition</b> returns a canonical command list which allows for (re-)define <i class="arg">methodName</i>.</p></li>
<li><p><b class="const">definitionhandle</b> returns the method handle for a submethod in a method ensemble from the perspective of <i class="arg">cls</i> as method provider. <i class="arg">methodName</i> must contain a complete method path.</p></li>
<li><p><b class="const">exists</b> returns 1 if there is a <i class="arg">methodName</i> provided by <i class="arg">cls</i>, returns 0 otherwise.</p></li>
<li><p><b class="const">handle</b> returns the method handle for <i class="arg">methodName</i>.</p></li>
<li><p><b class="const">origin</b> returns the aliased command if <i class="arg">methodName</i> is an alias method, or an empty string otherwise.</p></li>
<li><p><b class="const">parameters</b> returns the parameter specification of <i class="arg">methodName</i> as
a list of parameter names and type specifications.</p></li>
<li><p><b class="const">registrationhandle</b> returns the method handle for a submethod in a method ensemble from the perspective of the method caller. <i class="arg">methodName</i> must contain a complete method path.</p></li>
<li><p><b class="const">returns</b> gives the type specification defined
for the return value of <i class="arg">methodName</i>.</p></li>
<li><p><b class="const">submethods</b> returns the names of all submethods of <i class="arg">methodName</i>, if <i class="arg">methodName</i> is a method ensemble. Otherwise, an empty string is returned.</p></li>
<li><p><b class="const">syntax</b> returns the method parameters of <i class="arg">methodName</i> as a
concrete-syntax description to be used in human-understandable
messages (e.g., errors or warnings, documentation strings).</p></li>
<li><p><b class="const">type</b> returns whether <i class="arg">methodName</i> is a <em>scripted</em> method, an <em>alias</em> method, a <em>forwarder</em> method, or a <em>setter</em> method.</p></li>
</ul></dd>
<dt><a name="16"><i class="arg">cls</i> <b class="method">info methods</b> <span class="opt">?<b class="option">-callprotection</b> <i class="arg">level</i>?</span> <span class="opt">?<b class="option">-type</b> <i class="arg">methodType</i>?</span> <span class="opt">?<b class="option">-path</b>?</span> <span class="opt">?<i class="arg">namePattern</i>?</span></a></dt>
<dd><p>Returns the names of all methods defined by <i class="arg">cls</i>. Methods
covered include those defined using <b class="method"> alias</b>
and <b class="method"> forward</b>. The returned methods can be limited
to those whose names match <i class="arg">namePattern</i> (see <b class="cmd">string match</b>).</p>
<p>By setting <b class="option">-callprotection</b>, only methods of a certain call protection <i class="arg">level</i> (<b class="const">public</b>, <b class="const">protected</b>, or <b class="const">private</b>) will be returned. Methods of a specific type can be requested using <b class="option">-type</b>. The recognized values for <i class="arg">methodType</i> are:</p>
<ul class="itemized">
<li><p><b class="const">scripted</b> denotes methods defined using <b class="const">class</b> <b class="method">method</b>;</p></li>
<li><p><b class="const">alias</b> denotes alias methods defined using <b class="const">class</b> <b class="method">alias</b>;</p></li>
<li><p><b class="const">forwarder</b> denotes forwarder methods defined using <b class="const">class</b> <b class="method">forward</b>;</p></li>
<li><p><b class="const">setter</b> denotes methods defined using <b class="cmd">::nsf::setter</b>;</p></li>
<li><p><b class="const">all</b> returns methods of any type, without restrictions (also the default value);</p></li>
</ul></dd>
<dt><a name="17"><i class="arg">cls</i> <b class="method">info mixins</b> <span class="opt">?<b class="option">-guards</b>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is omitted, returns the object names of the mixin classes which
extend <i class="arg">cls</i> directly. By turning on the switch <b class="option">-guards</b>,
the corresponding guard expressions, if any, are also
reported along with each mixin as a three-element list: <i class="arg">className</i>
-guard <i class="arg">guardExpr</i>. The returned mixin classes can be limited to those whose names
match <i class="arg">patterns</i> (see <b class="cmd">string match</b>).</p></dd>
<dt><a name="18"><i class="arg">cls</i> <b class="method">info slots</b> <span class="opt">?<b class="option">-type</b> <i class="arg">className</i>?</span> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is not specified, returns the object names of all slot objects defined by <i class="arg">cls</i>. The returned slot objects can be limited according to any or a
combination of the following criteria: First, slot objects
can be filtered based on their command names matching <i class="arg">pattern</i> (see <b class="cmd">string
match</b>). Second, <b class="option">-type</b> allows one to select
slot objects which are instantiated from a subclass <i class="arg">className</i> of <b class="cmd">nx::Slot</b> (default: <b class="cmd">nx::Slot</b>).</p></dd>
<dt><a name="19"><i class="arg">cls</i> <b class="method">info variables</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>If <i class="arg">pattern</i> is omitted, returns the object names of all slot objects provided
by <i class="arg">cls</i> which are responsible for managing properties and variables of <i class="arg">cls</i>. Otherwise,
only slot objects whose names match <i class="arg">pattern</i> are
returned.</p>
<p>This is equivalent to calling: <i class="arg">cls</i> <b class="method">info slots</b> <b class="option">-type</b> <b class="cmd">::nx::VariableSlot</b> <i class="arg">pattern</i>.</p>
<p>To extract details of each slot object, use the <b class="method">info</b>
submethods available for each slot object.</p></dd>
</dl></dd>
<dt><b class="cmd">method</b></dt>
<dd><dl class="definitions">
<dt><a name="20"><i class="arg">cls</i> <span class="opt">?<b class="method">public</b> | <b class="method">protected</b> | <b class="method">private</b>?</span> <b class="method"> method</b> <i class="arg">name</i> <i class="arg">parameters</i> <span class="opt">?<b class="option">-checkalways</b>?</span> <span class="opt">?<b class="option">-returns</b> <i class="arg">valueChecker</i>?</span> <i class="arg">body</i></a></dt>
<dd><p>Defines a scripted method <i class="arg">methodName</i> for the scope of the class. The
method becomes part of the class's signature interface. Besides
a <i class="arg">methodName</i>, the method definition specifies
the method <i class="arg">parameters</i> and a method <i class="arg">body</i>.</p>
<p><i class="arg">parameters</i> accepts a Tcl <b class="cmd">list</b> containing an arbitrary
number of non-positional and positional parameter definitions. Each parameter
definition comprises a parameter name, a parameter-specific value checker, and
parameter options.</p>
<p>The <i class="arg">body</i> contains the method implementation as a script block. In this body script, the
colon-prefix notation is available to denote an object variable and
a self call. In addition, the context of the object receiving the
method call (i.e., the message) can be accessed (e.g., using <b class="cmd">nx::self</b>) and
the call stack can be introspected (e.g., using <b class="cmd">nx::current</b>).</p>
<p>Optionally, <b class="option">-returns</b> allows for setting a value checker on
values returned by the method implementation. By setting
the switch <b class="option">-checkalways</b>, value checking on
arguments and return value is guaranteed to be performed, even if
value checking is temporarily disabled; see <b class="cmd">nx::configure</b>).</p>
<p>A method closely resembles a Tcl <b class="cmd">proc</b>, but it differs in some
important aspects: First, a method can define non-positional
parameters and value checkers on arguments. Second, the script
implementing the method body can contain object-specific notation and
commands (see above). Third, method calls <em>cannot</em> be intercepted
using Tcl <b class="cmd">trace</b>. Note that an existing Tcl <b class="cmd">proc</b> can be registered as
an alias method with the class (see <b class="method"> alias</b>).</p></dd>
</dl></dd>
<dt><b class="cmd">mixins</b></dt>
<dd><dl class="definitions">
<dt><a name="21"><i class="arg">cls</i> <b class="method"> mixins</b> <i class="arg">submethod</i> <span class="opt">?<i class="arg">arg</i> ...?</span></a></dt>
<dd><p>Accesses and modifies the list of mixin classes of
<i class="arg">cls</i> using a specific setter or getter <i class="arg">submethod</i>:</p>
<dl class="definitions">
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins add</b> <i class="arg">spec</i> <span class="opt">?<i class="arg">index</i>?</span></dt>
<dd><p>Inserts a single mixin class into the current list of mixin classes of <i class="arg">cls</i>. Using <i class="arg">index</i>, a position in the existing list of mixin classes for inserting the new mixin class can be set. If
omitted, <i class="arg">index</i> defaults to the list head (0).</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins classes</b> <span class="opt">?<i class="arg">pattern</i>?</span></dt>
<dd><p>If <i class="arg">pattern</i> is omitted, returns the object names of the mixin classes which
extend <i class="arg">cls</i> directly. By specifying <i class="arg">pattern</i>, the returned mixin classes can
be limited to those whose names match <i class="arg">pattern</i> (see <b class="cmd">string match</b>).</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins clear</b></dt>
<dd><p>Removes all mixin classes from <i class="arg">cls</i> and returns the list of removed mixin classes. Clearing is equivalent to passing an empty list for <i class="arg">mixinSpecList</i> to
<b class="const"></b> <b class="method">mixins set</b>.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins delete</b> <span class="opt">?<b class="option">-nocomplain</b>?</span> <i class="arg">specPattern</i></dt>
<dd><p>Removes a mixin class from a current list of mixin classes of <i class="arg">cls</i> whose spec matches <i class="arg">specPattern</i>. <i class="arg">specPattern</i> can contain special matching chars (see <b class="cmd">string match</b>). <b class="const">class</b> <b class="method">mixins delete</b> will throw an error if there is no matching mixin class, unless <b class="option">-nocomplain</b> is set.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins get</b></dt>
<dd><p>Returns the list of current mixin specifications.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins guard</b> <i class="arg">className</i> <span class="opt">?<i class="arg">expr</i>?</span></dt>
<dd><p>If <i class="arg">expr</i> is specified, a guard expression <i class="arg">expr</i> is registered with the mixin class <i class="arg">className</i>. This requires that the corresponding mixin class <i class="arg">className</i> has been previously set using <b class="const">class</b> <b class="method">mixins set</b> or added using <b class="const"></b> <b class="method">mixins add</b>. <i class="arg">expr</i> must be a valid Tcl expression (see
<b class="cmd">expr</b>). An empty string for <i class="arg">expr</i> will clear the currently registered
guard expression for the mixin class <i class="arg">className</i>.</p>
<p>If <i class="arg">expr</i> is not specified, returns the active guard
expression. If none is available, an empty string will be returned.</p></dd>
<dt><i class="arg">cls</i> <b class="const"></b> <b class="method">mixins set</b> <i class="arg">mixinSpecList</i></dt>
<dd><p><i class="arg">mixinSpecList</i> represents a list of mixin class specs, with each spec being itself either a one-element or a three-element list: <i class="arg">className</i> ?-guard <i class="arg">guardExpr</i>?. If
having one element, the element will be considered the <i class="arg">className</i>
of the mixin class. If having three elements, the third
element <i class="arg">guardExpr</i> will be stored as a guard expression of the
mixin class. This guard expression will be evaluated using
<b class="cmd">expr</b> when <i class="arg">cls</i> receives a message to determine if the mixin
is to be considered during method dispatch or not. Guard expressions
allow for realizing context-dependent or conditional mixin
composition.</p></dd>
</dl>
<p>At the time of setting the mixin relation, that is, calling <b class="const"></b> <b class="method">mixins</b>, every
<i class="arg">className</i> as part of a spec must be an existing instance of <b class="cmd">nx::Class</b>. To
access and to manipulate the list of mixin classes of <i class="arg">cls</i>,
<b class="method">cget</b>|<b class="method">configure</b> <b class="option">-mixins</b> can also be used.</p></dd>
</dl></dd>
<dt><b class="cmd">new</b></dt>
<dd><dl class="definitions">
<dt><a name="22"><i class="arg">cls</i> <b class="method">new</b> <span class="opt">?<b class="option">-childof</b> <i class="arg">parentName</i>?</span> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i> <i class="arg">option</i> <i class="arg">value</i> ...?</span></a></dt>
<dd><p>A factory method to create autonamed instances of <i class="arg">cls</i>. It
returns the name of the newly created instance. For example:</p>
<pre class="example">
% nx::Class create AClass; # defines a class 'AClass' being an instance of 'nx::Class'
::AClass
% set inst [::AClass new]; # defines an autonamed object being an instance of 'AClass'
::nsf::__#0
% $inst info class
::AClass
</pre>
<p>The factory method will provide computed object names of the form,
e.g. <b class="const">::nsf::__#0</b>. The uniqueness of generated object names is
guaranteed for the scope of the current Tcl interpreter only.</p>
<p>It is a frontend to <b class="method">create</b> which will be called by <b class="method">new</b> once
the name of the instance has been computed, passing along the
arguments <i class="arg">option</i> to <b class="method">new</b> as the configuration options
(see <b class="method">create</b>).</p>
<p>If <b class="option">-childof</b> is provided, the new object will be created as a
nested object of <i class="arg">parentName</i>. <i class="arg">parentName</i> can be the name of
either an existing NX object or an existing Tcl namespace. If
non-existing, a Tcl namespace <i class="arg">parentName</i> will be created on the
fly.</p></dd>
</dl></dd>
<dt><b class="cmd">property</b></dt>
<dd><dl class="definitions">
<dt><a name="23"><i class="arg">cls</i> <b class="method">property</b> <span class="opt">?<b class="option">-accessor</b> <b class="const">public</b> | <b class="const">protected</b> | <b class="const">private</b>?</span> <span class="opt">?<b class="option">-configurable</b> <i class="arg">trueFalse</i>?</span> <span class="opt">?<b class="option">-incremental</b>?</span> <span class="opt">?<b class="option">-class</b> <i class="arg">className</i>?</span> <i class="arg">spec</i> <span class="opt">?<i class="arg">initBlock</i>?</span></a></dt>
<dd><p>Defines a property for the scope of the class. The <i class="arg">spec</i> provides
the property specification as a <b class="cmd">list</b> holding at least one
element or, maximum, two elements:
<i class="arg">propertyName</i><span class="opt">?<b class="const">:</b><i class="arg">typeSpec</i>?</span> <span class="opt">?<i class="arg">defaultValue</i>?</span>. The <i class="arg">propertyName</i> is also used as to form the names of the getter/setter methods,
if requested (see <b class="option">-accessor</b>). It
is, optionally, equipped with a <i class="arg">typeSpec</i> following a colon
delimiter which specifies a value checker for the values
which become assigned to the property. The second, optional element
sets a <i class="arg">defaultValue</i> for this property.</p>
<p>If <b class="option">-accessor</b> is set, a property will provide for
a pair of getter and setter methods:</p>
<dl class="definitions">
<dt><i class="arg">obj</i> <i class="arg">propertyName</i> <b class="method">set</b> <i class="arg">value</i></dt>
<dd><p>Sets the property <i class="arg">propertyName</i> to <i class="arg">value</i>.</p></dd>
<dt><i class="arg">obj</i> <i class="arg">propertyName</i> <b class="method">get</b></dt>
<dd><p>Returns the current value of property <i class="arg">propertyName</i>.</p></dd>
<dt><i class="arg">obj</i> <i class="arg">propertyName</i> <b class="method">unset</b></dt>
<dd><p>Removes the value store of <i class="arg">propertyName</i> (e.g., an object variable), if existing.</p></dd>
</dl>
<p>The option value passed along <b class="option">-accessor</b> sets the level of
call protection for the generated getter and setter methods: <b class="const">public</b>,
<b class="const">protected</b>, or <b class="const">private</b>. By default, no getter and setter
methods are created.</p>
<p>Turning on the switch <b class="option">-incremental</b> provides a refined
setter interface to the value managed by the property. First,
setting <b class="option">-incremental</b> implies requesting <b class="option">-accessor</b>
(set to <b class="const">public</b> by default, if not specified
explicitly). Second, the managed value will be considered a valid Tcl
list. A multiplicity of <b class="const">1..*</b> is set by default, if not
specified explicitly as part of <i class="arg">spec</i>. Third, to
manage this list value element-wise (<em>incrementally</em>), two
additional setter methods become available:</p>
<dl class="definitions">
<dt><i class="arg">obj</i> <i class="arg">propertyName</i> <b class="method">add</b> <i class="arg">element</i> <span class="opt">?<i class="arg">index</i>?</span></dt>
<dd><p>Adding <i class="arg">element</i> to the managed list value, at the list position given by <i class="arg">index</i> (by default: 0).</p></dd>
<dt><i class="arg">obj</i> <i class="arg">propertyName</i> <b class="method">delete</b> <i class="arg">elementPattern</i></dt>
<dd><p>Removing one or multiple elements from the managed list value which match <i class="arg">elementPattern</i>. <i class="arg">elementPattern</i> can contain matching characters (see <b class="cmd">string match</b>).</p></dd>
</dl>
<p>By setting <b class="option">-configurable</b> to <b class="const">true</b> (the default), the
property can be accessed and modified through <b class="method">cget</b> and
<b class="method">configure</b>, respectively. If <b class="const">false</b>, no configuration option
will become available via <b class="method">cget</b> and <b class="method">configure</b>.</p>
<p>If neither <b class="option">-accessor</b> nor <b class="option">-configurable</b> are
requested, the value managed by the property will have to be accessed
and modified directly. If the property manages an object variable, its
value will be readable and writable using <b class="cmd">set</b> and <b class="method">eval</b>.</p>
<p>A property becomes implemented by a slot object under any of the following conditions:</p>
<ul class="itemized">
<li><p><b class="option">-configurable</b> equals <b class="const">true</b> (by default).</p></li>
<li><p><b class="option">-accessor</b> is one of <b class="const">public</b>, <b class="const">protected</b>, or <b class="const">private</b>.</p></li>
<li><p><b class="option">-incremental</b> is turned on.</p></li>
<li><p><i class="arg">initBlock</i> is a non-empty string.</p></li>
</ul>
<p>Assuming default settings, every property is realized by a
slot object.</p>
<p>Provided a slot object managing the property is to be
created, a custom class <i class="arg">className</i> from which this slot object is
to be instantiated can be set using <b class="option">-class</b>. The
default value is <b class="cmd">::nx::VariableSlot</b>.</p>
<p>The last argument <i class="arg">initBlock</i> accepts an optional Tcl script which is passed into
the initialization procedure (see <b class="method">configure</b>) of the property's slot object. See
also <span class="sectref"><a href="#section1"><i class="arg">initBlock</i> for <b class="method">create</b> and <b class="method">new</b></a></span>.</p></dd>
</dl></dd>
<dt><b class="cmd">require</b></dt>
<dd><dl class="definitions">
<dt><a name="24"><i class="arg">cls</i> <b class="method">require</b> <span class="opt">?<b class="method">public</b> | <b class="method">protected</b> | <b class="method">private</b>?</span> <b class="method"> method</b> <i class="arg">methodName</i></a></dt>
<dd><p>Attempts to register a method definition made available using <b class="cmd">::nsf::method::provide</b> under
the name <i class="arg">methodName</i> with <i class="arg">cls</i> . The registered
method is subjected to default call protection (<b class="const">protected</b>), if
not set explicitly.</p></dd>
</dl></dd>
<dt><b class="cmd">variable</b></dt>
<dd><dl class="definitions">
<dt><a name="25"><i class="arg">cls</i> <b class="method">variable</b> <span class="opt">?<b class="option">-accessor</b> <b class="const">public</b> | <b class="const">protected</b> | <b class="const">private</b>?</span> <span class="opt">?<b class="option">-incremental</b>?</span> <span class="opt">?<b class="option">-class</b> <i class="arg">className</i>?</span> <span class="opt">?<b class="option">-configurable</b> <i class="arg">trueFalse</i>?</span> <span class="opt">?<b class="option">-initblock</b> <i class="arg">script</i>?</span> <i class="arg">spec</i> <span class="opt">?<i class="arg">defaultValue</i>?</span></a></dt>
<dd><p>Defines a variable for the scope of the class. The <i class="arg">spec</i> provides
the variable specification: <i class="arg">variableName</i><span class="opt">?<b class="const">:</b><i class="arg">typeSpec</i>?</span>. The
<i class="arg">variableName</i> will be used to name the underlying Tcl variable
and the getter/setter methods, if requested (see <b class="option">-accessor</b>).
<i class="arg">spec</i> is optionally equipped with a <i class="arg">typeSpec</i> following a colon
delimiter which specifies a value checker for the values
managed by the variable. Optionally, a <em>defaultValue</em> can
be defined.</p>
<p>If <b class="option">-accessor</b> is set explicitly, a variable will provide for a pair of
getter and setter methods:</p>
<dl class="definitions">
<dt><i class="arg">obj</i> <i class="arg">variableName</i> <b class="method">set</b> <i class="arg">varValue</i></dt>
<dd><p>Sets <i class="arg">variableName</i> to <i class="arg">varValue</i>.</p></dd>
<dt><i class="arg">obj</i> <i class="arg">variableName</i> <b class="method">get</b></dt>
<dd><p>Returns the current value of <i class="arg">variableName</i>.</p></dd>
<dt><i class="arg">obj</i> <i class="arg">variableName</i> <b class="method">unset</b></dt>
<dd><p>Removes <i class="arg">variableName</i>, if existing, underlying the property.</p></dd>
</dl>
<p>The option value passed along <b class="option">-accessor</b> sets the level of
call protection for the getter and setter methods: <b class="const">public</b>,
<b class="const">protected</b>, or <b class="const">private</b>. By default, no getter and setter
methods are created.</p>
<p>Turning on the switch <b class="option">-incremental</b> provides a refined
setter interface to the value managed by the variable. First,
setting <b class="option">-incremental</b> implies requesting <b class="option">-accessor</b>
(<b class="const">public</b> by default, if not specified
explicitly). Second, the managed value will be considered a valid Tcl
list. A multiplicity of <b class="const">1..*</b> is set by default, if not
specified explicitly as part of <i class="arg">spec</i> (see above). Third, to
manage this list value element-wise (<em>incrementally</em>), two
additional setter operations become available:</p>
<dl class="definitions">
<dt><i class="arg">obj</i> <i class="arg">variableName</i> <b class="method">add</b> <i class="arg">element</i> <span class="opt">?<i class="arg">index</i>?</span></dt>
<dd><p>Adding <i class="arg">element</i> to the managed list value, at the list position given by <i class="arg">index</i> (by default: 0).</p></dd>
<dt><i class="arg">obj</i> <i class="arg">variableName</i> <b class="method">delete</b> <i class="arg">elementPattern</i></dt>
<dd><p>Removing one or multiple elements from the managed list value which
match <i class="arg">elementPattern</i>. <i class="arg">elementPattern</i> can contain matching
characters (see <b class="cmd">string match</b>).</p></dd>
</dl>
<p>By setting <b class="option">-configurable</b> to <b class="const">true</b>, the variable can be
accessed and modified via <b class="method">cget</b> and <b class="method">configure</b>,
respectively. If <b class="const">false</b> (the default), the interface based on <b class="method">cget</b> and
<b class="method">configure</b> will not become available. In this case, and provided that
<b class="option">-accessor</b> is set, the variable can be accessed and modified via
the getter/setter methods. Alternatively, the underlying Tcl variable, which
is represented by the variable, can always be accessed and modified
directly, e.g., using <b class="method">eval</b>. By default, <b class="option">-configurable</b> is
<b class="const">false</b>.</p>
<p>A variable becomes implemented by a slot object under any of the following conditions:</p>
<ul class="itemized">
<li><p><b class="option">-configurable</b> equals <b class="const">true</b>.</p></li>
<li><p><b class="option">-accessor</b> is one of <b class="const">public</b>, <b class="const">protected</b>, or <b class="const">private</b>.</p></li>
<li><p><b class="option">-incremental</b> is turned on.</p></li>
<li><p><b class="option">-initblock</b> is a non-empty string.</p></li>
</ul>
<p>Provided a slot object managing the variable is to be
created, a custom class <i class="arg">className</i> from which this slot object is
to be instantiated can be set using <b class="option">-class</b>. The
default value is <b class="cmd">::nx::VariableSlot</b>.</p>
<p>Using <b class="option">-initblock</b>, an optional Tcl <i class="arg">script</i> can be defined which becomes passed into
the initialization procedure (see <b class="method">configure</b>) of the variable's slot object. See
also <span class="sectref"><a href="#section1"><i class="arg">initBlock</i> for <b class="method">create</b> and <b class="method">new</b></a></span>.</p></dd>
</dl></dd>
</dl>
</div>
<div id="section4" class="section"><h2><a name="section4">Object Life Cycle</a></h2>
<p><b class="cmd">nx::Class</b> provides means to control important stages through
which an NX object passes between and including its creation and its
destruction: allocation, recreation, deallocation.</p>
<pre class="example">
/cls/->create(/instance/)
.---------------. exists? [false] .----------------. .-------------------.
---->|Class::create()|----><>---------------->|Class::__alloc()|-----------><>---->|Object::configure()|
`---------------' | (1) `----------------' ^ (3) `---------+---------'
[true] | | | (4)
| .-------------------. | .------------------.
`->|Class::__recreate()|-------------------------' |/instance/->init()|
(2) `-------------------' `------------------'
/instance/->destroy()
.-----------------. .------------------.
---->|Object::destroy()|---->|Class::__dealloc()|
`-----------------' (5) `------------------'
</pre>
<p>Object creation is controlled by the factory method <b class="method">create</b>, provided by <b class="cmd">nx::Class</b> to its
instance <i class="arg">cls</i>. <b class="method">create</b> produces a new object <i class="arg">instance</i> as an
instance of <i class="arg">cls</i> in a number of steps.</p>
<ol class="enumerated">
<li><p>If <i class="arg">instance</i> does not represent an existing object, an
internal call to <b class="method">__alloc</b>, provided by <b class="cmd">nx::Class</b>, runs
the <em>allocation</em> procedure for a fresh <i class="arg">instance</i> of <i class="arg">cls</i>.</p></li>
<li><p>If <i class="arg">instance</i> corresponds to an existing object, the
<em>recreation</em> procedure is triggered by calling <b class="method">__recreate</b>
defined by <b class="cmd">nx::Class</b>.</p></li>
<li><p>The newly allocated or recreated object <i class="arg">instance</i> is then
configured by dispatching <b class="method">configure</b>, provided by <b class="cmd">nx::Object</b>, which
consumes the configuration options passed into <b class="method">create</b>. This
will establish the instance's initial state, e.g. by setting object
variables and object relations according to the configuration options
and corresponding default values.</p></li>
<li><p>Finally, the initialization method <b class="method">init</b> is dispatched, if
available for <i class="arg">instance</i>. <b class="method">init</b> can be defined by <i class="arg">cls</i> on
behalf of its instance <i class="arg">instance</i>, e.g. to lay out a
class-specific initialization behavior.</p>
<pre class="example">
% nx::Class create Foo {:property x}
% Foo method init {} {set :y [expr {${:x} + 1}]}
% Foo public method bar {} {return ${:y}}
% Foo create f1 -x 101
% f1 cget -x
101
% f1 bar
102
</pre>
<p>Alternatively, the object <i class="arg">instance</i> may define a per-object
<b class="method">init</b> on its own. A per-object <b class="method">init</b> can be chained to
a class-level <b class="method">init</b> using <b class="cmd">nx::next</b>, just like a regular
method.</p>
<p>Note that the definition of an <b class="method">init</b> method must contain an
empty parameter specification, since <b class="method">init</b> is always called
with an empty argument list.</p></li>
</ol>
<p>Object destruction, such as triggered by an application-level
<b class="method">destroy</b> call (5), is finalized by <b class="method">__dealloc</b> offerd by
<b class="cmd">nx::Class</b>.</p>
<p>In the following, the three built-in procedures ---
allocation, recreation, and deallocation --- are explained:</p>
<ul class="itemized">
<li><p><em>Allocation</em>: <b class="method">__alloc</b> creates a blank object <i class="arg">instance</i> as an instance of <i class="arg">cls</i> and returns the fully-qualified <i class="arg">instance</i>. <b class="method">__alloc</b> is primarily used internally by <b class="method">create</b> to allocate a Tcl memory storage for <i class="arg">instance</i> and to register <i class="arg">instance</i> with the Tcl
interpreter as a new command.</p></li>
<li><p><em>Recreation</em>:
Recreation is the NX scheme for resolving naming conflicts between
objects: An object is requested to be created using <b class="method">create</b> or
<b class="method">new</b> while an object of an identical object name, e.g. <i class="arg">instance</i>, already
exists:</p>
<pre class="example">
% Object create Bar
::Bar
% Object create Bar; # calls Object->__recreate(::Bar, ...)
::Bar
</pre>
<p>In such a situation, the built-in <b class="method">__recreate</b> first unsets
the object state (i.e., Tcl variables held by the object) and removes
relations of the object under recreation with other objects. Then,
second, standard object initialization is performed by calling <b class="method">configure</b> and
<b class="method">init</b>, if any.</p>
<p>Alternatively, recreation will be performed as a sequence of <b class="method">destroy</b> and
<b class="method">create</b> calls in the following recreation scenarios:</p>
<ul class="itemized">
<li><p>An existing class is requested to be recreated as an object.</p></li>
<li><p>An existing object is requested to be recreated as a class.</p>
<pre class="example">
% Object create Bar
::Bar
% Class create Bar; # calls Bar->destroy() & Class::create(::Bar, ...)
</pre>
</li>
<li><p>An object of an object system other than NX (e.g. XOTcl2) is asked to be recreated.</p></li>
</ul>
</li>
<li><p><em>Deallocation</em>: <b class="method">__dealloc</b> marks an instance <i class="arg">instance</i> of <i class="arg">cls</i> for
deletion by returning its Tcl memory representation to the Tcl memory pool and by
unregistering the corresponding Tcl command with the Tcl interpreter.</p>
<p>Beware that <b class="method">__dealloc</b> does not necessarily
cause the object to be deleted immediately. Depending on the lifecycle
of the object's environment (e.g. the Tcl interp interpreter, the containing
namespace) and on call references down the callstack, the actual
memory freeing/returning operation may occur at a later point.</p></li>
</ul>
<p>The three methods <b class="method">__alloc</b>, <b class="method">__recreate</b>, and <b class="method">__dealloc</b> are
internally provided and internally called. By default, they are not part of
the method interface of <i class="arg">cls</i> and cannot be called directly by clients of <i class="arg">cls</i>.
In addition, <b class="method">__alloc</b>, <b class="method">__recreate</b>, and <b class="method">__dealloc</b> are protected from
redefinition by a script.</p>
<p>To extend or to replace the built-in allocation, recreation, and
deallocation procedure, the methods <b class="method">__alloc</b>, <b class="method">__recreate</b>, and
<b class="method">__dealloc</b> can be refined by providing a custom method
implementation:</p>
<ul class="itemized">
<li><p>as a per-object method of <i class="arg">cls</i>;</p></li>
<li><p>as a method of a per-object mixin class extending <i class="arg">cls</i>;</p></li>
<li><p>as a method of a per-class mixin class extending <b class="cmd">nx::Class</b>;</p></li>
<li><p>as a method of a subclass specializing <b class="cmd">nx::Class</b>, from which <i class="arg">cls</i> is to be instantiated.</p></li>
</ul>
<p>This custom implementation can redirect to the built-in <b class="method">__alloc</b>, <b class="method">__recreate</b>, and
<b class="method">__dealloc</b>, respectively, by using <b class="cmd">nx::next</b>. By
providing such a custom implementation, <b class="method">__alloc</b>, <b class="method">__recreate</b>, and
<b class="method">__dealloc</b>, respectively, become available as callable methods
of <i class="arg">cls</i>:</p>
<dl class="definitions">
<dt><i class="arg">cls</i> <b class="method">__alloc</b> <i class="arg">instance</i></dt>
<dd></dd>
<dt><i class="arg">cls</i> <b class="method">__recreate</b> <i class="arg">instance</i> <span class="opt">?<i class="arg">arg</i> ...?</span></dt>
<dd></dd>
<dt><i class="arg">cls</i> <b class="method">__dealloc</b> <i class="arg">instance</i></dt>
<dd></dd>
</dl>
</div>
<div id="copyright" class="section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright © 2014 Stefan Sobernig <stefan.sobernig@wu.ac.at>, Gustaf Neumann <gustaf.neumann@wu.ac.at>; available under the Creative Commons Attribution 3.0 Austria license (CC BY 3.0 AT).</p>
</div>
</div></body></html>
|