~ubuntu-branches/ubuntu/utopic/critcl/utopic

« back to all changes in this revision

Viewing changes to embedded/man/files/critcl_class.n

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura
  • Date: 2013-05-11 00:08:06 UTC
  • Revision ID: package-import@ubuntu.com-20130511000806-7hq1zc3fnn0gat79
Tags: upstream-3.1.9
ImportĀ upstreamĀ versionĀ 3.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'\"
 
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
 
4
'\"
 
5
'\" The definitions below are for supplemental macros used in Tcl/Tk
 
6
'\" manual entries.
 
7
'\"
 
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)
 
14
'\"
 
15
'\" .AS ?type? ?name?
 
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.
 
19
'\"
 
20
'\" .BS
 
21
'\"     Start box enclosure.  From here until next .BE, everything will be
 
22
'\"     enclosed in one large box.
 
23
'\"
 
24
'\" .BE
 
25
'\"     End of box enclosure.
 
26
'\"
 
27
'\" .CS
 
28
'\"     Begin code excerpt.
 
29
'\"
 
30
'\" .CE
 
31
'\"     End code excerpt.
 
32
'\"
 
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.
 
39
'\"
 
40
'\" .VE
 
41
'\"     End of vertical sidebar.
 
42
'\"
 
43
'\" .DS
 
44
'\"     Begin an indented unfilled display.
 
45
'\"
 
46
'\" .DE
 
47
'\"     End of indented unfilled display.
 
48
'\"
 
49
'\" .SO
 
50
'\"     Start of list of standard options for a Tk widget.  The
 
51
'\"     options follow on successive lines, in four columns separated
 
52
'\"     by tabs.
 
53
'\"
 
54
'\" .SE
 
55
'\"     End of list of standard options for a Tk widget.
 
56
'\"
 
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.
 
62
'\"
 
63
'\" .UL arg1 arg2
 
64
'\"     Print arg1 underlined, then print arg2 normally.
 
65
'\"
 
66
'\" RCS: @(#) $Id: man.macros,v 1.1 2009/01/30 04:56:47 andreas_kupries Exp $
 
67
'\"
 
68
'\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
 
69
.if t .wh -1.3i ^B
 
70
.nr ^l \n(.l
 
71
.ad b
 
72
'\"     # Start an argument description
 
73
.de AP
 
74
.ie !"\\$4"" .TP \\$4
 
75
.el \{\
 
76
.   ie !"\\$2"" .TP \\n()Cu
 
77
.   el          .TP 15
 
78
.\}
 
79
.ta \\n()Au \\n()Bu
 
80
.ie !"\\$3"" \{\
 
81
\&\\$1  \\fI\\$2\\fP    (\\$3)
 
82
.\".b
 
83
.\}
 
84
.el \{\
 
85
.br
 
86
.ie !"\\$2"" \{\
 
87
\&\\$1  \\fI\\$2\\fP
 
88
.\}
 
89
.el \{\
 
90
\&\\fI\\$1\\fP
 
91
.\}
 
92
.\}
 
93
..
 
94
'\"     # define tabbing values for .AP
 
95
.de AS
 
96
.nr )A 10n
 
97
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
 
98
.nr )B \\n()Au+15n
 
99
.\"
 
100
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
 
101
.nr )C \\n()Bu+\\w'(in/out)'u+2n
 
102
..
 
103
.AS Tcl_Interp Tcl_CreateInterp in/out
 
104
'\"     # BS - start boxed text
 
105
'\"     # ^y = starting y location
 
106
'\"     # ^b = 1
 
107
.de BS
 
108
.br
 
109
.mk ^y
 
110
.nr ^b 1u
 
111
.if n .nf
 
112
.if n .ti 0
 
113
.if n \l'\\n(.lu\(ul'
 
114
.if n .fi
 
115
..
 
116
'\"     # BE - end boxed text (draw box now)
 
117
.de BE
 
118
.nf
 
119
.ti 0
 
120
.mk ^t
 
121
.ie n \l'\\n(^lu\(ul'
 
122
.el \{\
 
123
.\"     Draw four-sided box normally, but don't draw top of
 
124
.\"     box if the box started on an earlier page.
 
125
.ie !\\n(^b-1 \{\
 
126
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
 
127
.\}
 
128
.el \}\
 
129
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
 
130
.\}
 
131
.\}
 
132
.fi
 
133
.br
 
134
.nr ^b 0
 
135
..
 
136
'\"     # VS - start vertical sidebar
 
137
'\"     # ^Y = starting y location
 
138
'\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
 
139
.de VS
 
140
.if !"\\$2"" .br
 
141
.mk ^Y
 
142
.ie n 'mc \s12\(br\s0
 
143
.el .nr ^v 1u
 
144
..
 
145
'\"     # VE - end of vertical sidebar
 
146
.de VE
 
147
.ie n 'mc
 
148
.el \{\
 
149
.ev 2
 
150
.nf
 
151
.ti 0
 
152
.mk ^t
 
153
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
 
154
.sp -1
 
155
.fi
 
156
.ev
 
157
.\}
 
158
.nr ^v 0
 
159
..
 
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.
 
163
.de ^B
 
164
.ev 2
 
165
'ti 0
 
166
'nf
 
167
.mk ^t
 
168
.if \\n(^b \{\
 
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
 
173
.\}
 
174
.if \\n(^v \{\
 
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
 
177
.\}
 
178
.bp
 
179
'fi
 
180
.ev
 
181
.if \\n(^b \{\
 
182
.mk ^y
 
183
.nr ^b 2
 
184
.\}
 
185
.if \\n(^v \{\
 
186
.mk ^Y
 
187
.\}
 
188
..
 
189
'\"     # DS - begin display
 
190
.de DS
 
191
.RS
 
192
.nf
 
193
.sp
 
194
..
 
195
'\"     # DE - end display
 
196
.de DE
 
197
.fi
 
198
.RE
 
199
.sp
 
200
..
 
201
'\"     # SO - start of list of standard options
 
202
.de SO
 
203
.SH "STANDARD OPTIONS"
 
204
.LP
 
205
.nf
 
206
.ta 4c 8c 12c
 
207
.ft B
 
208
..
 
209
'\"     # SE - end of list of standard options
 
210
.de SE
 
211
.fi
 
212
.ft R
 
213
.LP
 
214
See the \\fBoptions\\fR manual entry for details on the standard options.
 
215
..
 
216
'\"     # OP - start of full description for a single option
 
217
.de OP
 
218
.LP
 
219
.nf
 
220
.ta 4c
 
221
Command-Line Name:      \\fB\\$1\\fR
 
222
Database Name:  \\fB\\$2\\fR
 
223
Database Class: \\fB\\$3\\fR
 
224
.fi
 
225
.IP
 
226
..
 
227
'\"     # CS - begin code excerpt
 
228
.de CS
 
229
.RS
 
230
.nf
 
231
.ta .25i .5i .75i 1i
 
232
..
 
233
'\"     # CE - end code excerpt
 
234
.de CE
 
235
.fi
 
236
.RE
 
237
..
 
238
.de UL
 
239
\\$1\l'|0\(ul'\\$2
 
240
..
 
241
.TH "critcl::class" n 1\&.0\&.6 doc "C Runtime In Tcl (CriTcl)"
 
242
.BS
 
243
.SH NAME
 
244
critcl::class \- CriTcl Utilities: C Classes
 
245
.SH SYNOPSIS
 
246
package require \fBTcl  8\&.4\fR
 
247
.sp
 
248
package require \fBcritcl  ?3\&.1\&.6?\fR
 
249
.sp
 
250
package require \fBcritcl::class  ?1\&.0\&.6?\fR
 
251
.sp
 
252
\fB::critcl::class::define\fR \fIname\fR \fIscript\fR
 
253
.sp
 
254
\fBinclude\fR \fIpath\fR
 
255
.sp
 
256
\fBsupport\fR \fIcode\fR
 
257
.sp
 
258
\fBtype\fR \fIname\fR
 
259
.sp
 
260
\fBclassconstructor\fR \fIbody\fR
 
261
.sp
 
262
\fBclassdestructor\fR \fIbody\fR
 
263
.sp
 
264
\fBconstructor\fR \fIbody\fR ?\fIpostbody\fR?
 
265
.sp
 
266
\fBdestructor\fR \fIbody\fR
 
267
.sp
 
268
\fBclassvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
 
269
.sp
 
270
\fBclassmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
 
271
.sp
 
272
\fBclassmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
 
273
.sp
 
274
\fBclassmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
 
275
.sp
 
276
\fBinsvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
 
277
.sp
 
278
\fBmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
 
279
.sp
 
280
\fBmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
 
281
.sp
 
282
\fBmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
 
283
.sp
 
284
\fBmethod_introspection\fR
 
285
.sp
 
286
.BE
 
287
.SH DESCRIPTION
 
288
.PP
 
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
 
292
faster\&.
 
293
.PP
 
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\&.
 
297
.PP
 
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
 
302
package\&.
 
303
.PP
 
304
Its intended audience are mainly developers wishing to write
 
305
Tcl packages with embedded C code\&.
 
306
.PP
 
307
This package resides in the Core Package Layer of CriTcl\&.
 
308
.PP
 
309
.PS
 
310
.nf
 
311
+----------------+
 
312
|Applications    |
 
313
| critcl         |
 
314
| critcl::app    |
 
315
+----------------+
 
316
 
 
317
*================*
 
318
|Core Packages   |
 
319
| critcl         |
 
320
| critcl::util   |
 
321
*================*
 
322
 
 
323
+----------------+
 
324
|Support Packages|
 
325
| stubs::*       |
 
326
| md5, platform  |
 
327
|  \&.\&.\&.           |
 
328
+----------------+
 
329
 
 
330
.fi
 
331
.PE
 
332
.PP
 
333
.SH API
 
334
.TP
 
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\&.
 
343
.PP
 
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"
 
348
.TP
 
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\&.
 
355
.sp
 
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\&.
 
359
.sp
 
360
The result of the command is the empty string\&.
 
361
.TP
 
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\&.
 
367
.sp
 
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\&.
 
371
.sp
 
372
The result of the command is the empty string\&.
 
373
.TP
 
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\&.
 
377
.sp
 
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\&.
 
381
.sp
 
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\&.
 
386
.sp
 
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\&.
 
390
.sp
 
391
The result of the command is the empty string\&.
 
392
.PP
 
393
.SS "CLASS LIFETIME MANAGEMENT"
 
394
.TP
 
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\&.
 
400
.sp
 
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\&.
 
406
.sp
 
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\&.
 
410
.sp
 
411
The C code blocks of multiple calls (including the constructors
 
412
of classvariable definitions) are executed in order of specification\&.
 
413
.sp
 
414
The result of the command is the empty string\&.
 
415
.sp
 
416
The C code in \fIbody\fR has access to the following
 
417
environment:
 
418
.RS
 
419
.TP
 
420
\fBinterp\fR
 
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\&.
 
424
.TP
 
425
\fBclass\fR
 
426
Pointer to the class structure to initialize\&.
 
427
.TP
 
428
error
 
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\&.
 
436
.RE
 
437
.TP
 
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\&.
 
443
.sp
 
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\&.
 
449
.sp
 
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\&.
 
453
.sp
 
454
The C code blocks of multiple calls (including the constructors
 
455
of class variable definitions) are executed in order of specification\&.
 
456
.sp
 
457
The result of the command is the empty string\&.
 
458
.sp
 
459
The C code in \fIbody\fR has access to the same
 
460
environment as the class constructor code blocks\&.
 
461
.PP
 
462
.SS "INSTANCE LIFETIME MANAGEMENT"
 
463
.TP
 
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\&.
 
474
.sp
 
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\&.
 
479
.sp
 
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\&.
 
483
.sp
 
484
The C code blocks of multiple calls (including the constructors
 
485
of instance variable definitions) are executed in order of specification\&.
 
486
.sp
 
487
The result of the command is the empty string\&.
 
488
.sp
 
489
The C code in \fIbody\fR has access to the following
 
490
environment:
 
491
.RS
 
492
.TP
 
493
\fBinterp\fR
 
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\&.
 
497
.TP
 
498
\fBinstance\fR
 
499
Pointer to the instance structure to initialize\&.
 
500
.TP
 
501
error
 
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\&.
 
509
.RE
 
510
.sp
 
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:
 
515
.RS
 
516
.TP
 
517
\fBinterp\fR
 
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\&.
 
521
.TP
 
522
\fBinstance\fR
 
523
Pointer to the instance structure to initialize\&.
 
524
.TP
 
525
\fBcmd\fR
 
526
The Tcl_Command token of the Tcl-level instance
 
527
command\&.
 
528
.TP
 
529
\fBfqn\fR
 
530
The fully qualified name of the instance command,
 
531
stored in a Tcl_Obj*\&.
 
532
.RE
 
533
.TP
 
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\&.
 
544
.sp
 
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\&.
 
549
.sp
 
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\&.
 
553
.sp
 
554
The C code blocks of multiple calls (including the constructors
 
555
of instance variable definitions) are executed in order of specification\&.
 
556
.sp
 
557
The result of the command is the empty string\&.
 
558
.sp
 
559
The C code in \fIbody\fR has access to the following
 
560
environment:
 
561
.RS
 
562
.TP
 
563
\fBinstance\fR
 
564
Pointer to the instance structure to release\&.
 
565
.RE
 
566
.PP
 
567
.SS "CLASS VARIABLES AND METHODS"
 
568
.TP
 
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
 
572
specified\&.
 
573
.sp
 
574
\fIAttention:\fR Specification of a class variable precludes
 
575
the use of an external C \fBtype\fR for the instance structure\&.
 
576
.sp
 
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\&.
 
580
.sp
 
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
 
587
code\&.
 
588
.sp
 
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\&.
 
592
.TP
 
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\&.
 
600
.sp
 
601
For this the \fIbody\fR has access to
 
602
.RS
 
603
.TP
 
604
\fBclass\fR
 
605
Pointer to the class structure\&.
 
606
.TP
 
607
\fBinterp\fR
 
608
Pointer to the Tcl interpreter (Tcl_Interp*) the
 
609
class structure is associated with
 
610
.TP
 
611
\fBobjc\fR
 
612
The number of method arguments\&.
 
613
.TP
 
614
\fBobjv\fR
 
615
The method arguments, as C array of Tcl_Obj pointers\&.
 
616
.RE
 
617
.IP
 
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\&.
 
623
.TP
 
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\&.
 
633
.sp
 
634
The \fIbody\fR has access to
 
635
.RS
 
636
.TP
 
637
\fBclass\fR
 
638
Pointer to the class structure\&.
 
639
.TP
 
640
\fBinterp\fR
 
641
Pointer to the Tcl interpreter (Tcl_Interp*) the
 
642
class structure is associated with
 
643
.TP
 
644
\&.\&.\&.
 
645
All \fIarguments\fR under their specified names and C types
 
646
as per their definition\&.
 
647
.RE
 
648
.TP
 
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
 
652
forms\&.
 
653
.sp
 
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\&.
 
657
.sp
 
658
It is assumed that the first four arguments of that function
 
659
represent the parameters
 
660
.RS
 
661
.TP
 
662
\fBclass\fR
 
663
Pointer to the class structure\&.
 
664
.TP
 
665
\fBinterp\fR
 
666
Pointer to the Tcl interpreter (Tcl_Interp*) the
 
667
class structure is associated with
 
668
.TP
 
669
\fBobjc\fR
 
670
The number of method arguments\&.
 
671
.TP
 
672
\fBobjv\fR
 
673
The method arguments, as C array of Tcl_Obj pointers\&.
 
674
.RE
 
675
.IP
 
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\&.
 
678
.PP
 
679
.SS "INSTANCE VARIABLES AND METHODS"
 
680
.TP
 
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
 
684
specified\&.
 
685
.sp
 
686
\fIAttention:\fR Specification of an instance variable
 
687
precludes the use of an external C \fBtype\fR for the instance
 
688
structure\&.
 
689
.sp
 
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
 
695
system\&.
 
696
.sp
 
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\&.
 
703
.sp
 
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\&.
 
707
.TP
 
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\&.
 
715
.sp
 
716
For this the \fIbody\fR has access to
 
717
.RS
 
718
.TP
 
719
\fBinstance\fR
 
720
Pointer to the instance structure\&.
 
721
.TP
 
722
\fBinterp\fR
 
723
Pointer to the Tcl interpreter (Tcl_Interp*) the
 
724
instance structure is associated with
 
725
.TP
 
726
\fBobjc\fR
 
727
The number of method arguments\&.
 
728
.TP
 
729
\fBobjv\fR
 
730
The method arguments, as C array of Tcl_Obj pointers\&.
 
731
.RE
 
732
.IP
 
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\&.
 
738
.TP
 
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\&.
 
748
.sp
 
749
The \fIbody\fR has access to
 
750
.RS
 
751
.TP
 
752
\fBinstance\fR
 
753
Pointer to the instance structure\&.
 
754
.TP
 
755
\fBinterp\fR
 
756
Pointer to the Tcl interpreter (Tcl_Interp*) the
 
757
instance structure is associated with
 
758
.TP
 
759
\&.\&.\&.
 
760
All \fIarguments\fR under their specified names and C types
 
761
as per their definition\&.
 
762
.RE
 
763
.TP
 
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
 
767
forms\&.
 
768
.sp
 
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\&.
 
772
.sp
 
773
It is assumed that the first four arguments of that function
 
774
represent the parameters
 
775
.RS
 
776
.TP
 
777
\fBinstance\fR
 
778
Pointer to the instance structure\&.
 
779
.TP
 
780
\fBinterp\fR
 
781
Pointer to the Tcl interpreter (Tcl_Interp*) the
 
782
instance structure is associated with
 
783
.TP
 
784
\fBobjc\fR
 
785
The number of method arguments\&.
 
786
.TP
 
787
\fBobjv\fR
 
788
The method arguments, as C array of Tcl_Obj pointers\&.
 
789
.RE
 
790
.IP
 
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\&.
 
793
.TP
 
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\&.
 
799
.sp
 
800
The two methods and the class variable are all named
 
801
\fBmethods\fR\&.
 
802
.PP
 
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\&.
 
807
.IP [1]
 
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:
 
811
.RS
 
812
.IP [1]
 
813
You cannot define your own instance variables\&.
 
814
.IP [2]
 
815
You cannot define your own class variables\&.
 
816
.IP [3]
 
817
You cannot use \fBmethod_introspection\fR\&.
 
818
.IP [4]
 
819
You have to allocate and release the instance structure on your
 
820
own, through \fBconstructor\fR and \fBdestructor\fR code blocks\&.
 
821
.RE
 
822
.IP [2]
 
823
If you declare class variables you are subject to the
 
824
following constraints and rules:
 
825
.RS
 
826
.IP [1]
 
827
You cannot use \fBtype\fR\&.
 
828
.IP [2]
 
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\&.
 
832
.RE
 
833
.IP [3]
 
834
If you declare instance variables (possibly automatic, see
 
835
above) you are subject to following constraints and rules:
 
836
.RS
 
837
.IP [1]
 
838
You cannot use \fBtype\fR\&.
 
839
.IP [2]
 
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\&.
 
843
.IP [3]
 
844
The system generates an instance method \fBdestroy\fR for
 
845
you\&.
 
846
.IP [4]
 
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\&.
 
850
.RE
 
851
.PP
 
852
.SH EXAMPLE
 
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\&.
 
856
.PP
 
857
The full implementation can be found in the directory
 
858
"\fIexamples/queue\fR" of the critcl source distribution/repository\&.
 
859
.CS
 
860
 
 
861
 
 
862
package require Tcl 8\&.4
 
863
package require critcl 3\&.1
 
864
 
 
865
critcl::buildrequirement {
 
866
    package require critcl::class ; # DSL, easy spec of Tcl class/object commands\&.
 
867
}
 
868
 
 
869
critcl::cheaders util\&.h
 
870
 
 
871
critcl::class::define ::queuec {
 
872
    include util\&.h
 
873
 
 
874
    insvariable Tcl_Obj* unget {
 
875
        List object unget elements
 
876
    } {
 
877
        instance->unget = Tcl_NewListObj (0,NULL);
 
878
        Tcl_IncrRefCount (instance->unget);
 
879
    } {
 
880
        Tcl_DecrRefCount (instance->unget);
 
881
    }
 
882
 
 
883
    insvariable Tcl_Obj* queue {
 
884
        List object holding the main queue
 
885
    } {
 
886
        instance->queue = Tcl_NewListObj (0,NULL);
 
887
        Tcl_IncrRefCount (instance->queue);
 
888
    } {
 
889
        Tcl_DecrRefCount (instance->queue);
 
890
    }
 
891
 
 
892
    insvariable Tcl_Obj* append {
 
893
        List object holding new elements
 
894
    } {
 
895
        instance->append = Tcl_NewListObj (0,NULL);
 
896
        Tcl_IncrRefCount (instance->append);
 
897
    } {
 
898
        Tcl_DecrRefCount (instance->append);
 
899
    }
 
900
 
 
901
    insvariable int at {
 
902
        Index of next element to return from the main queue
 
903
    } {
 
904
        instance->at = 0;
 
905
    }
 
906
 
 
907
    support {\&.\&.\&. queue_peekget, queue_size, etc\&.}
 
908
 
 
909
    method clear {} {\&.\&.\&.}
 
910
    method destroy {\&.\&.\&.}
 
911
 
 
912
    method get  as queue_peekget 1
 
913
    method peek as queue_peekget 0
 
914
 
 
915
    method put {item \&.\&.\&.}
 
916
 
 
917
    method size {} {
 
918
        if ((objc != 2)) {
 
919
            Tcl_WrongNumArgs (interp, 2, objv, NULL);
 
920
            return TCL_ERROR;
 
921
        }
 
922
 
 
923
        Tcl_SetObjResult (interp, Tcl_NewIntObj (queue_size (instance, NULL, NULL, NULL)));
 
924
        return TCL_OK;
 
925
    }
 
926
 
 
927
    method unget {item} {\&.\&.\&.}
 
928
}
 
929
 
 
930
package provide queuec 1
 
931
 
 
932
.CE
 
933
.SH AUTHORS
 
934
Andreas Kupries
 
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\&.
 
941
.SH KEYWORDS
 
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
 
943
.SH CATEGORY
 
944
Glueing/Embedded C code
 
945
.SH COPYRIGHT
 
946
.nf
 
947
Copyright (c) 2011-2012 Andreas Kupries
 
948
 
 
949
.fi
 
 
b'\\ No newline at end of file'