SimpleClass v1.0
The Simple Development Library [incr Tcl] classes declaration
Project: the Simple Development Library.
::Simple::Class::cget ?-debug?::Simple::Class::configure ?-debug extbool?declare-class class ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-api string? ?-keywords list? ?-examples string? ?-classtype type? ?-stereotype choice? ?-extends qualifiedname-list? ?-debug extbool? ?-error declaration? ?-variable declaration? ?-attribute declaration? ?-itkoption declaration? ?-itkcomponent declaration? ?-command declaration? ?-method declaration? ?-assumptions string? ?-resources string? ?-limitations string? ?-effects string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-history string? ?-copyright string? ?-body script?::Simple::Class::delete class::Simple::Class::information aliases class::Simple::Class::information api class::Simple::Class::information attributes class ?-access choice?::Simple::Class::information classes ?pattern?::Simple::Class::information commands class::Simple::Class::information errors class::Simple::Class::information exists class::Simple::Class::information exportedcommands class::Simple::Class::information itkcomponents class::Simple::Class::information itkoptions class::Simple::Class::information metadata class::Simple::Class::information methods class::Simple::Class::information objects ?-class name? ?-isa name? ?pattern?::Simple::Class::information variables class ?-access choice?::Simple::ItkComponent::information access class itkcomponent::Simple::ItkComponent::information description class itkcomponent::Simple::ItkComponent::information ignore class itkcomponent::Simple::ItkComponent::information keep class itkcomponent::Simple::ItkComponent::information rename class itkcomponent::Simple::ItkComponent::information resourceclass class itkcomponent::Simple::ItkOption::information choices class itkoption::Simple::ItkOption::information default class itkoption::Simple::ItkOption::information defaultgiven class itkoption::Simple::ItkOption::information description class itkoption::Simple::ItkOption::information monitortype class itkoption::Simple::ItkOption::information resourceclass class itkoption::Simple::ItkOption::information resourcename class itkoption::Simple::ItkOption::information type class itkoption::Simple::Class::CONFIGBODY-FOR-NON-PUBLIC-ATTRIBUTE::Simple::Class::CONFIGBODY-FOR-ARRAY-ATTRIBUTE::Simple::Class::CLASS-COMMAND-CONSTRUCTOR-OR-DESTRUCTOR::Simple::Class::CLASS-COMMAND-AND-METHOD-SHARE-BASE-COMMAND::Simple::Class::SUBCOMMANDS-WITH-DIFFERENT-ACCESS::Simple::Class::NON-EXISTING-ITKITEM::Simple::Class::SUBMETHODS-WITH-DIFFERENT-ACCESS::Simple::Class::SHALL-EXTEND-ITK-ARCHETYPE::Simple::Class::MULTIPLE-OBJECTS-FOR-SINGLETON-CLASS::Simple::Class::OBJECT-FOR-ABSTRACT-CLASS::Simple::Class::PUBLIC-METHOD-WITH-BODY-FOR-ABSTRACT-CLASS::Simple::Class::CONSTRUCTOR-OR-DESTRUCTOR-FOR-ABSTRACT-CLASS::Simple::Class::VIRTUAL-METHOD-CALLED::Simple::Class::UNDECLARED::Simple::Class::cget ?-debug?::Simple::Class::configure ?-debug extbool?declare-class class ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-api string? ?-keywords list? ?-examples string? ?-classtype type? ?-stereotype choice? ?-extends qualifiedname-list? ?-debug extbool? ?-error declaration? ?-variable declaration? ?-attribute declaration? ?-itkoption declaration? ?-itkcomponent declaration? ?-command declaration? ?-method declaration? ?-assumptions string? ?-resources string? ?-limitations string? ?-effects string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-history string? ?-copyright string? ?-body script?::Simple::Class::delete class::Simple::Class::information aliases class::Simple::Class::information api class::Simple::Class::information attributes class ?-access choice?::Simple::Class::information classes ?pattern?::Simple::Class::information commands class::Simple::Class::information errors class::Simple::Class::information exists class::Simple::Class::information exportedcommands class::Simple::Class::information itkcomponents class::Simple::Class::information itkoptions class::Simple::Class::information metadata class::Simple::Class::information methods class::Simple::Class::information objects ?-class name? ?-isa name? ?pattern?::Simple::Class::information variables class ?-access choice?::Simple::ItkComponent::information access class itkcomponent::Simple::ItkComponent::information description class itkcomponent::Simple::ItkComponent::information ignore class itkcomponent::Simple::ItkComponent::information keep class itkcomponent::Simple::ItkComponent::information rename class itkcomponent::Simple::ItkComponent::information resourceclass class itkcomponent::Simple::ItkOption::information choices class itkoption::Simple::ItkOption::information default class itkoption::Simple::ItkOption::information defaultgiven class itkoption::Simple::ItkOption::information description class itkoption::Simple::ItkOption::information monitortype class itkoption::Simple::ItkOption::information resourceclass class itkoption::Simple::ItkOption::information resourcename class itkoption::Simple::ItkOption::information type class itkoptionSynopsis: the Simple Development Library [incr Tcl] classes declaration.
Keywords: object oriented, class, method, [incr Tcl], [incr Tk], widget and megawidget.
This package provides a way to declare [incr Tcl] classes and [incr Tk] megawidgets in an homogeneous, easily parseable, fully introspectable way. It allows to substitute the comment block which is usually placed on top of each declaration by Tcl-handled text.
Classes are declared with a single command (declare-class). Every single component needed to either make the class work (such as its attributes or methods) or to document it (metadata, such as the class synopsis) is provided as arguments to that command. Components can be fully introspected, but metadata is only available if The Simple Development Library -storemetadata option is set when the class is declared.
Procedures are provided to declare and delete classes and get information about them.
Use declare-class to declare a class. Declared classes metadata can be obtained via the ::Simple::Class::information metadata procedure. Other subcommands of this procedure provide information about declared classes: exists, classes, objects, errors, exportedcommands, aliases, variables, attributes, itkoptions, itkcomponents, commands, methods and api. The ::Simple::ItkOption::information and ::Simple::ItkComponent::information procedures provide subcommand to quet information about the [incr Tk] options and components of an [incr Tk] megawidget, respectively.
Use ::Simple::Class::delete to delete the class.
# Install the package
package require SimpleClass
::Simple::Package::require-and-install SimpleClass
# Let's store the metadata
::Simple::configure -storemetadata true
# Declare a class
declare-class {
Class
} -synopsis {
This is the class synopsis.
} -variable {
{
Variable
} -description {
This is a class variable
} -value 50
} -attribute {
{
Attribute
} -description {
This is a class attribute
} -value 50
} -error {
{
Error
} -message {
Class error
} -explanation {
This is a class error.
}
} -command {
{
command
} -synopsis {
This is the command synopsis.
} -arguments {
{-modify boolflag {Whether to modify the class variable}}
{ value integer {New class variable value}}
} -effects {
* Modifies the class variable if -modify is given.
} -body {
# Must modify the class variable
if {[::Simple::Argument::information flaggiven -modify]} {
# Modify it
set ::Class::Variable $value
}
# Class variable value too big
if {$::Class::Variable > 99} {
# Throw the class error
::Simple::Error::throw ::Class::Error
# Correct class variable value
} else {
# Display it
puts "Class variable = $::Class::Variable"
}
}
} -method {
{
method
} -synopsis {
This is the method synopsis.
} -arguments {
{-modify boolflag {Whether to modify the object attribute}}
{ value integer {New object attribute value}}
} -effects {
* Modifies the object attribute if -modify is given.
} -body {
# Must modify the object attribute
if {[::Simple::Argument::information flaggiven -modify]} {
# Modify it
set Attribute $value
}
# Object attribute value too big
if {$Attribute > 99} {
# Throw the class error
::Simple::Error::throw ::Class::Error
# Correct object attribute value
} else {
# Display it
puts "Object $this attribute = $Attribute"
}
}
}
# Invoke the class command
# This displays the following:
# |Class variable = 50
::Class::command 77
# This displays the following:
# |Class variable = 88
::Class::command -modify 88
# This displays the following:
# |Class error (::Class::Error)
catch {::Class::command -modify 120} result
puts "$result ($::errorCode)"
# Introspect the class
# This displays the following:
# |Class errors: ::Class::Error
# |Class commands: ::Class::command
# |Class methods: ::Class::method
# |Class variables: ::Class::Variable
# |Class attributes: ::Class::Attribute
puts "Class errors: [::Simple::Class::information errors Class]"
puts "Class commands: [::Simple::Class::information commands Class]"
puts "Class methods: [::Simple::Class::information methods Class]"
puts "Class variables: [::Simple::Class::information variables Class]"
puts "Class attributes: [::Simple::Class::information attributes Class]"
# Obtain the class metadata
# This displays the following:
# |-assumptions =
# | -classtype =
# | -copyright =
# | -details =
# | -effects =
# | -examples =
# | -extends =
# | -history =
# | -keywords =
# |-limitations =
# | -overview =
# | -project =
# | -references =
# | -remarks =
# | -resources =
# | -stereotype =
# | -synopsis = This is the command synopsis.
# | -todo =
# | -usage =
# | -version = 1.0
array set metadata [::Simple::Class::information metadata Class]
foreach element [lsort [array names metadata]] {
puts [format {%12s = %s} -$element $metadata($element)]
}
# Create two objects of the class
Class object1
Class object2
# Invoke the first object methods
# This displays the following:
# |Object ::object1 attribute = 50
# |Object ::object1 attribute = 88
object1 method 77
object1 method -modify 88
# Invoke the second object methods
# This displays the following:
# |Object ::object2 attribute = 50
# |Object ::object2 attribute = 22
object2 method 11
object1 method -modify 22
# This displays the following:
# |Class error (::Class::Error)
catch {object1 method -modify 120} result
puts "$result ($::errorCode)"
| Date | Reason |
| 22-mar-2003 | Added -body to method declaration, version 0.5.1 |
| 15-jul-2003 | Method declaration added to declare-class, version 0.5.2 |
| 20-jan-2004 | Comments allowed before embedded declarations in declare-class, version 0.5.3 |
| 28-jan-2004 | Added -itkoption and -itkcomponent to declare-class, version 0.5.4 |
| 26-oct-2004 | Added -error to declare-class, version 0.5.5 |
| 04-apr-2005 | Added debug method and -debug option, version 0.5.6 |
| 22-jun-2005 | The Simple Development Library version 1.0 |
Copyright (C) 1999-2005, Juan C. Gil (jgil@gmv.es).
Paradigm: procedural.
Requisites: SimpleDeclare 1.0 and Itcl.
None.
Type: extbool.
Value: false.
Description: whether to create a %debug% debug method for every class.
::Simple::Class
::Simple::Class::Priv
::Simple::ItkOption
::Simple::ItkComponent
::Simple::Class::cget ?-debug?Synopsis: gets the package options.
Details: see section 4.1.
::Simple::Class::configure ?-debug extbool?Synopsis: configures the package options.
Details: see section 4.2.
declare-class class ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-api string? ?-keywords list? ?-examples string? ?-classtype type? ?-stereotype choice? ?-extends qualifiedname-list? ?-debug extbool? ?-error declaration? ?-variable declaration? ?-attribute declaration? ?-itkoption declaration? ?-itkcomponent declaration? ?-command declaration? ?-method declaration? ?-assumptions string? ?-resources string? ?-limitations string? ?-effects string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-history string? ?-copyright string? ?-body script?Synopsis: declares a class.
Details: see section 4.3.
::Simple::Class::delete classSynopsis: deletes an [incr Tcl] class.
Details: see section 4.4.
::Simple::Class::information aliases classSynopsis: returns a class list of aliases.
Details: see section 4.5.
::Simple::Class::information api classSynopsis: returns a class public API signature.
Details: see section 4.6.
::Simple::Class::information attributes class ?-access choice?Synopsis: returns a class list of attributes matching the given access level.
Details: see section 4.7.
::Simple::Class::information classes ?pattern?Synopsis: returns the list of classes matching the pattern.
Details: see section 4.8.
::Simple::Class::information commands classSynopsis: returns a class current list of public and exported commands.
Details: see section 4.9.
::Simple::Class::information errors classSynopsis: returns a class list of errors.
Details: see section 4.10.
::Simple::Class::information exists classSynopsis: returns whether a class exists.
Details: see section 4.11.
::Simple::Class::information exportedcommands classSynopsis: returns a class list of exported commands.
Details: see section 4.12.
::Simple::Class::information itkcomponents classSynopsis: returns a class list of [incr Tk] components.
Details: see section 4.13.
::Simple::Class::information itkoptions classSynopsis: returns a class list of [incr Tk] options.
Details: see section 4.14.
::Simple::Class::information metadata classSynopsis: returns a class metadata.
Details: see section 4.15.
::Simple::Class::information methods classSynopsis: returns a class current list of public methods.
Details: see section 4.16.
::Simple::Class::information objects ?-class name? ?-isa name? ?pattern?Synopsis: returns the list of objects matching the pattern.
Details: see section 4.17.
::Simple::Class::information variables class ?-access choice?Synopsis: returns a class list of variables matching the given access level.
Details: see section 4.18.
::Simple::ItkComponent::information access class itkcomponentSynopsis: returns an [incr Tk] component access mode.
Details: see section 4.19.
::Simple::ItkComponent::information description class itkcomponentSynopsis: returns an [incr Tk] component description.
Details: see section 4.20.
::Simple::ItkComponent::information ignore class itkcomponentSynopsis: returns an [incr Tk] component list of ignored options.
Details: see section 4.21.
::Simple::ItkComponent::information keep class itkcomponentSynopsis: returns an [incr Tk] component list of kept options.
Details: see section 4.22.
::Simple::ItkComponent::information rename class itkcomponentSynopsis: returns an [incr Tk] component list of renamed options.
Details: see section 4.23.
::Simple::ItkComponent::information resourceclass class itkcomponentSynopsis: returns an [incr Tk] component resource class.
Details: see section 4.24.
::Simple::ItkOption::information choices class itkoptionSynopsis: returns an [incr Tk] option choices.
Details: see section 4.25.
::Simple::ItkOption::information default class itkoptionSynopsis: returns an [incr Tk] option default value.
Details: see section 4.26.
::Simple::ItkOption::information defaultgiven class itkoptionSynopsis: returns whether an [incr Tk] option has a default value.
Details: see section 4.27.
::Simple::ItkOption::information description class itkoptionSynopsis: returns an [incr Tk] option description.
Details: see section 4.28.
::Simple::ItkOption::information monitortype class itkoptionSynopsis: returns whether an [incr Tk] option is being monitored.
Details: see section 4.29.
::Simple::ItkOption::information resourceclass class itkoptionSynopsis: returns an [incr Tk] option resource class.
Details: see section 4.30.
::Simple::ItkOption::information resourcename class itkoptionSynopsis: returns an [incr Tk] option resource name.
Details: see section 4.31.
::Simple::ItkOption::information type class itkoptionSynopsis: returns an [incr Tk] option type.
Details: see section 4.32.
::Simple::Class::CONFIGBODY-FOR-NON-PUBLIC-ATTRIBUTEMessage: -configbody given for non-public attribute "attribute".
Explanation: the declaration of attribute attribute failed because "-configbody" was provided for a non-public attribute, but that is not allowed.
Corrective action: either remove the "-configbody" or make the attribute public.
::Simple::Class::CONFIGBODY-FOR-ARRAY-ATTRIBUTEMessage: -configbody given for array attribute "attribute".
Explanation: the declaration of attribute attribute failed because "-configbody" was provided for an attribute whose type is a derived array type, but that is not allowed.
Corrective action: either remove the "-configbody" or change the attribute type.
::Simple::Class::CLASS-COMMAND-CONSTRUCTOR-OR-DESTRUCTORMessage: class commands can not be named "constructor or destructor".
Explanation: the declaration of a class failed because class command constructor or destructor is named "constructor" or "destructor", but that is not allowed.
Corrective action: use a different name for the class command.
::Simple::Class::CLASS-COMMAND-AND-METHOD-SHARE-BASE-COMMANDMessage: class command and method share the same base command "base command".
Explanation: the declaration of a class failed because a class command and a method are both subcommands sharing the same base command base command, but that is not allowed.
Corrective action: use different base commands for class commands and methods.
::Simple::Class::SUBCOMMANDS-WITH-DIFFERENT-ACCESSMessage: class subcommands "class subcommand 1" and "class cubcommand 2" have different access modes.
Explanation: the declaration of a class failed because two class subcommands (class subcommand 1 and class cubcommand 2) corresponding to the same base command have different access modes, but that is not allowed.
Corrective action: declare all subcommands for a given base command with the same access mode.
::Simple::Class::NON-EXISTING-ITKITEMMessage: class "class" doesn't have an option or a component "bad [incr Tk] option".
Explanation: class class does not have an option or a component named bad [incr Tk] option.
::Simple::Class::SUBMETHODS-WITH-DIFFERENT-ACCESSMessage: submethods "class" and "submethod 1" of class "submethod 2" have different access modes.
Explanation: the declaration of class class failed because two class submethods (submethod 1 and submethod 2) corresponding to the same base method have different access modes, but that is not allowed.
Corrective action: declare all submethods for a given base method with the same access mode.
::Simple::Class::SHALL-EXTEND-ITK-ARCHETYPEMessage: class class with option or component shall extend ::itk::Archetype.
Explanation: class class is a megawidget because it has an [incr Tk] option or component, and so shall extend ::itk::Archetype. Notice that ::itk::Widget and ::itk::Toplevel already extend ::itk::Archetype.
::Simple::Class::MULTIPLE-OBJECTS-FOR-SINGLETON-CLASSMessage: multiple objects for singleton class "class".
Explanation: more than one object is being created for singleton class class, but that is not allowed.
::Simple::Class::OBJECT-FOR-ABSTRACT-CLASSMessage: object for abstract class "class".
Explanation: an object for abstrac class class is being created, but that is not allowed.
::Simple::Class::PUBLIC-METHOD-WITH-BODY-FOR-ABSTRACT-CLASSMessage: public method "method" with body for abstract class "class".
Explanation: a public method method with body is being declared for abstract class class, but that is not allowed.
::Simple::Class::CONSTRUCTOR-OR-DESTRUCTOR-FOR-ABSTRACT-CLASSMessage: constructor or destructor for abstract class "class".
Explanation: a constructor or destructor has been provided for abstract class class, but that is not allowed.
::Simple::Class::VIRTUAL-METHOD-CALLEDMessage: virtual method "method" called.
Explanation: a virtual method method (an abstract class method with no body) has been called, usually from a derived class.
Corrective action: provide an implementation for the method in the derived class.
::Simple::Class::UNDECLAREDMessage: undeclared class "class".
Explanation: class class is undeclared, but a declared class is required.
None.
::Simple::Class::cget ?-debug?Synopsis: gets the package options.
Access mode: public.
Arguments: (flag parsing disabled)
| Argument | Type | Default value/ choices | Description |
| -debug | boolflag | (n/a) | Gets whether to create a debug method for every class |
Returns: the requested option value or the whole list of options if none specified.
::Simple::Class::configure ?-debug extbool?Synopsis: configures the package options.
Access mode: public.
Arguments: (flag parsing disabled)
| Argument | Type | Default value/ choices | Description |
| ?-debug? | extbool | false | Whether to create a debug method for every class |
Returns: the empty string.
declare-class class ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-api string? ?-keywords list? ?-examples string? ?-classtype type? ?-stereotype choice? ?-extends qualifiedname-list? ?-debug extbool? ?-error declaration? ?-variable declaration? ?-attribute declaration? ?-itkoption declaration? ?-itkcomponent declaration? ?-command declaration? ?-method declaration? ?-assumptions string? ?-resources string? ?-limitations string? ?-effects string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-history string? ?-copyright string? ?-body script?(Exported from ::Simple::Class).
Synopsis: declares a class.
Access mode: exported.
This procedure provides a way to declare [incr Tcl] classes and [incr Tk] megawidgets.
The -synopsis flag is mandatory.
The -classtype flag specifies a type whose allowed values are objects of the class. This type can then be used whenever a type is required, such as for the arguments of another class commands or methods.
The -stereotype flag specifies the class stereotype among one of multiobject (the default), abstract or singleton. Multiobject classes support an arbitrary number of objects. Abstract classes support no objects (they are intended to be extended). Finally, singleton classes can be instantiated just once.
The -extends flag specifies the list of classes from which this one inherits.
The -variable flag allows to create class variables (class variables in object-oriented parlance; common variables for [incr Tcl]). Its argument is a variable declaration intended to be the arguments of a call to ::Simple::Variable::declare, except for the added argument -access, whose value must be one of public (the default), protected or private; this argument specifies the variable access mode. This flag can be given multiple times.
The -attribute flag allows to create class attributes (class instance variables in object-oriented parlance; variables for [incr Tcl]). Its argument is an attribute declaration intended to be the arguments of a call to ::Simple::Variable::declare, except for the added argument -access, equivalent to that for class variables, and -configbody, valid for public attributes only, used to specify the attribute configuration script (see the configbody [incr Tcl] command). This flag can be given multiple times.
The -error flag allows to declare class errors. Its argument is an error declaration intended to be the arguments of a call to ::Simple::Error::declare. This flag can be given multiple times.
The -command flag allows to declare class commands (class or static functions in object-oriented parlance; common procedures for [incr Tcl]). Its argument is a command declaration intended to be the arguments of a call to ::Simple::Declare::declare-proc, except for the added argument -access, whose value must be one of public (the default), private, or exported; this argument specifies the command access mode. This flag can be given multiple times.
The -method flag allows to declare class methods (class instance functions or methods in object-oriented parlance; methods for [incr Tcl]). Its argument is a method declaration intended to be the arguments of a call to ::Simple::Declare::declare-proc, except for the fact that -alias is not allowed for methods, and the added argument -access, whose value must be one of public (the default), protected or private; this argument specifies the method access mode. This flag can be given multiple times.
If the method name is constructor, it corresponds to the class constructor. In this case, -synopsis is not allowed (it is hardcoded to "Class constructor"), and the added argument -init, the script used invoke base class constructors, can be specified.
If the method name is destructor, it corresponds to the class destructor. In this case, -synopsis is not allowed (it is hardcoded to "Class destructor"). The destructor default access mode is "private".
The -body flag specifies the class body, a script evaluated when the class is declared.
The -debug flag allows to override the package option of the same name for the class being declared. This option controls whether to create a %debug% debug method. This method has a single argument: a script which gets evaluated in the object scope.
The -itkoption and -itkcomponent flags provide support for the definition of [incr Tk] megawidgets as follows.
The -itkoption flag allows to create options for [incr Tk] megawidgets. Its argument is an [incr Tk] option declaration intended to be the arguments of a call to ::Simple::Variable::declare, except for the added argument -configbody, equivalent to that for attributes, and -resourcename and -resourceclass: see the itk_option define [incr Tk] command. This flag can be given multiple times.
The -itkcomponent flag allows to create components for [incr Tk] megawidgets. Its argument is an [incr Tk] component declaration which shall start by the component name and be followed by the following optional flags (see the itk_component add [incr Tk] command):
-description: the component description.
-access: the component access mode (one of public, protected or private).
-ignore: list of options to ignore for the megawidget; see the ignore command within the itk_component add [incr Tk] command.
-keep: list of options to keep for the megawidget; see the keep command within the itk_component add [incr Tk] command.
-rename: options to rename for the megawidget. Each option is a four-element list; see the rename command within the itk_component add [incr Tk] command.
-resourceclass: resource class.
-body: component body.
The usual command within the itk_component add [incr Tk] command is not supported. The -itkcomponents flag can be given multiple times.
All other arguments are metadata, and are stored or ignored depending on whether The Simple Development Library -storemetadata option is set when the class is declared, but for the -api and -body flags which are never stored.
# The canonical toaster example
declare-class {
Toaster
} -synopsis {
A toaster.
} -overview {
Toaster class with toast and clean methods and a crumb count that
will burn the toaster if too high
} -error {
{
FIRE
} -message {
== FIRE! FIRE! ==
}
} -attribute {
{
crumbs
} -description {
Number of crumbs in the toaster
} -type {
integer
} -value 0
} -method {
{
toast
} -synopsis {
Toast a given number of slices
} -arguments {
{ nSlices integer {Number of slices to toast}}
} -returns {
The number of crumbs after toasting the slices
} -body {
# Too many crumbs
if {$crumbs > 50} {
# Catch fire!
::Simple::Error::throw FIRE
}
# Each toasted slice produces 4 crumbs
incr crumbs [expr {4 * $nSlices}]
# Return the number of crumbs after toasting the slices
return $crumbs
}
} -method {
{
clean
} -synopsis {
Cleans the toaster
} -returns {
The empty string
} -body {
# Remove all the crumbs
set crumbs 0
# Return the empty string
return {}
}
}
declare-class {
SmartToaster
} -synopsis {
A smart toaster
} -overview {
This toaster has an autoclean feature that automatically cleans the
toaster when there are lots of crumbs. How smart!
} -extends {
::Toaster
} -method {
{
toast
} -synopsis {
Performs autoclean if necessary and toast a given number of slices
} -arguments {
{ nSlices integer {Number of slices to toast}}
} -returns {
The number of crumbs after toasting the slices
} -body {
# Lots of crumbs
if {$crumbs > 40} {
# Perform autoclean
clean
}
# Toast the slices
set answer [::Toaster::toast $nSlices]
# Return the number of crumbs after toasting the slices
return $answer
}
}
Arguments: (flag parsing disabled)
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| ?-version? | version | 1.0 | Class version |
| ?-project? | string | (empty string) | Class project |
| ?-synopsis? | string | (empty string) | Class synopsis |
| ?-overview? | string | (empty string) | Class overview |
| ?-usage? | string | (empty string) | Class usage message |
| ?-api? | string | (empty string) | Class API |
| ?-keywords? | list | (empty string) | Class keywords |
| ?-examples? | string | (empty string) | Class usage examples |
| ?-classtype? | type | (n/a) | Class type name |
| ?-stereotype? | choice | multiobject, abstract or singleton | Class stereotype |
| ?-extends? | qualifiedname-list | (empty string) | List of classes from which this one inherits |
| ?-debug? | extbool | false | Whether to create a debug method |
| ?-error? | declaration | (empty string) | Class error declaration |
| ?-variable? | declaration | (empty string) | Class variable declaration |
| ?-attribute? | declaration | (empty string) | Class attribute declaration |
| ?-itkoption? | declaration | (empty string) | [incr Tk] option declaration |
| ?-itkcomponent? | declaration | (empty string) | [incr Tk] component declaration |
| ?-command? | declaration | (empty string) | Class command declaration |
| ?-method? | declaration | (empty string) | Class method declaration |
| ?-assumptions? | string | (empty string) | Class assumptions |
| ?-resources? | string | (empty string) | Class required resources |
| ?-limitations? | string | (empty string) | Class limitations |
| ?-effects? | string | (empty string) | Class effects |
| ?-details? | string | (empty string) | Class implementation details |
| ?-references? | string | (empty string) | Class references |
| ?-remarks? | string | (empty string) | Class remarks |
| ?-todo? | string | (empty string) | Class to do list |
| ?-history? | string | (empty string) | Class history |
| ?-copyright? | string | (empty string) | Class copyright notice |
| ?-body? | script | (empty string) | Class body |
Returns: the empty string.
Effects:
Creates a class named class.
Creates the class commands, which may be exported or have an alias.
Creates a public %debug% debug method if -debug is given or the package option of the same name is set.
Creates a private create-components method if at least one [incr Tk] component is given. This method should be invoked by each megawidget object (for example from the megawidget constructor) to create the megawidget components.
Those of the class body.
Each declared class metadata is stored in a class private variable named %Metadata%.
Each declared class list of exported commands is stored in a class private variable named %ExportedCommands%.
Each declared class list of command aliases is stored in a class private variable named %Aliases%.
The ::Simple::Class::delete procedure.
The order of the flags is irrelevant.
::Simple::Class::delete classSynopsis: deletes an [incr Tcl] class.
Access mode: public.
This procedure deletes the given class together with its class type, if any.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the empty string.
Effects:
Deletes the given class and its class type, if any.
The declare-class procedure.
::Simple::Class::information aliases classSynopsis: returns a class list of aliases.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class list of aliases.
The ::Simple::Package::information aliases command.
::Simple::Class::information api classSynopsis: returns a class public API signature.
Access mode: public.
This procedure returns a string containing a class public API signatures.
The class public and exported commands are included, as well as the public constructor, public destructor and public methods.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the given class public API signatures as follows:
(extends <class list>) Class constructor: <class 1 constructor API> Class destructor: <class 1 destructor API> Class commands: <class 1 command 1 API> <class 1 command 2 API> ... Class methods: <class 1 method 1 API> <class 1 method 2 API> ...
The ::Simple::Package::information api command.
The ::Simple::Class::information commands command.
The ::Simple::Class::information methods command.
The returned list does not contain base methods.
The returned list does not contain methods with a percent sign in its name are those are assumed to be internal to The Simple Development Library.
::Simple::Class::information attributes class ?-access choice?Synopsis: returns a class list of attributes matching the given access level.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| ?-access? | choice | public, protected or private | Attributes access mode |
Returns: the class list of attributes matching the given access level.
::Simple::Class::information classes ?pattern?Synopsis: returns the list of classes matching the pattern.
Access mode: public.
This procedure wraps the ::itcl::find classes [incr Tcl] command. The following is an excerpt from that command manual page:
This procedure returns a list of classes. Classes in the current namespace are listed first, followed by classes in all other namespaces in the interpreter. If the optional pattern is specified, then only those classes whose name match the pattern are returned.
If a class resides in the current namespace context, this command reports its unqualified. However, if the pattern contains namespace qualifiers, or if the class resides in another context, this command reports its qualified name.
Arguments:
| Argument | Type | Default value/ choices | Description |
| ?pattern? | pattern | (empty string) | Pattern |
Returns: the list of classes matching the pattern.
The ::itcl::find classes [incr Tcl] command.
The itcl_info classes [incr Tcl] command.
::Simple::Class::information commands classSynopsis: returns a class current list of public and exported commands.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class current list of public and exported commands.
The ::Simple::Package::information api command.
The ::Simple::Package::information commands command.
The ::Simple::Class::information methods command.
The returned list does not contain base commands.
The returned list does not contain commands with a percent sign in its name are those are assumed to be internal to The Simple Development Library.
::Simple::Class::information errors classSynopsis: returns a class list of errors.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class list of errors.
::Simple::Class::information exists classSynopsis: returns whether a class exists.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: whether the given class exists.
::Simple::Class::information exportedcommands classSynopsis: returns a class list of exported commands.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class list of exported commands.
The ::Simple::Package::information exportedcommands command.
::Simple::Class::information itkcomponents classSynopsis: returns a class list of [incr Tk] components.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class list of [incr Tk] components.
::Simple::Class::information itkoptions classSynopsis: returns a class list of [incr Tk] options.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class list of [incr Tk] options.
::Simple::Class::information metadata classSynopsis: returns a class metadata.
Access mode: public.
This procedure returns a list of pairs suitable to be given as argument to the array set command. Each element is one of the flags given to declare-class upon class declaration (with no hypen), but for the -api and -body flags (which are not stored), and the item declarations (-error, -variable, -attribute, -itkoption, -itkcomponent, -command and -method); these are obtained using the corresponding ::Simple::Class::information subcommand.
Thus, the actual list of flags is: -version, -project, -synopsis, -overview, -usage, -keywords, -examples, -classtype, -stereotype, -extends, -assumptions, -resources, -limitations, -effects, -details, -references, -remarks, -todo, -history and -copyright.
Notice that no data is returned unless The Simple Development Library -storemetadata option is set when the class is declared.
If a particular flag was not given in the class declaration, the empty string is returned as that flag contents.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class metadata as an item/contents pairs list.
::Simple::Class::information methods classSynopsis: returns a class current list of public methods.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
Returns: the class current list of public methods.
The ::Simple::Package::information api command.
The ::Simple::Package::information commands command.
The returned list does not contain base methods.
The returned list does not contain methods with a percent sign in its name are those are assumed to be internal to The Simple Development Library.
::Simple::Class::information objects ?-class name? ?-isa name? ?pattern?Synopsis: returns the list of objects matching the pattern.
Access mode: public.
This procedure wraps the ::itcl::find classes [incr Tcl] command. The order of the arguments is different due to a limitation in The Simple Development Library (and Tcl) which forces the optional arguments to be the last ones. The following is an excerpt from that command manual page:
This procedure returns a list of objects. Objects in the current namespace are listed first, followed by objects in all other namespaces in the interpreter. If the optional pattern is specified, then only those objects whose name match the pattern are returned.
If the optional -class flag is given, this list is restricted to objects whose most-specific class is the one given as parameter to that flag. If the -isa flag is given, this list is further restricted to objects having the class given as paramter to that flag anywhere in their heritage.
If an object resides in the current namespace context, this command reports its unqualified name. However, if the pattern contains namespace qualifiers, or if the object resides in another context, this command reports its fully-qualified name.
Arguments:
| Argument | Type | Default value/ choices | Description |
| ?-class? | name | (n/a) | Class name |
| ?-isa? | name | (n/a) | Base class name |
| ?pattern? | pattern | (empty string) | Pattern |
Returns: the list of objects matching the pattern.
The ::itcl::find objects [incr Tcl] command.
The itcl_info objects [incr Tcl] command.
::Simple::Class::information variables class ?-access choice?Synopsis: returns a class list of variables matching the given access level.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| ?-access? | choice | public, protected or private | Variables access mode |
Returns: the class list of variables matching the given access level.
::Simple::ItkComponent::information access class itkcomponentSynopsis: returns an [incr Tk] component access mode.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkcomponent | unqualifiedname | (n/a) | [incr Tk] component |
Returns: the [incr Tk] component access mode.
::Simple::ItkComponent::information description class itkcomponentSynopsis: returns an [incr Tk] component description.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkcomponent | unqualifiedname | (n/a) | [incr Tk] component |
Returns: the [incr Tk] component description.
::Simple::ItkComponent::information ignore class itkcomponentSynopsis: returns an [incr Tk] component list of ignored options.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkcomponent | unqualifiedname | (n/a) | [incr Tk] component |
Returns: the [incr Tk] component list of ignored options.
::Simple::ItkComponent::information keep class itkcomponentSynopsis: returns an [incr Tk] component list of kept options.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkcomponent | unqualifiedname | (n/a) | [incr Tk] component |
Returns: the [incr Tk] component list of kept options.
::Simple::ItkComponent::information rename class itkcomponentSynopsis: returns an [incr Tk] component list of renamed options.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkcomponent | unqualifiedname | (n/a) | [incr Tk] component |
Returns: the [incr Tk] component list of renamed options.
::Simple::ItkComponent::information resourceclass class itkcomponentSynopsis: returns an [incr Tk] component resource class.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkcomponent | unqualifiedname | (n/a) | [incr Tk] component |
Returns: the [incr Tk] component resource class.
::Simple::ItkOption::information choices class itkoptionSynopsis: returns an [incr Tk] option choices.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: the [incr Tk] option choices.
::Simple::ItkOption::information default class itkoptionSynopsis: returns an [incr Tk] option default value.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: the [incr Tk] option default value.
The ::Simple::Variable::information default procedure.
The ::Simple::Option::information default procedure.
::Simple::ItkOption::information defaultgiven class itkoptionSynopsis: returns whether an [incr Tk] option has a default value.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: whether the [incr Tk] option has a default value.
The ::Simple::Variable::information defaultgiven procedure.
The ::Simple::Option::information defaultgiven procedure.
::Simple::ItkOption::information description class itkoptionSynopsis: returns an [incr Tk] option description.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: the [incr Tk] option description.
::Simple::ItkOption::information monitortype class itkoptionSynopsis: returns whether an [incr Tk] option is being monitored.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: whether an [incr Tk] option is being monitored.
The ::Simple::Variable::information monitortype procedure.
::Simple::ItkOption::information resourceclass class itkoptionSynopsis: returns an [incr Tk] option resource class.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: the [incr Tk] option resource class.
::Simple::ItkOption::information resourcename class itkoptionSynopsis: returns an [incr Tk] option resource name.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: the [incr Tk] option resource name.
::Simple::ItkOption::information type class itkoptionSynopsis: returns an [incr Tk] option type.
Access mode: public.
Arguments:
| Argument | Type | Default value/ choices | Description |
| class | name | (n/a) | Class name |
| itkoption | flag | (n/a) | [incr Tk] option |
Returns: the [incr Tk] option type.