2
'\" Generated from file '/home/aku/Projects/Packages/Critcl/dev-master/embedded/man/files/critcl_class\&.n' by tcllib/doctools with format 'nroff'
3
'\" Copyright (c) 2011-2012 Andreas Kupries
5
'\" The definitions below are for supplemental macros used in Tcl/Tk
8
'\" .AP type name in/out ?indent?
9
'\" Start paragraph describing an argument to a library procedure.
10
'\" type is type of argument (int, etc.), in/out is either "in", "out",
11
'\" or "in/out" to describe whether procedure reads or modifies arg,
12
'\" and indent is equivalent to second arg of .IP (shouldn't ever be
13
'\" needed; use .AS below instead)
16
'\" Give maximum sizes of arguments for setting tab stops. Type and
17
'\" name are examples of largest possible arguments that will be passed
18
'\" to .AP later. If args are omitted, default tab stops are used.
21
'\" Start box enclosure. From here until next .BE, everything will be
22
'\" enclosed in one large box.
25
'\" End of box enclosure.
28
'\" Begin code excerpt.
33
'\" .VS ?version? ?br?
34
'\" Begin vertical sidebar, for use in marking newly-changed parts
35
'\" of man pages. The first argument is ignored and used for recording
36
'\" the version when the .VS was added, so that the sidebars can be
37
'\" found and removed when they reach a certain age. If another argument
38
'\" is present, then a line break is forced before starting the sidebar.
41
'\" End of vertical sidebar.
44
'\" Begin an indented unfilled display.
47
'\" End of indented unfilled display.
50
'\" Start of list of standard options for a Tk widget. The
51
'\" options follow on successive lines, in four columns separated
55
'\" End of list of standard options for a Tk widget.
57
'\" .OP cmdName dbName dbClass
58
'\" Start of description of a specific option. cmdName gives the
59
'\" option's name as specified in the class command, dbName gives
60
'\" the option's name in the option database, and dbClass gives
61
'\" the option's class in the option database.
64
'\" Print arg1 underlined, then print arg2 normally.
66
'\" RCS: @(#) $Id: man.macros,v 1.1 2009/01/30 04:56:47 andreas_kupries Exp $
68
'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
72
'\" # Start an argument description
76
. ie !"\\$2"" .TP \\n()Cu
81
\&\\$1 \\fI\\$2\\fP (\\$3)
94
'\" # define tabbing values for .AP
97
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
100
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
101
.nr )C \\n()Bu+\\w'(in/out)'u+2n
103
.AS Tcl_Interp Tcl_CreateInterp in/out
104
'\" # BS - start boxed text
105
'\" # ^y = starting y location
113
.if n \l'\\n(.lu\(ul'
116
'\" # BE - end boxed text (draw box now)
121
.ie n \l'\\n(^lu\(ul'
123
.\" Draw four-sided box normally, but don't draw top of
124
.\" box if the box started on an earlier page.
126
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
129
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
136
'\" # VS - start vertical sidebar
137
'\" # ^Y = starting y location
138
'\" # ^v = 1 (for troff; for nroff this doesn't matter)
142
.ie n 'mc \s12\(br\s0
145
'\" # VE - end of vertical sidebar
153
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
160
'\" # Special macro to handle page bottom: finish off current
161
'\" # box/sidebar if in box/sidebar mode, then invoked standard
162
'\" # page bottom macro.
169
.\" Draw three-sided box if this is the box's first page,
170
.\" draw two sides but no top otherwise.
171
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
172
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
175
.nr ^x \\n(^tu+1v-\\n(^Yu
176
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
189
'\" # DS - begin display
195
'\" # DE - end display
201
'\" # SO - start of list of standard options
203
.SH "STANDARD OPTIONS"
209
'\" # SE - end of list of standard options
214
See the \\fBoptions\\fR manual entry for details on the standard options.
216
'\" # OP - start of full description for a single option
221
Command-Line Name: \\fB\\$1\\fR
222
Database Name: \\fB\\$2\\fR
223
Database Class: \\fB\\$3\\fR
227
'\" # CS - begin code excerpt
233
'\" # CE - end code excerpt
241
.TH "critcl::class" n 1\&.0\&.6 doc "C Runtime In Tcl (CriTcl)"
244
critcl::class \- CriTcl Utilities: C Classes
246
package require \fBTcl 8\&.4\fR
248
package require \fBcritcl ?3\&.1\&.6?\fR
250
package require \fBcritcl::class ?1\&.0\&.6?\fR
252
\fB::critcl::class::define\fR \fIname\fR \fIscript\fR
254
\fBinclude\fR \fIpath\fR
256
\fBsupport\fR \fIcode\fR
258
\fBtype\fR \fIname\fR
260
\fBclassconstructor\fR \fIbody\fR
262
\fBclassdestructor\fR \fIbody\fR
264
\fBconstructor\fR \fIbody\fR ?\fIpostbody\fR?
266
\fBdestructor\fR \fIbody\fR
268
\fBclassvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
270
\fBclassmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
272
\fBclassmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
274
\fBclassmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
276
\fBinsvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
278
\fBmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
280
\fBmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
282
\fBmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
284
\fBmethod_introspection\fR
289
Welcome to the \fIC Runtime In Tcl\fR, \fICriTcl\fR for short, a
290
system to build C extension packages for Tcl on the fly, from C code
291
embedded within Tcl scripts, for all who wish to make their code go
294
This document is the reference manpage for the \fBcritcl::class\fR
295
package\&. This package provides convenience commands for advanced
296
functionality built on top of the core\&.
298
With it a user wishing to create a C level object with class
299
and instance commands can concentrate on specifying the class- and
300
instance-variables and -methods in a manner similar to a TclOO class,
301
while all the necessary boilerplate around it is managed by this
304
Its intended audience are mainly developers wishing to write
305
Tcl packages with embedded C code\&.
307
This package resides in the Core Package Layer of CriTcl\&.
335
\fB::critcl::class::define\fR \fIname\fR \fIscript\fR
336
This is the main command to define a new class \fIname\fR, where
337
\fIname\fR is the name of the Tcl command representing the class,
338
i\&.e\&. the \fIclass command\fR\&. The \fIscript\fR provides the
339
specification of the class, i\&.e\&. information about included headers,
340
class- and instance variables, class- and instance-methods, etc\&.
341
See the section \fBClass Specification API\fR below for the
342
detailed list of the available commands and their semantics\&.
344
.SH "CLASS SPECIFICATION API"
345
Here we documents all class specification commands available inside of
346
the class definition script argument of \fB::critcl::class::define\fR\&.
347
.SS "GENERAL CONFIGURATION"
349
\fBinclude\fR \fIpath\fR
350
This command specifies the path of a header file to include within the
351
code generated for the class\&. This is separate from the \fBsupport\fR
352
because the generated include directives will be put at the very
353
beginning of the generated code\&. This is done to allow the use of the
354
imported declarations within the instance type, and elsewhere\&.
356
The command can be used multiple times, each adding a header to
357
include\&. It is of course possible to not use this command at all, for
358
classing not making use of external definitions\&.
360
The result of the command is the empty string\&.
362
\fBsupport\fR \fIcode\fR
363
This command specifies supporting C code, i\&.e\&. any definitions (types,
364
functions, etc\&.) needed by the \fIwhole\fR class and not fitting into
365
class- and instance-methods\&. The code is embedded at global level,
366
outside of any function or other definition\&.
368
The command can be used multiple times, each adding another
369
segment of C code to insert\&. It is of course possible to not use this
370
command at all, for classes not requiring swupporting code\&.
372
The result of the command is the empty string\&.
374
\fBtype\fR \fIname\fR
375
This command specifies the name of an external C type to be used as
376
the type of the instance structure\&.
378
Initialization and release of the structure with the given type
379
are the responsibility of the user, through \fBconstructor\fR and
380
\fBdestructor\fR code fragments\&.
382
\fIAttention:\fR Using this command precludes the use of
383
regular class- and instance variables\&. It further precludes the use of
384
\fBmethod-introspection\fR as well, as this make use of generated
385
instance-variables\&.
387
If class- and/or instance-variable have to be used in
388
conjunction with an external C type, simply create and use a class- or
389
instance-variable with that type\&.
391
The result of the command is the empty string\&.
393
.SS "CLASS LIFETIME MANAGEMENT"
395
\fBclassconstructor\fR \fIbody\fR
396
This command specifies a C code block surrounding the initialization
397
of the class variables, i\&.e\&. the fields of the class structure\&.
398
\fINote\fR that allocation and release of the class structure itself
399
is done by the system andf not the responsibility of the user\&.
401
For the initialization (and release) of a class variable it is
402
recommended to use the \fIconstructor\fR and \fIdestructor\fR
403
arguments of the variable's definition (See command
404
\fBclassvariable\fR) for this instead of using a separate
405
\fBclassconstructor\fR\&.
407
This is an optional command\&. Using it more than once is allowed
408
too and each use will add another C code fragment to use during
409
construction\&. I\&.e\&. multiple calls aggregate\&.
411
The C code blocks of multiple calls (including the constructors
412
of classvariable definitions) are executed in order of specification\&.
414
The result of the command is the empty string\&.
416
The C code in \fIbody\fR has access to the following
421
Pointer to the Tcl interpreter (Tcl_Interp*) the
422
class structure will be associated with\&. It enables the generation
423
of a Tcl error message should construction fail\&.
426
Pointer to the class structure to initialize\&.
429
A C code label the constructor can jump to should it have
430
to signal a construction failure\&. It is the responsibility of the
431
constructor to release any variables already initialized before
432
jumping to this label\&. This also why the 'execution in order of
433
specification' is documented and can be relied on\&. It gives us the
434
knowledge which other constructors have already been run and
435
initialized what other fields\&.
438
\fBclassdestructor\fR \fIbody\fR
439
This command specifies a C code block surrounding the release of the
440
class variables, i\&.e\&. the fields of the class structure\&.
441
\fINote\fR that allocation and release of the class structure itself
442
is done by the system and not the responsibility of the user\&.
444
For the initialization (and release) of a class variable it is
445
recommended to use the \fIconstructor\fR and \fIdestructor\fR
446
arguments of the variable's definition (See command
447
\fBclassvariable\fR) for this instead of using a separate
448
\fBclassconstructor\fR\&.
450
This is an optional command\&. Using it more than once is allowed
451
too and each use will add another C code fragment to use during
452
construction\&. I\&.e\&. multiple calls aggregate\&.
454
The C code blocks of multiple calls (including the constructors
455
of class variable definitions) are executed in order of specification\&.
457
The result of the command is the empty string\&.
459
The C code in \fIbody\fR has access to the same
460
environment as the class constructor code blocks\&.
462
.SS "INSTANCE LIFETIME MANAGEMENT"
464
\fBconstructor\fR \fIbody\fR ?\fIpostbody\fR?
465
This command specifies a C code block surrounding the initialization
466
of the instance variables, i\&.e\&. the fields of the instance structure\&.
467
\fINote\fR that allocation and release of the instance structure
468
itself is done by the system and not the responsibility of the user\&.
469
\fIOn the other hand\fR, if an external \fBtype\fR was specified
470
for the instance structure, then instance variables are not possible,
471
and the system has no knowledge of the type's structure\&. In that case
472
it is the responsibility of the \fIbody\fR to allocate and free the
473
structure itself too\&.
475
For the initialization (and release) of an instance variable it
476
is recommended to use the \fIconstructor\fR and \fIdestructor\fR
477
arguments of the variable's definition (See command \fBinsvariable\fR)
478
for this instead of using a separate \fBconstructor\fR\&.
480
This is an optional command\&. Using it more than once is allowed
481
too and each use will add another C code fragment to use during
482
construction\&. I\&.e\&. multiple calls aggregate\&.
484
The C code blocks of multiple calls (including the constructors
485
of instance variable definitions) are executed in order of specification\&.
487
The result of the command is the empty string\&.
489
The C code in \fIbody\fR has access to the following
494
Pointer to the Tcl interpreter (Tcl_Interp*) the
495
instance structure will be associated with\&. It enables the generation
496
of a Tcl error message should construction fail\&.
499
Pointer to the instance structure to initialize\&.
502
A C code label the constructor can jump to should it have
503
to signal a construction failure\&. It is the responsibility of the
504
constructor to release any variables already initialized before
505
jumping to this label\&. This also why the 'execution in order of
506
specification' is documented and can be relied on\&. It gives us the
507
knowledge which other constructors have already been run and
508
initialized what other fields\&.
511
The C code in \fIpostbody\fR is responsible construction action
512
to be done after the primary construction was done and the Tcl-level
513
instance command was successfully created\&. It has access to a slightly
514
different environment:
518
Pointer to the Tcl interpreter (Tcl_Interp*) the
519
instance structure will be associated with\&. It enables the generation
520
of a Tcl error message should construction fail\&.
523
Pointer to the instance structure to initialize\&.
526
The Tcl_Command token of the Tcl-level instance
530
The fully qualified name of the instance command,
531
stored in a Tcl_Obj*\&.
534
\fBdestructor\fR \fIbody\fR
535
This command specifies a C code block surrounding the release of the
536
instance variables, i\&.e\&. the fields of the instance structure\&.
537
\fINote\fR that allocation and release of the instance structure
538
itself is done by the system and not the responsibility of the user\&.
539
\fIOn the other hand\fR, if an external \fBtype\fR was specified
540
for the instance structure, then instance variables are not possible,
541
and the system has no knowledge of the type's structure\&. In that case
542
it is the responsibility of the \fIbody\fR to allocate and free the
543
structure itself too\&.
545
For the initialization (and release) of an instance variable it
546
is recommended to use the \fIconstructor\fR and \fIdestructor\fR
547
arguments of the variable's definition (See command \fBinsvariable\fR)
548
for this instead of using a separate \fBconstructor\fR\&.
550
This is an optional command\&. Using it more than once is allowed
551
too and each use will add another C code fragment to use during
552
construction\&. I\&.e\&. multiple calls aggregate\&.
554
The C code blocks of multiple calls (including the constructors
555
of instance variable definitions) are executed in order of specification\&.
557
The result of the command is the empty string\&.
559
The C code in \fIbody\fR has access to the following
564
Pointer to the instance structure to release\&.
567
.SS "CLASS VARIABLES AND METHODS"
569
\fBclassvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
570
This command specifies a field in the class structure of the class\&.
571
Multiple fields can be specified, and are saved in the order
574
\fIAttention:\fR Specification of a class variable precludes
575
the use of an external C \fBtype\fR for the instance structure\&.
577
\fIAttention:\fR Specification of a class variable
578
automatically causes the definition of an instance variable named
579
\fBclass\fR, pointing to the class structure\&.
581
Beyond the basic \fIname\fR and C type of the new variable the
582
definition may also contain a \fIcomment\fR describing it, and C code
583
blocks to initialize and release the variable\&.
584
These are effectively local forms of the commands
585
\fBclassconstructor\fR and \fBclassdestructor\fR\&. Please read their
586
descriptions for details regarding the C environment available to the
589
The comment, if specified will be embedded into the generated C
590
code for easier cross-referencing from generated "\fI\&.c\fR" file to
591
class specification\&.
593
\fBclassmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
594
This command specifies a class method and the C code block
595
implementing its functionality\&. This is the first of three forms\&. The
596
method is specified like a \fBcritcl::ccommand\fR, with a fixed set of
597
C-level arguments\&. The \fIbody\fR has to perform everything
598
(i\&.e\&. argument extraction, checking, result return, and of course the
599
actual functionality) by itself\&.
601
For this the \fIbody\fR has access to
605
Pointer to the class structure\&.
608
Pointer to the Tcl interpreter (Tcl_Interp*) the
609
class structure is associated with
612
The number of method arguments\&.
615
The method arguments, as C array of Tcl_Obj pointers\&.
618
The \fIarguments\fR of the definition are only a human readable form
619
of the method arguments and syntax and are not used in the C code,
620
except as comments put into the generated code\&. Again, it is the
621
responsibility of the \fIbody\fR to check the number of arguments,
622
extract them, check their types, etc\&.
624
\fBclassmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
625
This command specifies a class method and the C code block
626
implementing its functionality\&. This is the second of three forms\&. The
627
method is specified like a \fBcritcl::cproc\fR\&.
628
Contrary to the first variant here the \fIarguments\fR are computer
629
readable, expected to be in the same format as the \fIarguments\fR of
630
\fBcritcl::cproc\fR\&. The same is true for the \fIresulttype\fR\&.
631
The system automatically generates a wrapper doing argument checking
632
and conversion, and result conversion, like for \fBcritcl::cproc\fR\&.
634
The \fIbody\fR has access to
638
Pointer to the class structure\&.
641
Pointer to the Tcl interpreter (Tcl_Interp*) the
642
class structure is associated with
645
All \fIarguments\fR under their specified names and C types
646
as per their definition\&.
649
\fBclassmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
650
This command specifies a class method and the C code block
651
implementing its functionality\&. This is the third and last of three
654
The class method is implemented by the external function
655
\fIfunname\fR, i\&.e\&. a function which is declared outside of the class
656
code itself, or in a \fBsupport\fR block\&.
658
It is assumed that the first four arguments of that function
659
represent the parameters
663
Pointer to the class structure\&.
666
Pointer to the Tcl interpreter (Tcl_Interp*) the
667
class structure is associated with
670
The number of method arguments\&.
673
The method arguments, as C array of Tcl_Obj pointers\&.
676
Any additional arguments specified will be added after these and are
677
passed into the C code as is, i\&.e\&. are considered to be C expressions\&.
679
.SS "INSTANCE VARIABLES AND METHODS"
681
\fBinsvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
682
This command specifies a field in the instance structure of the class\&.
683
Multiple fields can be specified, and are saved in the order
686
\fIAttention:\fR Specification of an instance variable
687
precludes the use of an external C \fBtype\fR for the instance
690
\fIAttention:\fR Specification of an instance variable
691
automatically causes the definition of an instance variable of type
692
\fBTcl_Command\fR, and named \fBcmd\fR, holding the token of the
693
instance command, and the definition of an instance method named
694
\fBdestroy\fR\&. This implicit instance variable is managed by the
697
Beyond the basic \fIname\fR and C type of the new variable the
698
definition may also contain a \fIcomment\fR describing it, and C code
699
blocks to initialize and release the variable\&.
700
These are effectively local forms of the commands \fBconstructor\fR
701
and \fBdestructor\fR\&. Please read their descriptions for details
702
regarding the C environment available to the code\&.
704
The comment, if specified will be embedded into the generated C
705
code for easier cross-referencing from generated "\fI\&.c\fR" file to
706
class specification\&.
708
\fBmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
709
This command specifies an instance method and the C code block
710
implementing its functionality\&. This is the first of three forms\&. The
711
method is specified like a \fBcritcl::ccommand\fR, with a fixed set of
712
C-level arguments\&. The \fIbody\fR has to perform everything
713
(i\&.e\&. argument extraction, checking, result return, and of course the
714
actual functionality) by itself\&.
716
For this the \fIbody\fR has access to
720
Pointer to the instance structure\&.
723
Pointer to the Tcl interpreter (Tcl_Interp*) the
724
instance structure is associated with
727
The number of method arguments\&.
730
The method arguments, as C array of Tcl_Obj pointers\&.
733
The \fIarguments\fR of the definition are only a human readable form
734
of the method arguments and syntax and are not used in the C code,
735
except as comments put into the generated code\&. Again, it is the
736
responsibility of the \fIbody\fR to check the number of arguments,
737
extract them, check their types, etc\&.
739
\fBmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
740
This command specifies an instance method and the C code block
741
implementing its functionality\&. This is the second of three
742
forms\&. The method is specified like a \fBcritcl::cproc\fR\&.
743
Contrary to the first variant here the \fIarguments\fR are computer
744
readable, expected to be in the same format as the \fIarguments\fR of
745
\fBcritcl::cproc\fR\&. The same is true for the \fIresulttype\fR\&.
746
The system automatically generates a wrapper doing argument checking
747
and conversion, and result conversion, like for \fBcritcl::cproc\fR\&.
749
The \fIbody\fR has access to
753
Pointer to the instance structure\&.
756
Pointer to the Tcl interpreter (Tcl_Interp*) the
757
instance structure is associated with
760
All \fIarguments\fR under their specified names and C types
761
as per their definition\&.
764
\fBmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
765
This command specifies an instance method and the C code block
766
implementing its functionality\&. This is the third and last of three
769
The instance method is implemented by the external function
770
\fIfunname\fR, i\&.e\&. a function which is declared outside of the instance
771
code itself, or in a \fBsupport\fR block\&.
773
It is assumed that the first four arguments of that function
774
represent the parameters
778
Pointer to the instance structure\&.
781
Pointer to the Tcl interpreter (Tcl_Interp*) the
782
instance structure is associated with
785
The number of method arguments\&.
788
The method arguments, as C array of Tcl_Obj pointers\&.
791
Any additional arguments specified will be added after these and are
792
passed into the C code as is, i\&.e\&. are considered to be C expressions\&.
794
\fBmethod_introspection\fR
795
This command generates one class- and one instance-method both of
796
which will return a list of the instance methods of the class, and
797
supporting structures, like the function to compute the information,
798
and a class variable caching it\&.
800
The two methods and the class variable are all named
803
.SS "CONTEXT DEPENDENT INTERACTIONS"
804
This section documents the various interactions between the
805
specification commands\&. While these are are all documented with the
806
individual commands here they are pulled together to see at a glance\&.
808
If you are using the command \fBtype\fR to specify an external
809
C type to use for the instance structure you are subject to
810
the following constraints and rules:
813
You cannot define your own instance variables\&.
815
You cannot define your own class variables\&.
817
You cannot use \fBmethod_introspection\fR\&.
819
You have to allocate and release the instance structure on your
820
own, through \fBconstructor\fR and \fBdestructor\fR code blocks\&.
823
If you declare class variables you are subject to the
824
following constraints and rules:
827
You cannot use \fBtype\fR\&.
829
The system generates an instance variable \fBclass\fR for
830
you, which points from instance to class structure\&. This makes
831
you also subject to the rules below, for instance variables\&.
834
If you declare instance variables (possibly automatic, see
835
above) you are subject to following constraints and rules:
838
You cannot use \fBtype\fR\&.
840
The system generates and manages an instance variable
841
\fBcmd\fR for you, which holds the Tcl_Command token
842
of the instance command\&.
844
The system generates an instance method \fBdestroy\fR for
847
The system manages allocation and release of the instance
848
structure for you\&. You have to care only about the instance
849
variables themselves\&.
853
The example shown below is the specification of queue data structure,
854
with most of the method implementations and support code omitted to
855
keep the size down\&.
857
The full implementation can be found in the directory
858
"\fIexamples/queue\fR" of the critcl source distribution/repository\&.
862
package require Tcl 8\&.4
863
package require critcl 3\&.1
865
critcl::buildrequirement {
866
package require critcl::class ; # DSL, easy spec of Tcl class/object commands\&.
869
critcl::cheaders util\&.h
871
critcl::class::define ::queuec {
874
insvariable Tcl_Obj* unget {
875
List object unget elements
877
instance->unget = Tcl_NewListObj (0,NULL);
878
Tcl_IncrRefCount (instance->unget);
880
Tcl_DecrRefCount (instance->unget);
883
insvariable Tcl_Obj* queue {
884
List object holding the main queue
886
instance->queue = Tcl_NewListObj (0,NULL);
887
Tcl_IncrRefCount (instance->queue);
889
Tcl_DecrRefCount (instance->queue);
892
insvariable Tcl_Obj* append {
893
List object holding new elements
895
instance->append = Tcl_NewListObj (0,NULL);
896
Tcl_IncrRefCount (instance->append);
898
Tcl_DecrRefCount (instance->append);
902
Index of next element to return from the main queue
907
support {\&.\&.\&. queue_peekget, queue_size, etc\&.}
909
method clear {} {\&.\&.\&.}
910
method destroy {\&.\&.\&.}
912
method get as queue_peekget 1
913
method peek as queue_peekget 0
915
method put {item \&.\&.\&.}
919
Tcl_WrongNumArgs (interp, 2, objv, NULL);
923
Tcl_SetObjResult (interp, Tcl_NewIntObj (queue_size (instance, NULL, NULL, NULL)));
927
method unget {item} {\&.\&.\&.}
930
package provide queuec 1
935
.SH "BUGS, IDEAS, FEEDBACK"
936
This document, and the package it describes, will undoubtedly contain
937
bugs and other problems\&.
938
Please report such at \fIhttps://github\&.com/andreas-kupries/critcl\fR\&.
939
Please also report any ideas for enhancements you may have for either
940
package and/or documentation\&.
942
C class, C code, C instance, C object, Embedded C Code, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, generate package, linker, on demand compilation, on-the-fly compilation
944
Glueing/Embedded C code
947
Copyright (c) 2011-2012 Andreas Kupries
b'\\ No newline at end of file'