Debian Codegraph @

man/tree.mann

raw ◀ ▶
1 Debian patch touch this file
1 '\"
2 '\" Copyright 1991-1997 by Lucent Technologies, Inc.
3 '\"
4 '\" Permission to use, copy, modify, and distribute this software and its
5 '\" documentation for any purpose and without fee is hereby granted, provided
6 '\" that the above copyright notice appear in all copies and that both that the
7 '\" copyright notice and warranty disclaimer appear in supporting documentation,
8 '\" and that the names of Lucent Technologies any of their entities not be used
9 '\" in advertising or publicity pertaining to distribution of the software
10 '\" without specific, written prior permission.
11 '\"
12 '\" Lucent Technologies disclaims all warranties with regard to this software,
13 '\" including all implied warranties of merchantability and fitness. In no event
14 '\" shall Lucent Technologies be liable for any special, indirect or
15 '\" consequential damages or any damages whatsoever resulting from loss of use,
16 '\" data or profits, whether in an action of contract, negligence or other
17 '\" tortuous action, arising out of or in connection with the use or performance
18 '\" of this software.
19 '\"
20 '\" Tree command created by George Howlett.
21 '\" Extensive cleanups and enhancements by Peter MacDonald.
22 '\"
23 .so man.macros
24 .TH tree n BLT_VERSION BLT "BLT Built-In Commands"
25 .BS
26 '\" Note: do not modify the .SH NAME line immediately below!
27 .SH NAME
28 tree \- Create and manage tree data objects.
29 .SH SYNOPSIS
30 \fBtree create\fR ?\fB-fixed\fR? ?\fB-dictset\fR? ?\fB-keyhash\fR \fIN\fR? ?\fItreeName\fR?
31 .sp
32 \fBtree destroy\fR \fItreeName\fR...
33 .sp
34 \fBtree names\fR ?\fIpattern\fR?
35 .sp
36 \fBtree op\fR \fIsubcmd\fR ?\fIsubsubcmd ...\fR? \fItreeName\fR ?\fIarg arg ...\fR?
37 .BE
38 .SH DESCRIPTION
39 The \fBtree command\fR is used to create, destroy, and
40 provide Tcl access to a \fBtree object\fR.
41 A \fBtree object\fR
42 is an ordered tree of nodes where each node can have
43 data key-values, tags and a label.
44 The \fBtreeview\fR widget uses a \fBtree object\fR.
45
46 .SH INTRODUCTION
47
48 Tree provides Tcl with a rich API for managing complex data structures.
49 Here is a simple example.
50 .PP
51 .CS
52 set t [tree create]
53 set id [$t insert 0]
54 $t set $id X 2
55 set n [$t get $id X]
56
57 # Create a node with label
58 $t insert 0 -label A
59 $t set 0->A X 1
60 set n [$t get 0->A X]
61 .CE
62 .PP
63 Labels provide convenient \fB->\fR indexing relative a starting node.
64 .PP
65 Nodes may also be created with initial data values.
66 .PP
67 .CS
68 $t insert 0 -label A -data {X 1 Y "a 1 b 2"}
69 $t incr 0->A X 3
70 $t set 0->A Y(a) 4
71 .CE
72 .PP
73 Note round braces are used to access sub-values in a \fBdict-array\fR.
74 See the section
75 .SB "DICT-ARRAYS"
76 below for details.
77 .CE
78 .SH SYNTAX
79 .TP
80 \fBtree create\fR ?\fB-fixed\fR? ?\fB-dictset\fR? ?\fB-keyhash\fR \fIN\fR? ?\fItreeName\fR?
81 Creates a new tree object. The name of the new tree is returned
82 and a Tcl command is created.
83 If no \fItreeName\fR argument is present, then the name of the tree is
84 automatically generated in the form "\fBtree0\fR", "\fBtree1\fR",
85 etc relative to the current namespace.
86 A tree name (if given) can not start with a dash.
87 Tree names containing the substring "\fB#auto\fR" will
88 be replaced with a generated identifier. For example, the
89 name \fBdata#auto\fR will translate to \fBdatatree0\fR.
90 Note that when
91 the Tcl command is deleted the \fBtree object\fR also gets freed.
92 .sp
93 Newly created trees always contain a single root node with id \fB0\fR
94 that can not be deleted.
95 .sp
96 Switches for \fBcreate\fR are listed below:
97 .RS
98 .TP 1i
99 \fB\-fixed\fR
100 Make \fBinsert\fR automatically set the \fB\-fixed\fR flag.
101 This will disallow later setting of keys not given
102 as \fI\-data\fR to the insert. This includes dict-array keys.
103 See the \fBfixed\fR sub-command.
104 .TP 1i
105 \fB\-dictset\fR
106 Define that any update of an \fBarray\fR field will coerce the
107 array object to a dict object.
108 a dict will preserve order of sub-field keys on update.
109 See the \fBdictset\fR sub-command.
110 .TP 1i
111 \fB\-keyhash\fR \fIsize\fR
112 Define the size beyond which node key storage starts using
113 a hash (the default is 21 keys). Normally
114 small numbers of keys are stored as a list. But once more than
115 \fIsize\fR keys are added to a node, key storage converts to a hash.
116 This affects the order of key iteration (eg. for \fBget\fR/\fBnames\fR/\fBvalues\fR).
117 A list will iterate in the order in which keys were added,
118 whereas the order of a hash is undetermined.
119 For large numbers of
120 ordered keys, specify a really large \fIsize\fR (eg. 1000000).
121 .RE
122
123 .TP
124 \fBtree destroy\fR \fItreeName\fR...
125 Releases one of more trees. The Tcl command associated with
126 \fItreeName\fR is also removed. Trees are reference counted. The
127 internal tree data object isn't destroyed until no one else is using
128 the tree.
129 .TP
130 \fBtree names\fR ?\fIpattern\fR?
131 Returns the names of all tree objects. if a \fIpattern\fR argument
132 is given, then the only those trees whose name matches pattern will
133 be listed.
134 .TP
135 \fBtree op\fR \fIsubcmd\fR ?\fIsubsubcmd ...\fR? \fItreeName\fR ?\fIarg arg ...\fR?
136 Provide direct calls to sub-commands, without going through the object command.
137 Aside from self documentating,
138 it allows wize to provide support checked tree calls.
139 .SH NODE IDS AND TAGS
140 Nodes in a tree object may be referenced by id or by tag.
141 Each node has a unique serial number or id that is assigned to it
142 at creation. The id of an node never changes or is reused
143 unless all nodes in a tree are delete.
144 .PP
145 A node may also have any number of tags associated with it. A tag is
146 just a string of characters, and it may take any form but
147 can not start with
148 an integer. For example, "\fBx123\fR" is valid, but "\fB123x\fR"
149 is not. The same tag may be associated with one
150 or multiple nodes (ranges or \fItagnode\fR).
151 Ranges are commonly used to group nodes in various interesting ways.
152 .PP
153 Commands that take a \fItagnode\fR can operate on ranges and
154 will accept either a tag or a list of zero or more integer node numbers.
155 A node-list may contain only integers, and can not have leading spaces.
156 Node-lists simplify the use of iterating commands because
157 it avoids excessive use of \fBeval\fR.
158 .PP
159 There are four built-in or psuedo tags:
160 .RS
161 .TP 1i
162 \fBall\fR
163 Applies to every node in the tree.
164 .TP 1i
165 \fBnonroot\fR
166 Applies to every node in the tree except the root node.
167 .TP 1i
168 \fBrootchildren\fR
169 Applies to every node in the tree whose parent is the root node.
170 .TP 1i
171 \fBroot\fR
172 Managed automatically by the tree object, \fBroot\fR specifies the node
173 that is currently set as the root node for the tree.
174 .RE
175 .PP
176 When specifying nodes in tree object commands, if the specifier is an
177 integer then it is assumed to refer to the single node with that id.
178 If the specifier is not an integer, then it is assumed to refer to all
179 of the nodes in the tree that have a tag matching the specifier. The
180 symbol \fInode\fR is used below to indicate that an argument specifies
181 either an id or a tag that selects a single node.
182 A \fItagnode\fR is either a tag that selects a group of
183 nodes, or it's a list of zero or more integer node numbers.
184 Many tree commands only operate on a single node at a
185 time; if \fInode\fR is specified in a way that names multiple items, then
186 an error "refers to more than one node" is generated.
187 .SH NODE MODIFIERS
188 You can also specify node in relation to another node by appending one
189 or more modifiers to the node id or tag after \fB->\fR.
190 A modifier refers to a node
191 in relation to the specified node. For example,
192 "\fBroot->firstchild\fR"
193 selects the first subtree of the root node.
194 .PP
195 The following modifiers are available:
196 .RS
197 .TP 1i
198 \fBfirstchild\fR
199 Selects the first child of the node.
200 .TP 1i
201 \fBlastchild\fR
202 Selects the last child of the node.
203 .TP 1i
204 \fBnextnode\fR
205 Selects the next node in preorder to the node.
206 .TP 1i
207 \fBnextsibling\fR
208 Selects the next sibling of the node.
209 .TP 1i
210 \fBparentnode\fR
211 Selects the parent of the node.
212 .TP 1i
213 \fBprevnode\fR
214 Selects the previous node in preorder to the node.
215 .TP 1i
216 \fBprevsibling\fR
217 Selects the previous sibling of the node.
218 .TP 1i
219 \fBmaxnode\fR
220 The maximum node number.
221 .TP 1i
222 "\fIlabel\fR"
223 .TP 1i
224 \'\fIlabel\fR'
225 .TP 1i
226 \fIlabel\fR
227 Selects the child node whose label is \fIlabel\fR. Enclosing \fIlabel\fR in
228 quotes (double or single) supports labels with embedded spaces and
229 prevents matching reserved words (eg. a node labeled "parentnode").
230 If mulitiple child nodes
231 have the same label, the first matching node is used.
232 .RE
233 .PP
234 It's an error if the node can't be found. For example,
235 \fBlastchild\fR and \fBfirstchild\fR will generate errors if the node
236 has no children. The exception to this is the \fBindex\fR operation which
237 returns -1, allowing you to test if a modifier is valid.
238 .SH TREE OPERATIONS
239 Once you create a tree object, you can use its Tcl command
240 to query or modify it. The
241 general form is
242 .DS
243 \fItreeName\fR \fIoperation\fR ?\fIarg\fR?...
244 .DE
245 Both \fIoperation\fR and its arguments determine the exact behavior of
246 the command. The operations available for trees are listed below.
247 .TP
248 \fItreeName\fR \fBancestor\fR \fInode1\fR \fInode2\fR
249 Returns the mutual ancestor of the two nodes \fInode1\fR and
250 \fInode2\fR. The ancestor can be one of the two nodes. For example,
251 if \fInode1\fR and \fInode2\fR are the same nodes, their ancestor is
252 \fInode1\fR.
253 .TP
254 \fItreeName\fR \fBappend\fR \fInode key\fR \fIstring\fR ?\fIstring ...\fR?
255 Append one or more strings to node/key value.
256 .TP
257 \fItreeName\fR \fBappendi\fR \fItagnode key\fR \fIstring\fR ?\fIstring ...\fR?
258 The same as \fBappend\fR but accepts a multi-node tag and an
259 undefined key will be initialized to {}. Returns the number of nodes
260 updated.
261 .TP
262 \fItreeName\fR \fBapply\fR \fInode\fR ?\fIswitches\fR?
263 Runs commands for all nodes matching the criteria given by
264 \fIswitches\fR for the subtree designated by \fInode\fR. By default
265 all nodes match, but you can set switches to narrow the match. This
266 operation differs from \fBfind\fR in two ways: 1) Tcl commands can be
267 invoked both pre- and post-traversal of a node and 2) the tree is
268 always traversed in depth first order.
269 .sp
270 The \fB\-exact\fR, \fB\-glob\fR,
271 and \fB\-regexp\fR switches indicate both what kind of pattern matching
272 to perform and the pattern. By default each pattern will be compared
273 with the node label. You can set more than one of these switches. If
274 any of the patterns match (logical or), the node matches.
275 If the \fB\-key\fR switch is
276 used, it designates the data field to be matched.
277 .sp
278 The valid switches are listed
279 below:
280 .RS
281 .TP 1i
282 \fB\-depth\fR \fInumber\fR
283 Descend at most \fInumber\fR (a non-negative integer) levels
284 If \fInumber\fR is \fB1\fR this means only apply the tests
285 to the children of \fInode\fR.
286 .TP 1i
287 \fB\-exact\fR \fIstring\fR
288 Matches each node using \fIstring\fR. The node must match \fIstring\fR
289 exactly.
290 .TP 1i
291 \fB\-glob\fR \fIstring\fR
292 Test each node to \fIstring\fR using global pattern
293 matching. Matching is done in a fashion similar to that used by
294 \fBstring match\fR.
295 .TP 1i
296 \fB\-invert\fR
297 Invert the results of the pattern matching of \fB-name\fR.
298 .TP 1i
299 \fB\-isleaf\fR
300 Only test nodes with no children.
301 .TP 1i
302 \fB\-istree\fR
303 Only test nodes with children.
304 .TP 1i
305 \fB\-key\fR \fIkey\fR
306 .TP 1i
307 \fB\-keyglob\fR \fIkey\fR
308 .TP 1i
309 \fB\-keyregexp\fR \fIkey\fR
310 .TP 1i
311 \fB\-keyexact\fR \fIkey\fR
312 If pattern matching is selected (using the \fB\-exact\fR,
313 \fB\-glob\fR, or \fB\-regexp\fR switches), compare the values of the
314 data field keyed by \fIkey\fR instead of the node's label. If no
315 pattern matching switches are set, then any node with this data key
316 will match. The field names may also be patterns using \fB-keyglob\fR, etc.
317 .TP 1i
318 \fB\-nocase\fR
319 Ignore case when matching patterns.
320 .TP 1i
321 \fB\-precommand\fR \fIcommand\fR
322 Invoke \fIcommand\fR for each matching node. Before \fIcommand\fR is
323 invoked, the id of the node is appended. You can control
324 processing by the return value of \fIcommand\fR. If \fIcommand\fR
325 generates an error, processing stops and the \fBfind\fR operation
326 returns an error. But if \fIcommand\fR returns \fBbreak\fR, then
327 processing stops, no error is generated. If \fIcommand\fR returns
328 \fBcontinue\fR, then processing
329 stops on that subtree and continues on the next.
330 .TP 1i
331 \fB\-postcommand\fR \fIcommand\fR
332 Invoke \fIcommand\fR for each matching node. Before \fIcommand\fR is
333 invoked, the id of the node is appended. You can control
334 processing by the return value of \fIcommand\fR. If \fIcommand\fR
335 generates an error, processing stops and the \fBfind\fR operation
336 returns an error. But if \fIcommand\fR returns \fBbreak\fR, then
337 processing stops, no error is generated. If \fIcommand\fR returns
338 \fBcontinue\fR, then processing
339 stops on that subtree and continues on the next.
340 .TP 1i
341 \fB\-regexp\fR \fIstring\fR
342 Test each node using \fIstring\fR as a regular expression pattern.
343 .TP 1i
344 \fB\-tag\fR \fIstring\fR
345 Only test nodes that have the tag \fIstring\fR.
346 .TP 1i
347 \fB\-usepath\fR
348 Use the node's full path when comparing nodes. The node's full
349 path is a list of labels, starting from the root of each ancestor
350 and the node label. The default is to compare only the node label.
351 .RE
352 .TP
353 \fItreeName\fR \fBattach\fR ?\fB-notags\fR? ?\fItreeObject\fR?
354 Queries or
355 attaches to an existing tree object \fItreeObject\fR. This is primarly
356 used where the tree object was previously created via the C API (eg.
357 via TreeView). The current
358 tree associated with \fItreeName\fR is discarded. In addition, the
359 current set of tags, notifier events, and traces are removed.
360 If \fB-notags\fR is given, tags will not be shared.
361 .TP
362 \fItreeName\fR \fBchildren\fR ?\fB-labels\fR? \fInode\fR ?\fIfirst\fR? ?\fIlast\fR?
363 Returns a list of children for \fInode\fR. If \fInode\fR is a leaf,
364 then an empty string is returned. If \fIfirst\fR and/or \fIlast\fR
365 are given they are the integer index of the children to display.
366 If the \fB-labels\fR option is used,
367 labels are returned instead of the nodes.
368 .TP
369 \fItreeName\fR \fBcopy\fR \fIsrcNode\fR ?\fIdestTree\fR? \fIparentNode\fR ?\fIswitches\fR?
370 Copies \fIsrcNode\fR into \fIparentNode\fR. Both nodes \fIsrcNode\fR and
371 \fIparentNode\fR must already exist. The id of the new node is
372 returned. You can copy from one tree to another. If a \fIdestTree\fR
373 argument is present, it indicates the name of the destination tree.
374 By default both the source and destination trees are the same. The valid
375 \fIswitches\fR are listed below:
376 .RS
377 .TP
378 \fB\-label\fR \fIstring\fR
379 Label \fIdestNode\fR as \fIstring\fR. By default, \fIdestNode\fR has
380 the same label as \fIsrcNode\fR.
381 .TP
382 \fB\-overwrite\fR
383 Overwrite nodes that already exist. Normally nodes are always
384 created, even if there already exists a node by the same name. This
385 switch indicates to add or overwrite the node's data fields.
386 .TP
387 \fB\-recurse\fR
388 Recursively copy all the subtrees of \fIsrcNode\fR as well. In this case,
389 \fIsrcNode\fR can't be an ancestor of \fIdestNode\fR as it would result
390 in a cyclic copy.
391 .TP
392 \fB\-reverse\fR
393 Reverse the direction of the copy.
394 .TP
395 \fB\-tags\fR
•396 Copy tag information. Normally the following node is copied: its
397 label and data fields. This indicates to copy tags as well.
398 .RE
399 .TP
400 \fItreeName\fR \fBcreate\fR ?\fIswitches\fR?
401 Cause the creation of zero or more nodes.
402 Exactly one of \fB-num\fR, \fB-nodes\fR or \fB-path\fR is required.
403 This can create all nodes in a given \fB-path\fR
404 or efficiently populate a tree with large numbers
405 of nodes.
406 The return values is the id of the last created node (or \fB-path\fR element).
407 The valid flags for \fIswitches\fR are described below.
408 .RS
409 .TP 1i
410 \fB\-fixed\fR
411 Set the fixed flag.
412 .TP 1i
413 \fB\-data\fR \fIlist\fR
414 Data to set in each node.
415 .TP 1i
416 \fB\-labelstart\fR \fInumber\fR
417 The label generated nodes is to use
418 a sequence number starting from \fInumber\fR.
419 The default is to just use the node id.
420 .TP 1i
421 \fB\-nodes\fR \fIlist\fR
422 List of nodes ids to create.
423 The \fB\-offset\fR option can specify
424 a constant to add.
425 .TP 1i
426 \fB\-num\fR \fInumber\fR
427 The number of nodes to create.
428 .TP 1i
429 \fB\-offset\fR \fInumber\fR
430 Number to add to each element in \fB-nodes\fR.
431 For example, if loading sqlite rowids you should use 1.
432 The default is 0.
433 .TP 1i
434 \fB\-parent\fR \fInode\fR
435 The \fInode\fR to insert children into.
436 The default is the root node.
437 .TP 1i
438 \fB\-path\fR \fIpathList\fR
439 Verify that a path exists and create any missing nodes.
440 Uses labels in \fIpathList\fR to lookup nodes, creating
441 them if not found. The id for the last
442 node in the path is returned (created or not).
443 .TP 1i
444 \fB\-pos\fR \fInumber\fR
445 The position where to insert child nodes.
446 The default is -1, meaning append.
447 .TP 1i
448 \fB\-prefix\fR \fIstr\fR
449 String prefix to add to each nodes label.
450 .TP 1i
451 \fB\-start\fR \fInumber\fR
452 Node nuber to start from when using \fB-num\fR. The default is 1.
453 .TP 1i
454 \fB\-tags\fR \fItagList\fR
455 List of tags to add to each newly created node.
456 .RE
457 .TP
458 \fItreeName\fR \fBdegree\fR \fInode\fR
459 Returns the number of children of \fInode\fR.
460 .TP
461 \fItreeName\fR \fBdelete\fR \fInode\fR...
462 Recursively deletes one or more nodes from the tree.
463 The node and all its descendants are removed. The one exception
464 is the root node. In this case, only its descendants are removed.
465 The root node will remain. Any tags or
466 traces on the nodes are released.
467 .TP
468 \fItreeName\fR \fBdepth\fR \fInode\fR
469 Returns the depth of the node. The depth is the number of
470 steps from the node to the root of the tree. The depth of the
471 root node is \fB0\fR.
472 .TP
473 \fItreeName\fR \fBdictset\fR ?\fIbool\fR?
474 Get or set the dictset flag for the tree which causes any set of an
475 array sub-fields to force the value to type dict.
476 Unlike array types, dicts preserve the order of elements.
477 Setting this to one has the same effect as using the \fB-dictset\fR
478 flag at tree creation time.
479 .TP
480 \fItreeName\fR \fBdump\fR \fInode\fR ?\fIswitches\fR?
481 Save tree data for \fInode\fR and its descendants.
482 With the \fB-file\fR option, output goes to the file
483 \fIfileName\fR (this is unsupported in a safe interp).
484 With the \fB-channel\fR option, data is output to channel \fIchan\fR.
485 If neither option is given, the dump is returned as data.
486 .sp
487 The subtree designated by \fInode\fR is
488 traversed to obtain the following information for each node: 1) the node's
489 path relative to \fInode\fR, 2) a sublist key value pairs
490 representing the node's data fields, and 3) a sublist of tags.
491 and 4) the label
492 This list returned can be used
493 later to copy or restore the tree with the \fBrestore\fR operation.
494 .sp
495 The valid \fIswitches\fR are listed below.
496 .RS
497 .TP
498 \fB\-channel \fIchan\fR
499 Obtain data from from the given channel \fIchan\fR.
500 The channel is not closed afterwards.
501 .TP
502 \fB\-file \fIfileName\fR
503 Obtain data from from the file.
504 \fIfileName\fR. This options is unsupported in a safe interp.
505 .TP
506 \fB\-keys \fIlist\fR
507 A list of patterns of matching keys to be dumped.
508 .TP
509 \fB\-skipkeys \fIlist\fR
510 A list of patterns of matching keys not to be dumped.
511 .TP
512 \fB\-tag \fIpattern\fR
513 A pattern match for tags to include in a node dump.
514 .TP
515 \fB\-skiptag \fIpattern\fR
516 A pattern match for tags to not include in a node dump.
517 .TP
518 \fB\-notags\fR
519 Do not restore any tags
520 .TP
521 \fB\-nopath\fR
522 To save space, do not dump the full path for each node.
523 Instead output periods for all but the last path element.
524 Full paths are used only for partial restores.
525 .RE
526 .TP
527 \fItreeName\fR \fBexists\fR \fInode\fR ?\fIkey\fR?
528 Indicates if \fInode\fR exists in the tree. If a \fIkey\fR argument
529 is present then the command also indicates if the named data field
530 exists.
531 .TP
532 \fItreeName\fR \fBfind\fR ?\fIswitches\fR?
533 Finds for all nodes matching the criteria given by \fIswitches\fR
534 for the subtree designated by \fInode\fR. A list of the selected
535 nodes is returned. By default all nodes match, but you can set
536 switches to narrow the match.
537 .sp
538 The \fB\-exact\fR, \fB\-glob\fR,
539 and \fB\-regexp\fR switches indicate what kind of pattern matching
540 to perform for \fB-name\fR. By default the pattern will be compared
541 with the node label. If the \fB\-key\fR switch is
542 used, it designates the data field to be matched.
543 .sp
544 The order in
545 which the nodes are traversed is controlled by the \fB\-order\fR switch.
546 The possible orderings are \fBpreorder\fR, \fBpostorder\fR, \fBinorder\fR,
547 and \fBbreadthfirst\fR. The default is \fBpreorder\fR.
548 .sp
549 The valid switches are listed
550 below:
551 .RS
552 .TP 1i
553 \fB\-addtag\fR \fIstring\fR
554 Add the tag \fIstring\fR to each selected node.
555 The tag will be created even if no nodes are tagged.
556 .TP 1i
557 \fB\-column\fR \fIkey\fR
558 Use value with field given by \fIkey\fR.
559 Like the \fBtreeview find -column\fR option,
560 this key may contain an array referrence.
561 .TP 1i
562 \fB\-cmdargs\fR \fIcolumns\fR
563 Specify columns whose values are to be appended to \fB\-command\fR.
564 .TP 1i
565 \fB\-command\fR \fIcommand\fR
566 Invoke \fIcommand\fR for each matching node. Before \fIcommand\fR is
567 invoked, the id of the node is appended. You can control
568 processing by the return value of \fIcommand\fR. If \fIcommand\fR
569 generates an error, processing stops and the \fBfind\fR operation
570 returns an error. But if \fIcommand\fR returns \fBbreak\fR, then
571 processing stops, no error is generated. If \fIcommand\fR returns
572 \fBcontinue\fR, then processing
573 stops on that subtree and continues on the next.
574 If \fIcommand\fR returns \fBreturn\fR, then the returned integer
575 is used to indicate 1 for match or 0 for mismatch.
576 .TP 1i
577 \fB\-count\fR
578 Just return the number of matches.
579 .TP 1i
580 \fB\-depth\fR \fInumber\fR
581 Include only nodes with level equal to \fInumber\fR.
582 .TP 1i
583 \fB\-exact\fR
584 Matches each node exactly.
585 .TP 1i
586 \fB\-exec\fR \fIscript\fR
587 Specifies a Tcl script to be evaluated for each matching node.
588 If \fB-var\fR was also specified, that variable is set with the value of
589 the node id before each evaluation. Otherwise,
590 percent sustitutions are performed: note this is much
591 less efficient than using either \fB-var\fR or \fB-command\fR
592 .sp
593 The result of each eval gets appended to the return list, unless
594 the script issues a CONTINUE, in which case that node is skipped.
595 .sp
596 The available percent substitutions on \fIstring\fR are:
597 .RS
598 .TP 5
599 \fB%#\fR
600 The id of the node.
601 .TP 5
602 \fB%W\fR
603 The pathname of the tree.
604 .TP 5
605 \fB%p\fR
606 The label of the node.
607 .TP 5
608 \fB%P\fR
609 The full pathname of the node.
610 .TP 5
611 \fB%R\fR
612 The -> delimited path from root, eg. "root->able->baker->charlie"
613 .TP 5
614 \fB%r\fR
615 The -> delimited path from 0, eg. "0->able->baker->charlie"
616 .TP 5
617 \fB%T\fR
618 The dot delimited tag path eg. ".able.baker.charlie"
619 .TP 5
620 \fB%V\fR
621 The value if using \fB-key\fR or the label otherwise.
622 .TP 5
623 \fB%D\fR
624 The data for the node, ie. like that returned from \fBget\fR.
625 .TP 5
626 \fB%%\fR
627 Translates to a single percent.
628 .RE
629 .TP 1i
630 \fB\-glob\fR
631 Test each node using global pattern
632 matching. Matching is done in a fashion similar to that used by the
633 \fBstring match\fR.
634 .TP 1i
635 \fB\-invert\fR
636 Invert the pattern matching of \fB-name\fR.
637 .TP 1i
638 \fB\-isarray\fR
639 Only test nodes where the specified \fB-key\fR value
640 is an array. Can not be used with \fB-name\fR.
641 The \fB-invert\fR flag will invert the meaning of the
642 check. Note that this will attempt to convert the key value in
643 each traversed node into an array type.
644 .TP 1i
645 \fB\-isempty\fR
646 Only match nodes where the specified \fB-column\fR key value
647 was unset.
648 .TP 1i
649 \fB\-isfixed\fR
650 Only test nodes that have used \fBfixed 1\fR.
651 .TP 1i
652 \fB\-isleaf\fR
653 Only test nodes with no children.
654 .TP 1i
655 \fB\-isnotfixed\fR
656 Only test nodes that have not used \fBfixed 1\fR.
657 .TP 1i
658 \fB\-istree\fR
659 Only test nodes with children.
660 .TP 1i
661 \fB\-keycount\fR \fInum\fR
662 Only test if number of keys is equal to \fInum\fR.
663 .TP 1i
664 \fB\-key\fR \fIkey\fR
665 .TP 1i
666 \fB\-keyglob\fR \fIkey\fR
667 .TP 1i
668 \fB\-keyregexp\fR \fIkey\fR
669 .TP 1i
670 \fB\-keyexact\fR \fIkey\fR
671 Compare the values of the data field keyed by \fIkey\fR instead of
672 the node's label. If no \fB\-name\fR pattern is used
673 then any node with this data key will match.
674 The key names may also be patterns using \fB-keyglob\fR, etc.
675 .TP 1i
676 \fB\-limit\fR \fInumber\fR
677 Stop processing after \fInumber\fR (a positive integer) matches.
678 .TP 1i
679 \fB\-maxdepth\fR \fInumber\fR
680 Include only nodes at level \fInumber\fR or less.
681 .TP 1i
682 \fB\-mindepth\fR \fInumber\fR
683 Include only nodes at level \fInumber\fR or greater.
684 .TP 1i
685 \fB\-name\fR \fIstring\fR
686 The name to use for pattern matching.
687 .TP 1i
688 \fB\-nocase\fR
689 Ignore case when matching patterns.
690 .TP 1i
691 \fB\-nodes \fItagnode\fR
692 Search only in \fItagnode\fR, which is either a tag
693 or a list of nodes ids. This makes possible nested searches.
694 Note this option is incompatible with
695 \fB-top\fR and \fB-notop\fR.
696 .TP 1i
697 \fB\-notop\fR
698 Exclude the \fB-top\fR or starting node.
699 .TP 1i
700 \fB\-order\fR \fIstring\fR
701 Traverse the tree and process nodes according to \fIstring\fR. \fIString\fR
702 can be one of the following:
703 .RS
704 .TP 1i
705 \fBbreadthfirst\fR
706 Process the node and the subtrees at each sucessive level. Each node
707 on a level is processed before going to the next level.
708 .TP 1i
709 \fBinorder\fR
710 Recursively process the nodes of the first subtree, the node itself,
711 and any the remaining subtrees.
712 .TP 1i
713 \fBpostorder\fR
714 Recursively process all subtrees before the node.
715 .TP 1i
716 \fBpreorder\fR
717 Recursively process the node first, then any subtrees (default).
718 .RE
719 .TP 1i
720 \fB\-usepath\fR
721 Use the node's full path when doing the comparison.
722 The default is to compare only the node label.
723 .TP 1i
724 \fB\-regexp\fR
725 Test each node using regular expression pattern matching.
726 .TP 1i
727 \fB\-reldepth\fR
728 Change the meaning of \fB\-depth\fR, \fB\-mindepth\fR and \fB\-maxdepth\fR
729 to be relative to the \fB\-top\fR node.
730 .TP 1i
731 \fB\-return \fIkey\fR
732 Return the value of the given \fIkey\fR, or the empty string if none.
733 If the given \fIkey\fR is the empty string, the node label will be returned.
734 If no value was found and the given \fIkey\fR starts with a percent
735 returns the sustitution as per \fB-exec\fR. Note that a percent
736 substitution longer than 2 chars will append values as list elements.
737 .TP 1i
738 \fB\-strict\fR
739 Generate an error if a given key value is unset when using \fB-return\fR.
740 .TP 1i
741 \fB\-top \fInode\fR
742 Search is only at \fInode\fR and it's descendants.
743 The default is the root node.
744 .TP 1i
745 \fB\-var \fIvariable\fR
746 A variable to set with the node id before each iteration of the \fB-exec\fR
747 script.
748 .TP 1i
749 \fB\-withouttag\fR \fIstring\fR
750 Only test nodes that don't have the tag \fIstring\fR.
751 .TP 1i
752 \fB\-withtag\fR \fIstring\fR
753 Only test nodes that have the tag \fIstring\fR.
754 .RE
755 .TP
756 \fItreeName\fR \fBfindchild\fR \fInode\fR \fIlabel\fR
757 Searches for a child node \fIlabel\fR in \fInode\fR. The id of the
758 child node is returned if found. Otherwise \fB-1\fR is returned.
759 This is the same as using \fBindex \fInode->label\fR.
760 .TP
761 \fItreeName\fR \fBfirstchild\fR \fInode\fR
762 Returns the id of the first child in the \fInode\fR's list
763 of subtrees. If \fInode\fR is a leaf (has no children),
764 then \fB-1\fR is returned.
765 .TP
766 \fItreeName\fR \fBfixed\fR \fInode\fR ?\fIisfixed\fR?
767 Get or set the fixed key-fields flag for a node.
768 New key-fields can be added to a node only if fixed is 0 (the default)
769 If \fInode\fR is given as an empty string, operates on the tree flag.
770 Note that copied and restored nodes do not preserve the fixed state.
771 .TP
772 \fItreeName\fR \fBforeach\fR \fIvar tagnode script\fR
773 Provides a \fBforeach\fR loop for tree. For
774 each node in \fItagnode\fR the node-id is assigned to \fIvar\fR and then
775 \fIscript\fR is evaluated. The \fItagnode\fR is either a tag or a list of
776 nodes as described in the section
777 .SB NODE IDS AND TAGS
778 above.
779 .TP
780 \fItreeName\fR \fBget\fR \fInode\fR ?\fIkey\fR? ?\fIdefaultValue\fR?
781 Returns a list of key-value pairs of data for \fInode\fR. If \fIkey\fR
782 is present, then only the value for that particular data field is
783 returned. It's normally an error if \fInode\fR does not contain the
784 data field \fIkey\fR. But if you provide a \fIdefaultValue\fR
785 argument, this value is returned instead (\fInode\fR will still not
786 contain \fIkey\fR). This feature can be used to access a data field of
787 \fInode\fR without first testing if it exists. This operation may
788 trigger \fBread\fR data traces.
789 .TP
790 \fItreeName\fR \fBincr\fR \fInode key\fR ?\fIamount\fR?
791 Increment value by 1 or given \fIamount\fR and return the value.
792 The incr operation normally tries to use integers,
793 but uses doubles when one of
794 value or \fIamount\fR is a double.
795 .TP
796 \fItreeName\fR \fBincri\fR \fItagnode key\fR ?\fIamount\fR?
797 The same as \fBincr\fR but accepts a multi-node tag and an
798 undefined key will be initialized to 0. Returns the number of nodes
799 updated.
800 .TP
801 \fItreeName\fR \fBindex\fR \fInode\fR
802 Returns the id of \fInode\fR. In addition
803 to standard node id form,
804 \fInode\fR can also be a path (a list of labels from the root) as returned
805 by the \fBpath\fR command.
806 If \fInode\fR is invalid, then \fB-1\fR is returned.
807 .TP
808 \fItreeName\fR \fBinsert\fR \fIparent\fR ?\fIswitches\fR?
809 Inserts a new node into parent node \fIparent\fR.
810 The id of the new node is returned.
811 The following switches
812 are available:
813 .RS
814 .TP 1i
815 \fB\-after\fR \fIchild\fR
816 Position \fInode\fR after \fIchild\fR. The node \fIchild\fR must be a
817 child of \fIparent\fR.
818 .TP 1i
819 \fB\-before\fR \fIchild\fR
820 Position \fInode\fR before \fIchild\fR. The node \fIchild\fR must be a
821 child of \fIparent\fR.
822 .TP 1i
823 \fB\-data\fR \fIdataList\fR
824 Sets the value for each data field in \fIdataList\fR for the
825 new node. \fIDataList\fR is a list of key-value pairs.
826 May not be used in conjuction with \fB-names\fR or \fB-values\fR.
827 .TP 1i
828 \fB\-fixed\fR \fIbool\fR
829 If \fIbool\fR is 1, set \fBfixed\fR field mode after initializing
830 the key/value pairs from \fB-data\fR.
831 This disallows creation of new key fields
832 after the node is created.
833 If not given, the tree default for fixed is used.
834 .TP 1i
835 \fB\-label\fR \fIstring\fR
836 Designates the labels of the node as \fIstring\fR. By default, nodes
837 are labeled as \fB0\fR, \fB1\fR, etc.
838 .TP 1i
839 \fB\-names\fR \fInameList\fR
840 The names for the data fields. This must have the same length as
841 \fB-values\fR, and may not be used in conjuction with \fB-data\fR.
842 .TP 1i
843 \fB\-node\fR \fIid\fR
844 Designates the id for the node. Normally new ids are automatically
845 generated. This allows you to create a node with a specific id.
846 It is an error if the id is already used by another node in the tree.
847 .TP 1i
848 \fB\-pos\fR \fInumber\fR
849 Inserts the node into \fIparent\fR's list of children at
850 position \fInumber\fR. The default is to append.
851 .TP 1i
852 \fB\-pretags\fR \fItagList\fR
853 Adds each tag in \fItagList\fR to the new node, before
854 data is added. Unlike \fB-tags\fR, traces on these tags
855 will fire on key data during the insert.
856 .TP 1i
857 \fB\-tags\fR \fItagList\fR
858 Adds each tag in \fItagList\fR to the new node. \fITagList\fR is a list
859 of tags, so be careful if a tag has embedded space.
860 .TP 1i
861 \fB\-values\fR \fIvalueList\fR
862 The values for the data fields. This must have the same length as
863 \fB-names\fR, and may not be used in conjuction with \fB-data\fR.
864 .RE
865 .TP
866 \fItreeName\fR \fBis\fR \fIproperty\fR \fIargs\fR
867 Indicates the property of a node. Both \fIproperty\fR and \fIargs\fR
868 determine the property being tested. Returns \fB1\fR if true and
869 \fB0\fR otherwise. The following \fIproperty\fR and \fIargs\fR
870 are valid:
871 .RS
872 .TP 1i
873 \fBancestor\fR \fInode1\fR \fInode2\fR
874 Indicates if \fInode1\fR is an ancestor of \fInode2\fR.
875 .TP 1i
876 \fBbefore\fR \fInode1\fR \fInode2\fR
877 Indicates if \fInode1\fR is before \fInode2\fR in depth first traversal.
878 .TP 1i
879 \fBleaf\fR \fInode\fR
880 Indicates if \fInode\fR is a leaf (it has no subtrees).
881 .TP 1i
882 \fBroot\fR \fInode\fR
883 Indicates if \fInode\fR is the designated root. This can be changed
884 by the \fBroot\fR operation.
885 .RE
886 .TP
887 \fItreeName\fR \fBismodified\fR ?\fInodeOrTag\fR? ?\fIisflag\fR?
888 Get or set modified state for the tree or nodes.
889 With no args returns modified state for tree.
890 With one args returns modified state for a node.
891 With two args set modified state for one or more nodes.
892 In the last case, where ?\fInodeOrTag\fR? is the tag \fBall\fR,
893 the state for the tree is also set.
894 .sp
895 Newly created nodes
896 are always considered to be modified until explicitly
897 cleared. After clearing, subsequent updates to keys or tags
898 will toggle the node (and tree) modified again.
899 .TP
900 \fItreeName\fR \fBisset\fR \fInode\fR \fIkey\fR
901 Return 1 if key is set in node.
902 .TP
903 \fItreeName\fR \fBkeys\fR \fInode\fR ?\fItagnode ...\fR?
904 Return list of unique keys for all of the given nodes in \fItagnode\fR.
905 Keys are in no particular order.
906 Accepts nodes and tags or all. See also \fBnames\fR.
907 .TP
908 \fItreeName\fR \fBlabel\fR \fInode\fR ?\fInewLabel\fR?
909 Returns the label of the node designated by \fInode\fR. If \fInewLabel\fR
910 is present, the node is relabeled using it as the new label.
911 .TP
912 \fItreeName\fR \fBlappend\fR \fInode key\fR \fIvalue\fR ?\fIvalue ...\fR?
913 Append one or more list values to node/key value.
914 .TP
915 \fItreeName\fR \fBlappendi\fR \fItagnode key\fR \fIvalue\fR ?\fIvalue ...\fR?
916 The same as \fBlappend\fR but accepts a multi-node tag and an
917 undefined key will be initialized to {}. Returns the number of nodes
918 updated.
919 .TP
920 \fItreeName\fR \fBlastchild\fR \fInode\fR
921 Returns the id of the last child in the \fInode\fR's list
922 of subtrees. If \fInode\fR is a leaf (has no children),
923 then \fB-1\fR is returned.
924 .TP
925 \fItreeName\fR \fBmodify\fR \fItagnode\fR \fIkey value\fR ?\fIkey value\fR...?
926 Update one or more fields in one or more nodes in \fItagnode\fR.
927 As with \fBset\fR, \fInode\fR
928 can be a tag referring to multiple nodes.
929 This is identical to \fBset\fR, except an error is thrown if
930 any of the key fields do not exist.
931 Despite the error, all nodes that do have said fields get updated.
932 For modifying a single node, see \fBupdate\fR.
933 .TP
934 \fItreeName\fR \fBmove\fR \fInode\fR \fInewParent\fR ?\fIswitches\fR?
935 Moves \fInode\fR into \fInewParent\fR. \fINode\fR is appended to the
936 list children of \fInewParent\fR. \fINode\fR can not be an ancestor
937 of \fInewParent\fR. The valid flags for \fIswitches\fR are described below.
938 .RS
939 .TP 1i
940 \fB\-after\fR \fIchild\fR
941 Position \fInode\fR after \fIchild\fR. The node \fIchild\fR must be a
942 child of \fInewParent\fR.
943 .TP 1i
944 \fB\-before\fR \fIchild\fR
945 Position \fInode\fR before \fIchild\fR. The node \fIchild\fR must be a
946 child of \fInewParent\fR.
947 .TP 1i
948 \fB\-pos\fR \fInumber\fR
949 Inserts \fInode\fR into \fIparent\fR's list of children at
950 position \fInumber\fR. The default is -1 to append the node.
951 .RE
952 .TP
953 \fItreeName\fR \fBnames\fR \fInode\fR ?\fIkey\fR? ?\fIpattern\fR?
954 Return key names for \fInode\fR, in the order defined (if possible).
955 If a key is given, attempts to return ARRAY fields (see DICT-ARRAYS).
956 If a pattern is given, the array keys are limited
957 to those matching the glob pattern.
958 An error is thrown if the convert to array fails (ie. list-length is odd).
959 The \fBtype\fR command can be used to query the type.
960 See also \fBvalues\fR.
961 .TP
962 \fItreeName\fR \fBnext\fR \fInode\fR
963 Returns the next node from \fInode\fR in a preorder traversal.
964 If \fInode\fR is the last node in the tree,
965 then \fB-1\fR is returned.
966 .TP
967 \fItreeName\fR \fBnextsibling\fR \fInode\fR
968 Returns the node representing the next subtree from \fInode\fR
969 in its parent's list of children. If \fInode\fR is the last child,
970 then \fB-1\fR is returned.
971 .TP
972 \fItreeName\fR \fBnodeseq\fR ?\fIstart\fR?
973 Get or set the \fIstart\fR sequence number for subsequent
974 node insertions not using \fB-node\fR. The default is 0.
975 .TP
976 \fItreeName\fR \fBnotify\fR \fIargs\fR
977 Manages notification events that indicate that the tree structure has
978 been changed.
979 See the
980 .SB "NOTIFY OPERATIONS"
981 section below.
982 .TP
983 \fItreeName\fR \fBoldvalue\fR ?\fInewvalue\fR?
984 Return the value from before the last (untraced) change operation.
985 This is used primarly by write traces wishing to
986 restore a key to it's pre-write value (eg. read-only variables).
987 The oldvalue is saved internally everytime a change operation occurs
988 to a key value by deferring its deallocation.
989 Changes made during node traces do not affect oldvalue.
990 .sp
991 If \fInewvalue\fR is provided, the current value of oldvalue is
992 discarded and replaced. This is useful really only for releasing large objects.
993 .TP
994 \fItreeName\fR \fBparent\fR \fInode\fR
995 Returns the parent node of \fInode\fR. If \fInode\fR is the root
996 of the tree,
997 then \fB-1\fR is returned.
998 .TP
999 \fItreeName\fR \fBpath\fR \fInode\fR ?\fIdelim\fR? ?\fIprefix\fR?
1000 Returns the full path (from root) of \fInode\fR using the node labels.
1001 If \fIdelim\fR is not specified, the result is a list.
1002 Otherwise, the result is a string starting with \fIprefix\fR and
1003 each element of the path separated by \fIdelim\fR.
1004 This latter form is useful for building tags like: \fB.able.baker\fR
1005 .TP
1006 \fItreeName\fR \fBposition\fR ?\fB-sort\fR? ?\fB-format\fR \fIftype\fR? \fInode\fR ?\fInode\fR ...?
1007 Returns the position of the node(s) in its parent's list of children.
1008 Positions are numbered from 0.
1009 The position of the root node is always 0.
1010 The value of \fIftype\fR is one of:
1011 \fBposition parent-at-position id+position id+parent-at-position\fR.
1012 .TP
1013 \fItreeName\fR \fBprevious\fR \fInode\fR
1014 Returns the previous node from \fInode\fR in a preorder traversal.
1015 If \fInode\fR is the root of the tree,
1016 then \fB-1\fR is returned.
1017 .TP
1018 \fItreeName\fR \fBprevsibling\fR \fInode\fR
1019 Returns the node representing the previous subtree from \fInode\fR
1020 in its parent's list of children. If \fInode\fR is the first child,
1021 then \fB-1\fR is returned.
1022 .TP
1023 \fItreeName\fR \fBrestore\fR \fInode\fR \fIswitches\fR
1024 Performs the inverse function of the \fBdump\fR operation, restoring
1025 nodes to the tree. The format of the input data is exactly what is
1026 returned by the \fBdump\fR operation. It's a list containing information
1027 for each node to be restored. The information consists of 1) the relative
1028 path of the node, 2) a sublist of key value pairs representing the
1029 node's data, 3) a list of tags for the node, and 4) the label.
1030 Nodes are created
1031 starting from \fInode\fR. Nodes can be listed in any order. If a node's
1032 path describes ancestor nodes that do not already exist, they are
1033 automatically created.
1034 .sp
1035 The valid \fIswitches\fR are listed below. Exactly one
1036 of \fB-channel\fR, \fB-file\fR or \fB-data\fR must be specified.
1037 .RS
1038 .TP
1039 \fB\-addtags\fR
1040 List of tags to add to each node restored node.
1041 Each tag will be created only if a node loaded.
1042 .TP
1043 \fB\-channel \fIchan\fR
1044 Obtain data from from the given channel \fIchan\fR.
1045 The channel is not closed afterwards.
1046 .TP
1047 \fB\-data \fIstring\fR
1048 Data input is from the given \fIstring\fR.
1049 .TP
1050 \fB\-file \fIfileName\fR
1051 Obtain data from from the file.
1052 \fIfileName\fR. This options is unsupported in a safe interp.
1053 .TP
1054 \fB\-keys \fIlist\fR
1055 A list of patterns of matching keys to be restored.
1056 .TP
1057 \fB\-skipkeys \fIlist\fR
1058 A list of patterns of matching keys not to be restored.
1059 .TP
1060 \fB\-tag \fIpattern\fR
1061 A pattern match for tags to include in a node restore.
1062 .TP
1063 \fB\-skiptag \fIpattern\fR
1064 A pattern match for tags to not include in a node restore.
1065 .TP
1066 \fB\-notags\fR
1067 Do not restore any tags
1068 .TP
1069 \fB\-overwrite\fR
1070 Overwrite nodes that already exist. Normally nodes are always
1071 created, even if there already exists a node by the same name. This
1072 switch indicates to overwrite existing node's data fields.
1073 .RE
1074 .TP
1075 \fItreeName\fR \fBroot\fR ?\fInode\fR?
1076 Returns the id of the root node. Normally this is node \fB0\fR. If
1077 a \fInode\fR argument is provided, it will become the new root of the
1078 tree. This lets you temporarily work within a subset of the tree.
1079 Changing root affects operations such as \fBnext\fR, \fBpath\fR,
1080 \fBprevious\fR, etc.
1081 .TP
1082 \fItreeName\fR \fBset\fR \fItagnode\fR \fIkey value\fR ?\fIkey value\fR...?
1083 Sets one or more data fields in \fInode\fR. \fItagode\fR may
1084 be a tag that represents several nodes and a count of the number
1085 of nodes updated is returned.
1086 \fIKey\fR is the
1087 name of the data field to be set, or an array-like reference such as \fBfield(subkey)\fR.
1088 See the
1089 .SB "DICT-ARRAYS"
1090 section below. \fIValue\fR is the respective keys value.
1091 The \fIKey\fR will be created if it does not exists (see \fBmodify\fR).
1092 .sp
1093 The set operation triggers \fBwrite\fR and \fBcreate\fR data traces.
1094 .TP
1095 \fItreeName\fR \fBsize\fR \fInode\fR
1096 Returns the number of nodes in the subtree. This includes the node
1097 and all its descendants. The size of a leaf node is 1.
1098 .TP
1099 \fItreeName\fR \fBsort\fR \fInode\fR ?\fIswitches\fR?
1100 Return nodes in sorted order.
1101 .RS
1102 .TP 1i
1103 \fB\-ascii\fR
1104 Compare strings using the ASCII collation order.
1105 .TP 1i
1106 \fB\-command\fR \fIstring\fR
1107 Use command \fIstring\fR as a comparison command. To compare two
1108 elements, evaluate a Tcl script consisting of command with the five
1109 elements appended as additional arguments:
1110 \fIthe tree, node1, node1, label1, label2\fR.
1111 The script should return
1112 an integer less than, equal to, or greater than zero if the first
1113 element is to be considered less than, equal to, or greater than the
1114 second, respectively.
1115 .TP 1i
1116 \fB\-decreasing\fR
1117 Sort in decreasing order (largest items come first).
1118 .TP 1i
1119 \fB\-dictionary\fR
1120 Compare strings using a dictionary-style comparison. This is the same
1121 as \fB\-ascii\fR except (a) case is ignored except as a tie-breaker and (b)
1122 if two strings contain embedded numbers, the numbers compare as integers, not
1123 characters. For example, in \fB\-dictionary\fR mode, bigBoy sorts between
1124 bigbang and bigboy, and x10y sorts between x9y and x11y.
1125 .TP 1i
1126 \fB\-integer\fR
1127 Compare the nodes as integers.
1128 .TP 1i
1129 \fB\-key\fR \fIstring\fR
1130 Sort based upon the node's data field keyed by \fIstring\fR. Normally
1131 nodes are sorted according to their label.
1132 label.
1133 .TP 1i
1134 \fB\-real\fR
1135 Compare the nodes as real numbers.
1136 .TP 1i
1137 \fB\-recurse\fR
1138 Recursively sort the entire subtree rooted at \fInode\fR.
1139 .TP 1i
1140 \fB\-reorder\fR
1141 Recursively sort subtrees for each node. \fBWarning\fR. Unlike
1142 the normal flat sort, where a list of nodes is returned, this will
1143 reorder the tree.
1144 .TP 1i
1145 \fB\-usepath\fR
1146 Compare the full path of each node. The default is to compare only the node
1147 label.
1148 .RE
1149 .TP
1150 \fItreeName\fR \fBsqlload\fR ?\fIswitches\fR? \fIdbhfile\fR \fIsqlstmt\fR
1151 Load tree with the results of evaling the SQL in \fIsqlstmt\fR using
1152 \fIdbhfile\fR.
1153 The evaluated SQL creates one tree-node per row result.
1154 The returned value is the number of rows loaded.
1155 \fIDbhfile\fR is either an \fBsqlite3\fR database handle,
1156 or an \fBsqlite3\fR file.
1157 .sp
1158 The \fBsqlload\fR command can populate a tree with 10k nodes
1159 about 7 times faster than \fBsqlite3 eval\fR.
1160 It also preserves NULL values
1161 and object types (eg. int or double) used internally
1162 by sqlite. This eliminates later reconversion within tree.
1163 See the
1164 .SB "SQLLOAD EXAMPLE"
1165 below.
1166 .sp
1167 The following switches are available:
1168 .RS
1169 .TP 1i
1170 \fB\-addtags \fItaglist\fR
1171 The tags in \fItaglist\fR to add to each inserted node.
1172 Each tag will be created only if a node loaded.
1173 .TP 1i
1174 \fB\-fixed\fR
1175 Set the \fBfixed\fR flag to disallow new keys after creation.
1176 .TP 1i
1177 \fB\-key \fIname\fR
1178 Store the entire result in the key \fIname\fR instead
1179 of creating one key per column.
1180 Array notation can be used to then access column results.
1181 This is more efficent as it initially stores just one
1182 object per row. Conversion to an array
1183 is at the first array access (if that occurs).
1184 .TP 1i
1185 \fB\-labelcol \fIcolumn\fR
1186 The value of \fIcolumn\fR is used as the label.
1187 By default the label is the node id.
1188 .TP 1i
1189 \fB\-maprowid \fInum\fR
1190 This option maps the node id to the rowid plus the constant \fInum\fR.
1191 The key for \fBrowid\fR will also not be created.
1192 This is applicable only if \fBrowid\fR is returned in the result-set
1193 of \fIsqlstmt\fR.
1194 If \fBrowid\fR is not in the result set, this option is ignored.
1195 If mapping fails (because the tree already contains a requested node)
1196 the load will abort at that point
1197 with an error. Note that \fInum\fR must be >= 1 since sqlite
1198 rowids start from 0, but the root node of the tree uses the node-id 0.
1199 .TP 1i
1200 \fB\-max \fInum\fR
1201 The maximum number of rows to return. The default is 100,000.
1202 Note that SQL queries on large tables should probably always use LIMIT.
1203 .TP 1i
1204 \fB\-nullvalue \fIstring\fR
1205 Define value to use for null values. The default is no value,
1206 meaning do not set key if value is null.
1207 Note this is different from the sqlite Tcl extension which uses
1208 an empty string for NULL.
1209 .TP 1i
1210 \fB\-parent \fIstring\fR
1211 The node where results are
1212 inserted as child nodes. The default is the tree root.
1213 .TP 1i
1214 \fB\-pathcol \fIcolumn\fR
1215 Name of column containing the full path where node is to be created.
1216 This works like \fB\-treecols\fR, but uses a singl columns.
1217 .TP 1i
1218 \fB\-skipcols \fIcolumns\fR
1219 The given \fIcolumns\fR are not to be added as keys. This is useful mostly
1220 in conjuction with \fB-tagcol\fR, \fB-labelcol\fR, \fB-pathcol\fR.
1221 .TP 1i
1222 \fB\-pos \fInum\fR
1223 Where to insert into parents list of children.
1224 Default is -1, meaning to append.
1225 .TP 1i
1226 \fB\-tagcol \fIcolumn\fR
1227 The value of \fIcolumn\fR is added as a tag.
1228 .TP 1i
1229 \fB\-treecols \fIcolumns\fR
1230 Columns whose values concatenated
1231 give the path of where node is to be created.
1232 This works like \fB\-pathcol\fR, but uses multiple columns.
1233 .RE
1234 .TP
1235 \fItreeName\fR \fBsum\fR ?\fIswitches\fR? \fItagnode key\fR ?\fIkey ...\fR?
1236 Add values in key fields for all \fItagnode\fR and return the sum.
1237 Values that are not doubles (or integer) are ignored.
1238 .RS
1239 .TP 1i
1240 \fB\-diff\fI value\fR
1241 Double value difference to ignore and not do update for \fB-runtotal\fR.
1242 This is unused when using \fB\-int\fR.
1243 .TP 1i
1244 \fB\-force\fR
1245 Force update \fB-runtotal\fR even if value was unchanged.
1246 Normally, a check is made to avoid updating unchanged values.
1247 .TP 1i
1248 \fB\-int\fR
1249 Use and accept only integer values.
1250 .TP 1i
1251 \fB\-runtotal \fIkey\fR
1252 Place running total in the given key field (if changed).
1253 .TP 1i
1254 \fB\-start \fInum\fR
1255 The start value for the sum: default is 0.
1256 .RE
1257 .TP
1258 \fItreeName\fR \fBsupdate\fR \fInode\fR \fIkey value\fR ?\fIkey value\fR...?
1259 Like \fBupdate\fR, but uses a string comparison
1260 to avoid writes if the value will not be changed. This is useful primarily
1261 for avoiding unnecessary write traces.
1262 .TP
1263 \fItreeName\fR \fBtag\fR \fIargs\fR
1264 Manages tags for the tree object.
1265 See the
1266 .SB "TAG OPERATIONS"
1267 section below.
1268 .TP
1269 \fItreeName\fR \fBtrace\fR \fIargs\fR
1270 Manages traces for data fields in the tree object.
1271 Traces cause Tcl commands to be executed whenever a data field of a
1272 node is created, read, written, or unset. Traces can be set for a
1273 specific node or a tag, representing possibly many nodes.
1274 See the
1275 .SB "TRACE OPERATIONS"
1276 section below.
1277 .TP
1278 \fItreeName\fR \fBtype\fR \fInode\fR \fIkey\fR
1279 Return type of value. This is the introspected type from the Tcl_Obj
1280 value passed to set.
1281 .TP
1282 \fItreeName\fR \fBupdate\fR \fInode\fR \fIkey value\fR ?\fIkey value\fR...?
1283 Like \fBmodify\fR, except an error is generated if a tag
1284 is used that applies to more than one node.
1285 .TP
1286 \fItreeName\fR \fBunset\fR \fInode\fR \fIkey\fR...
1287 Removes one or more data fields from \fInode\fR. \fINode\fR may
1288 be a tag that represents several nodes. \fIKey\fR is the
1289 name of the data field to be removed. It's not an error is
1290 \fInode\fR does not contain \fIkey\fR.
1291 A count of the number of nodes unset is returned.
1292 This operation may trigger \fBunset\fR data traces.
1293 .TP
1294 \fItreeName\fR \fBvalues\fR \fInode\fR ?\fIkey\fR? ?\fIwithnames\fR?
1295 Return values for \fInode\fR.
1296 The values are returned in the same order as the keys
1297 returned from \fBnames\fR.
1298 .sp
1299 If a \fIkey\fR is given,
1300 array values get returned for the \fIkey\fR value.
1301 If \fIwithname\fR is \fBTrue\fR, then key
1302 names are also returned with the values. This differs from \fBget\fR
1303 in that the result is a true Tcl list object, not an array object.
1304 If subsequently using an array value in a list context,
1305 this can be more efficient by
1306 avoiding a split on string representations.
1307 .TP
1308 \fItreeName\fR \fBvecdump\fR \fIvector\fR \fIkey\fR ?\fItagnode\fR?
1309 Dump key field to a vector. With no \fItagnode\fR, dumps every node
1310 to the 1-1 corresponding vector index. With \fItag\fR dumps
1311 nodes to consequetive vector elements.
1312 .TP
1313 \fItreeName\fR \fBvecload\fR \fIvector\fR \fIkey\fR ?\fItagnode\fR?
1314 Loads key field from a vector. With no \fItagnode\fR, loads every node
1315 from the 1-1 corresponding vector index. With \fItag\fR loads
1316 nodes from consequetive vector elements.
1317 .TP
1318 \fItreeName\fR \fBwith\fR \fIvariable\fR ?\fIswitch\fR? \fItagnode script\fR
1319 For each node in \fItagnode\fR,
1320 evaluate the \fIscript\fR after assigning key values to
1321 elements of the array \fIvariable\fR.
1322 The \fB-keys\fR limits which keys may be assigned.
1323 If \fIscript\fR completes normally,
1324 and any of the key values change in the \fIvariable\fR, then the
1325 updates are reflected back into the key values
1326 (unless \fB-noupdate\fR is used).
1327 Unsetting a variable key
1328 will cause that change to be ignored. New elements added to the
1329 array variable are ignored.
1330 .sp
1331 Doing a \fBreturn\fR, \fBbreak\fR, or \fBcontinue\fR inside
1332 \fIscript\fR will still cause updates to copy back, but
1333 processing will stop and (unless \fB-break\fR is used)
1334 the return code will become the return code to the caller.
1335 This means that a \fBbreak\fR, \fBcontinue\fR, and
1336 \fBreturn\fR will propagate up through
1337 multiple nested \fBwith\fR statements to the
1338 to an enclosing \fBforeach\fR, \fBwhile\fR, etc.
1339 But \fB-break\fR can be used to change this, making \fBwith\fR behave more
1340 like a \fBforeach\fR loop.
1341 .sp
1342 If \fB-keys\fR is not used, the list of key names will be
1343 stored in \fIvariable(*)\fR and the node id
1344 stored in \fIvariable(#)\fR (which could then
1345 be overwritten by a key of that name).
1346 By default, the array is not cleaned up before or after each execution.
1347 However, if \fB-unset\fR is used, the array is unset at the start of each
1348 iteration, and \fB-init\fR can be used to specify a default value.
1349 Also, long running queries can speed up by initializing variables
1350 prior to the call to \fBwith\fR.
1351 .sp
1352 If the \fIvariable\fR name string is zero length, an simple
1353 variables are used instead of an array,
1354 and * and # do not get set.
1355 Note, when not using -keys, arbitrary local variables can get overwritten.
1356 .sp
1357 If \fB-array\fR is used, \fBwith\fR operates on the keys of an tree array/dict
1358 instead of the keys of the node.
1359 .sp
1360 Upon normal completion, the number of times \fIscript\fR
1361 was evaluated is returned.
1362 .sp
1363 The valid switches are listed below:
1364 .RS
1365 .TP 1i
1366 \fB-array\fR \fIkey\fR
1367 Specifies a
1368 single key that is to be treated as an array-dict.
1369 The fields of the array for that one key are then used
1370 (instead of keys from the whole node).
1371 This changes the meaning of \fB-keys\fR and \fB-glob\fR to be the
1372 keys of the array rather than the keys of the node.
1373 Nodes missing the given array key will be skipped.
1374 If a key value can not be converted to an array,
1375 an error will occur.
1376 .TP 1i
1377 \fB-break\fR
1378 Treat \fBbreak\fR and \fBcontinue\fR like \fBforeach\fR does
1379 rather than just passing them up to the enclosing script body.
1380 .TP 1i
1381 \fB-init\fI value\fR
1382 Variables specified by \fB-keys\fR are to be initialized to \fIvalue\fR
1383 for each node where key is missing.
1384 .TP 1i
1385 \fB-keys\fR \fIkeylist\fR
1386 Copy only the named keys and does not set (*).
1387 .TP 1i
1388 \fB-glob\fR \fIpattern\fR
1389 Pattern to limit matching keys. Can not be used with \fB-keys\fR.
1390 .TP 1i
1391 \fB-noupdate\fR
1392 Ignore changes to array variables. This
1393 do not copy changed variables back into tree nodes.
1394 .TP 1i
1395 \fB-unset\fR
1396 Unset the array variable at the begin of each evaluation.
1397 .RE
1398 .RE
1399 .SH DICT-ARRAYS
1400 Round braces can be used to access sub-values of a key value.
1401 In effect, this means each key value can be an array (or dict), eg.
1402 .PP
1403 .CS
1404 set t [tree create]
1405 set n [$t insert 0 -data {a 1 b 2 c "x 9 y 8 z 7"}]
1406 $t get $n; # a 1 b 2 c {x 9 y 8 z 7}
1407 $t get $n c; # x 9 y 8 z 7
1408 $t get $n c(y); # 8
1409 $t update $n c(y) 8.6
1410 $t get $n c; # x 9 y 8.6 z 7
1411 $t unset $n c(y)
1412 $t get $n c; # x 9 z 7
1413 $t set $n d 10
1414 $t incr $n d
1415 .CE
1416 .PP
1417 If a key value is a dict object tree will make use of it.
1418 If not, on access it converts the value to a pure \fBarray\fR hash object.
1419 The following example shows the type in a comment after each operation.
1420 .PP
1421 .CS
1422 set t [tree create]
1423 $t insert 0 -label A;
1424 $t set 0->A X [dict create a 1 b 2 c 3]; # dict
1425 array set q { x 1 y 2 };
1426 $t set 0->A Y [array get q]; # dict
1427 $t set 0->A Z {m 0 n 1}; # string
1428 $t incr 0->A Z(m); # array
1429 dict size [$t get 0->A Z]; # dict
1430 .CE
1431 .PP
1432 One advantage of using a dict is that it preserves order.
1433 See \fBdictset\fR.
1434 .SH TAG OPERATIONS
1435 Tags are a general means of selecting and marking nodes in the tree.
1436 A tag is just a string of characters, and it may take any form except
1437 that of an integer. The same tag may be associated with many
1438 different nodes.
1439 .PP
1440 Most tree operations use tags. And several operations let you
1441 operate on multiple nodes at once. For example, you can use the
1442 \fBset\fR operation with the tag \fBall\fR to set a data field in
1443 for all nodes in the tree.
1444 .PP
1445 Tags are invoked by the \fBtag\fR operation. The
1446 general form is
1447 .DS
1448 \fItreeName\fR \fBtag\fR \fIoperation\fR ?\fIarg\fR?...
1449 .DE
1450 Both \fIoperation\fR and its arguments determine the exact behavior of
1451 the command. The operations available for tags are listed below.
1452 .TP
1453 \fItreeName\fR \fBtag add\fR \fIstring\fR ?\fInode\fR?...
1454 Adds the tag \fIstring\fR to zero or more nodes.
1455 If no nodes are given, just creates the tag.
1456 A count of the number of nodes tagged is returned.
1457 .TP
1458 \fItreeName\fR \fBtag delete\fR \fIstring\fR \fInode\fR...
1459 Remove the tag \fIstring\fR from one or more nodes.
1460 A count of the number of nodes visited is returned.
1461 Calling \fBtag delete\fR with a builtin tag is ignore.
1462 .TP
1463 \fItreeName\fR \fBtag dump\fR \fItagnode\fR ?\fIswitches\fR?
1464 Dump the nodes specified by the tag \fItagnode\fR.
1465 .sp
1466 The valid \fIswitches\fR are listed below.
1467 .RS
1468 .TP
1469 \fB\-keys \fIlist\fR
1470 A list of patterns of matching keys to be dumped.
1471 .TP
1472 \fB\-skipkeys \fIlist\fR
1473 A list of patterns of matching keys not to be dumped.
1474 .TP
1475 \fB\-tag \fIpattern\fR
1476 A pattern match for tags to include in a node dump.
1477 .TP
1478 \fB\-skiptag \fIpattern\fR
1479 A pattern match for tags to not include in a node dump.
1480 .TP
1481 \fB\-notags\fR
1482 Do not dump the tags.
1483 .TP
1484 \fB\-nopath\fR
1485 To save space, do not dump the full path for each node.
1486 Instead output periods for all but the last path element.
1487 Full paths are used only for partial restores.
1488 .RE
1489 .TP
1490 \fItreeName\fR \fBtag exists\fR \fIstring\fR ?\fIid\fR?
1491 If an \fIid\fR is given, return 1 (or 0) if node has (or hasn't) the tag.
1492 Otherwise, returns 1 if at least one nodes has tag \fIstring\fR.
1493 .TP
1494 \fItreeName\fR \fBtag forget\fR \fIstring\fR ?\fIstring\fR ...?
1495 Removes the tag definition for one or more of \fIstring\fR.
1496 It's not an error if the tag \fIstring\fR does not exist.
1497 .TP
1498 \fItreeName\fR \fBtag lookups\fR ?\fIpattern\fR?
1499 Dump a lookup table (dictionary)
1500 of nodes-to-tags, or tags-to-nodes if \fIpattern\fR
1501 is given.
1502 With no arguments, returns a pair list of nodes/tags,
1503 for nodes that have tags.
1504 With an argument, returns a pair list of tags/nodes.
1505 \fBlookups\fR provides efficient bulk processing when dealing with
1506 large numbers of nodes and/or tags.
1507 .TP
1508 \fItreeName\fR \fBtag names\fR ?\fB-glob\fR? ?\fB-regexp\fR? ?\fB-nocase\fR? ?\fInode\fR? ?\fInode ...\fR?
1509 Returns a list of tags used by the tree. If no \fInode\fR argument
1510 is given, returns a list of all known tags. Otherwise, returns
1511 the union of the tags used by all given \fInode\fR numbers.
1512 Patterns can be used via \fB-glob\fR or \fB-regexp\fR.
1513 If \fB-nocase\fR is used, the pattern is expected to be all lower case.
1514 .TP
1515 \fItreeName\fR \fBtag nodes\fR \fIstring\fR ?\fIstring ...\fR?
1516 Returns a list of any nodes that have any of given \fIstring\fR tag. If no node
1517 is tagged with any of the \fIstring\fR, then an empty string is returned.
1518 .SH TRACE OPERATIONS
1519 Data fields can be traced much like tracing Tcl
1520 variables. Data traces cause a Tcl command to be executed whenever
1521 data fields are created, read, written, or unset.
1522 A trace can apply to one or more nodes. You can trace a specific node
1523 by using its id, or a group of nodes by a their tag.
1524 Note: operations on arrays trigger on the whole key value,
1525 not the individual array element.
1526 .PP
1527 The tree's \fBget\fR, \fBset\fR, and \fBunset\fR operations can
1528 trigger various traces. The \fBget\fR operation can cause
1529 a \fIread\fR trace to fire. The \fBset\fR operation causes a \fIwrite\fR
1530 trace to fire. And if the data field is written for the first time, you
1531 will also get a \fIcreate\fR trace.
1532 The \fBunset\fR operation triggers \fIunset\fR traces.
1533 .PP
1534 Data traces are invoked by the \fBtrace\fR
1535 operation. The general form is
1536 .DS
1537 \fItreeName\fR \fBtrace\fR \fIoperation\fR ?\fIarg\fR?...
1538 .DE
1539 Both \fIoperation\fR and its arguments determine the exact behavior of
1540 the command. The operations available for traces are listed below.
1541 .TP
1542 \fItreeName\fR \fBtrace create\fR \fInode\fR \fIkey\fR \fIops\fR \fIcommand\fR ?-bgerror?
1543 Create a trace on data fields (or tags for tag traces)
1544 given by the pattern in \fIkey\fR. The \fInode\fR argument
1545 can be a nodeid, or a tag to refer to multiple nodes eg. \fIall\fR.
1546 The return value is an identifier that can
1547 be used with "\fBtrace info\fR" or "\fBtrace delete\fR".
1548 Traces are temporarily disabled while executing \fIcommand\fR within the trace.
1549 .sp
1550 \fICommand\fR is a command prefix, to which
1551 four arguments are appended before invocation:
1552 \fItreeName\fR, \fInodeid\fR, \fIkey\fR and, \fIops\fR.
1553 If an error occurs in \fIcommand\fR (and \fI-bgerror\fR was not used)
1554 the invoking operation will also abort.
1555 .sp
1556 \fIOps\fR indicates which operations are of
1557 interest. It consists of one or more of the following letters:
1558 .RS
1559 .TP
1560 \fBr\fR
1561 Invoke \fIcommand\fR whenever \fIkey\fR is read.
1562 .TP
1563 \fBw\fR
1564 Invoke \fIcommand\fR whenever \fIkey\fR is written.
1565 .TP
1566 \fBc\fR
1567 Invoke \fIcommand\fR whenever \fIkey\fR is created.
1568 .TP
1569 \fBu\fR
1570 Invoke \fIcommand\fR whenever \fIkey\fR is unset,
1571 typically with the \fBunset\fR command.
1572 to that.
1573 .TP
1574 \fBe\fR
1575 Invoke \fIcommand\fR whenever \fBexists\fR is used on an non-existant
1576 key. This can be used to populate node key data on demand.
1577 .TP
1578 \fBt\fR
1579 Invoke \fIcommand\fR whenever tag \fIkey\fR is added to a node.
1580 .TP
1581 \fBm\fR
1582 Invoke \fIcommand\fR when tag \fIkey\fR gets added to more than one node.
1583 This trace can be used to enforce tags that should be on at most one node.
1584 It can avoid later errors with tags used in
1585 \fBget\fR or other commands not accepting non-unique tags.
1586 .TP
1587 \fBd\fR
1588 Invoke \fIcommand\fR whenever tag \fIkey\fR is \fIdeleted\fR from a node
1589 using either \fBtag delete\fR or \fBtag forget\fR.
1590 Node deletion will not trigger this trace.
1591 .sp
1592 .RE
1593 .TP
1594 \fItreeName\fR \fBtrace delete\fR \fItraceId\fR...
1595 Deletes one of more traces. \fITraceId\fR is
1596 the trace identifier returned by the \fBtrace create\fR operation.
1597 .TP
1598 \fItreeName\fR \fBtrace info\fR \fItraceId\fR
1599 Returns information about the trace \fItraceId\fR. \fITraceId\fR
1600 is a trace identifier previously returned by the \fBtrace create\fR operation.
1601 It's the same information specified for the \fBtrace create\fR operation.
1602 It consists of the node id or tag, data field key, a string of letters
1603 indicating the operations that are traced (it's in the same
1604 form as \fIops\fR) and, the command prefix.
1605 .TP
1606 \fItreeName\fR \fBtrace names\fR
1607 Returns a list of identifers for all the current traces.
1608 .SH NOTIFY OPERATIONS
1609 The purpose of \fBnotify\fR is to get control when structural operations
1610 occur on a tree. This is used internally by \fBtreeview\fR or example when a
1611 tree object is shared. A client may create nodes,
1612 sort a tree, move a node, etc. Notifier
1613 can cause such operations to generate events,
1614 resulting in Tcl commands being executed.
1615 .PP
1616 The general form of \fBnotify\fR is:
1617 .PP
1618 .RS
1619 \fItreeName\fR \fBnotify\fR \fIoperation\fR ?\fIarg\fR?...
1620 .RE
1621 .PP
1622 The available \fIoperation\fR are as follows:
1623 .TP
1624 \fItreeName\fR \fBnotify create\fR ?\fIswitches\fR? \fIcommand\fR ?\fIargs\fR?...
1625 Creates a notifier for the tree. A notify identifier in the form
1626 "\fBnotify0\fR", "\fBnotify1\fR", etc. is returned.
1627 .sp
1628 \fICommand\fR and \fIargs\fR are saved and invoked whenever the tree
1629 structure is changed (controlled by \fIswitches\fR). Two arguments are
1630 appended to \fIcommand\fR and \fIargs\fR before it's invoked: the id
1631 of the node and a string representing the type of event that occured.
1632 If an error is returned by \fIcommand\fR
1633 the invoking operation returns an error (when not using \fI-whenidle\fR).
1634 One or more of the following switches are used to indicate the events
1635 that are of interest:
1636 .RS
1637 .TP 1i
1638 \fB\-bgerror\fR
1639 Generate a background error if an error occurs.
1640 .TP 1i
1641 \fB\-create\fR
1642 Invoke \fIcommand\fR whenever a new node is added.
1643 This is called after the creation. Returning an error will
1644 delete the node.
1645 .TP 1i
1646 \fB\-delete\fR
1647 Invoke \fIcommand\fR whenever a node has been deleted.
1648 This is called before the delete starts to allow aborting it with an error.
1649 Deletes resulting from failed inserts are ignored.
1650 .TP 1i
1651 \fB\-disabletrace\fR
1652 Disable traces from firing during a notify event.
1653 .TP 1i
1654 \fB\-get\fR
1655 Invoke \fIcommand\fR whenever a node with no keys is accessed (via \fBget\fR
1656 or \fBwith\fR).
1657 If a node has at least one key, this will not trigger.
1658 The invocation occurs before the read, meaning it can
1659 be used to implement demand loading of data keys into empty nodes
1660 (eg. loading database row data on read).
1661 .TP 1i
1662 \fB\-insert\fR
1663 Invoke \fIcommand\fR when an \fBinsert\fR completes.
1664 This differs from \fB-create\fR in that the call occurs
1665 after the label, tags and data are added (but before
1666 \fB-fixed\fR gets set).
1667 This trace applies to the subcommands \fBcreate\fR, \fBcopy\fR,
1668 \fBrestore\fR, \fBsqlload\fR, and
1669 \fBinsert\fR (both tree and treeview).
1670 It is useful for verifying key-data, tags and labels.
1671 Returning an error will delete the node and cause the
1672 originating command to generate an error.
1673 .TP 1i
1674 \fB\-move\fR
1675 Invoke \fIcommand\fR at the start of a node move.
1676 .TP 1i
1677 \fB\-movepost\fR
1678 Invoke \fIcommand\fR after a node has been moved.
1679 .TP 1i
1680 \fB\-sort\fR
1681 Invoke \fIcommand\fR whenever the tree has been sorted and reordered.
1682 .TP 1i
1683 \fB\-relabel\fR
1684 Invoke \fIcommand\fR at the start of a node relabel.
1685 .TP 1i
1686 \fB\-relabelpost\fR
1687 Invoke \fIcommand\fR after a node has been relabeled.
1688 .TP 1i
1689 \fB\-allevents\fR
1690 Invoke \fIcommand\fR whenever any of the above events occur.
1691 .TP 1i
1692 \fB\-whenidle\fR
1693 When an event occurs don't invoke \fIcommand\fR immediately, but
1694 queue it to be run the next time the event loop is entered and there
1695 are no events to process. If subsequent events occur before
1696 the event loop is entered, \fIcommand\fR will still be
1697 invoked only once.
1698 .RE
1699 .TP
1700 \fItreeName\fR \fBnotify delete\fR \fInotifyId\fR
1701 Deletes one or more notifiers from the tree. \fINotifyId\fR is the
1702 notifier identifier returned by the \fBnotify create\fR operation.
1703 .TP
1704 \fItreeName\fR \fBnotify info\fR \fInotifyId\fR
1705 Returns information about the notify event \fInotifyId\fR. \fINotifyId\fR
1706 is a notify identifier previously returned by the \fBnotify create\fR operation.
1707 It's the same information specified for the \fBnotify create\fR operation.
1708 It consists of the notify id, a sublist of event flags (it's in the same
1709 form as \fIflags\fR) and, the command prefix.
1710 .TP
1711 \fItreeName\fR \fBnotify names\fR
1712 Returns a list of identifers for all the current notifiers.
1713
1714 .SH TABLE EXAMPLE
1715 The following is a simple example.
1716 .sp
1717 .CS
1718 variable Users {
1719 tom { Name "Tom Brown" Sex M Age 19 Class {4 5} Rate {A 1 B 2}}
1720 mary { Name "Mary Brown" Sex F Age 16 Class {5} Rate {A 2}}
1721 sam { Name "Sam Spade" Sex M Age 19 Class {3 4} Rate {B 3}}
1722 }
1723 set t [tree create]
1724 foreach {i d} $Users {
1725 # Use name in -tags so we don't have to do "0->mary" etc.
1726 $t insert 0 -tags $i -data $d -label $i
1727 }
1728
1729 $t update tom Sex F Name "Tomi Brown"
1730 $t append sam Name " Jr"
1731 $t lappend sam Class 5
1732 $t incr mary Age
1733 $t update tom Rate(A) 2
1734 $t incr 0->mary Age
1735
1736 # Set a trace.
1737 proc ::Aupd {t id key op} { tclLog "AA: $t $id $key $op" }
1738 $t trace create all Age w ::Aupd
1739 $t incr mary Age
1740
1741 # Display it.
1742 pack [treeview .t -tree $t] -fill both -expand y
1743 eval .t column insert end [$t keys all]
1744 .CE
1745 .SH TREE EXAMPLE
1746 The following is a nested tree example with updates.
1747 .sp
1748 .CS
1749 variable Info {
1750 system {
1751 sol { OS Linux Version 3.4 }
1752 bing { OS Win Version 7 }
1753 gui { OS Mac Version 8 }
1754 }
1755 network {
1756 intra { Address 192.168.1 Netmask 255.255.255.0 }
1757 dmz { Address 192.168.10 Netmask 255.255.255.0 }
1758 wan { Address 0.0.0.0 Netmask 0.0.0.0 Class {A 1 B 4}}
1759 }
1760 admins {
1761 sully { Name "Sully Van Damme" Level 3 }
1762 maverick { Name "Maverick Gump" Level 1 }
1763 }
1764 }
1765
1766 set s [tree create]
1767 foreach {n vals} $Info {
1768 set ind [$s insert 0 -label $n]
1769 foreach {i d} $vals {
1770 $s insert $ind -label $i -data $d
1771 }
1772 }
1773
1774 set old [$s get 0->system->bing]
1775 $s update 0->system->bing OS Linux Version 3.4
1776 $s update 0->network->dmz Address 192.168.11
1777 $s update 0->network->wan Class(A) 2
1778 eval $s set 0->system->bing $old
1779 $s insert 0->admins -label linus -data { Name "Linus Torvalds" Level 9 }
1780
1781
1782 pack [treeview .s -tree $s -width 600] -fill both -expand y
1783 eval .s column insert end [$s keys all]
1784 .CE
1785 .SH SQLLOAD EXAMPLE
1786 Here is an example using \fBsqlload\fR on table \fIcust\fR from a
1787 database file, and displaying it in a treeview:
1788 .CS
1789 set t [tree create]
1790 $t sqlload mydb.dat "select rowid,* from cust"
1791 pack [treeview .t -tree $t -width 500] -fill both -expand y
1792 eval .t column insert end [lsort [$t keys all]]
1793 .CE
1794 Although there is no corresponding \fBsqldump\fR command,
1795 scripting it is easy. Following
1796 is one approach.
1797 .CS
1798 proc sqldump {t db table {ids {}}} {
1799 # Dump nodes from tree t into table in open sqlite database db.
1800 if {$ids == {}} { set ids [$t children root] }
1801 set keys [$t keys $ids]
1802 catch { $db eval "CREATE TABLE $table ( [join $keys ,] )" }
1803 $t with s $ids {
1804 set nams {}
1805 set vals {}
1806 foreach nam $s(*) {
•1807 lappend vals $s($nam)
1808 lappend nams $nam
1809 }
1810 set vals [join $vals ,]
1811 set nams [join $nams ,]
1812 set q [format {INSERT INTO %s (%s) VALUES (%s)} $table $nams $vals]
1813 $db eval $q
1814 }
1815 }
1816 sqlite3 [set db dbhandle] mydb.dat
1817 sqldump $t $db cust2
1818 .CE
1819 .SH TREE KEY STRING STORAGE
1820 Key name strings
1821 are stored by default in a global hash table.
1822 However, sometimes this can be undesirable (eg. with threading),
1823 and so the behavior may be changed (at tree create time only).
1824 To enable per-interp storage of keys, set
1825 \fBblt::treeKeysLocal\fR to 1 before tree creation.
1826 To enable per-tree storage of keys, set
1827 \fBblt::treeKeysLocal\fR to 2 before tree creation.
1828 The above is unavailable in safe interps.
1829 .SH C LANGUAGE API
1830 Blt_TreeApply,
1831 Blt_TreeApplyBFS,
1832 Blt_TreeApplyDFS,
1833 Blt_TreeChangeRoot,
1834 Blt_TreeCreate,
1835 Blt_TreeCreateEventHandler,
1836 Blt_TreeCreateNode,
1837 Blt_TreeCreateTrace,
1838 Blt_TreeDeleteEventHandler,
1839 Blt_TreeDeleteNode,
1840 Blt_TreeDeleteTrace,
1841 Blt_TreeExists,
1842 Blt_TreeFindChild,
1843 Blt_TreeFirstChild,
1844 Blt_TreeFirstKey,
1845 Blt_TreeGetNode,
1846 Blt_TreeGetToken,
1847 Blt_TreeGetValue,
1848 Blt_TreeIsAncestor,
1849 Blt_TreeIsBefore,
1850 Blt_TreeIsLeaf,
1851 Blt_TreeLastChild,
1852 Blt_TreeMoveNode,
1853 Blt_TreeName,
1854 Blt_TreeNextKey,
1855 Blt_TreeNextNode,
1856 Blt_TreeNextSibling,
1857 Blt_TreeNodeDegree,
1858 Blt_TreeNodeDepth,
1859 Blt_TreeNodeId,
1860 Blt_TreeNodeLabel,
1861 Blt_TreeNodeParent,
1862 Blt_TreePrevNode,
1863 Blt_TreePrevSibling,
1864 Blt_TreeRelabelNode,
1865 Blt_TreeReleaseToken,
1866 Blt_TreeRootNode,
1867 Blt_TreeSetValue,
1868 Blt_TreeSize,
1869 Blt_TreeSortNode, and
1870 Blt_TreeUnsetValue.
1871 .SH KEYWORDS
1872 tree, treeview, widget