annotate pkg-src/tree-nx/Tree.h @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1 //
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2 // Tree.h -- a generic class to build tree data structures
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3 // This class requires the String class, also by Don Yacktman.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4 // Written by Don Yacktman (c) 1993 by Don Yacktman.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
5 // All rights reserved.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
6 //
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
7 // Subclasses should be designed to hold more data than just children and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
8 // a String-based label...That's where the usefulness of the class
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
9 // becomes apparent. By using a list, any number of children is ok.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
10 //
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
11 // You may use and copy this class freely as long as you
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
12 // comply with the following terms:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
13 // (1) If you use this class in an application which you
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
14 // intend to sell commercially, as shareware, or otherwise,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
15 // you may only do so with express written permission
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
16 // of the author. Use in applications which will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
17 // be distributed free of charge is encouraged.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
18 // (2) You must include the source code to this object and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
19 // all accompanying documentation with your application,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
20 // or provide it to users if requested, free of charge.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
21 // (3) Do not remove the author's name or any of the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
22 // copyright notices
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
23 //
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
24
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
25 #import <appkit/appkit.h> // superclass is in there
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
26 #import <stdio.h>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
27 #import "String.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
28
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
29 @interface Tree:Object
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
30 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
31 id branches; // an instance of the list class
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
32 id label; // node name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
33 id value; // must be a string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
34 BOOL notCollapsed; // print children when dumping if true.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
35 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
36
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
37
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
38 // init with null label
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
39 - init;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
40
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
41 // designated initializer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
42 - initLabel:(const char *)newLabel; // send a char* string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
43 - initLabelString:string; // send a String object
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
44
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
45 // access to the label of this node
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
46 - setLabel:(const char *)newLabel; // send a char* string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
47 - (const char *)label;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
48
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
49 // access to the value of this node
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
50 - setValue:newValue; // send a String object
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
51 - (const char *)value;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
52
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
53 // clean up our mess
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
54 - free;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
55
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
56 // add a new child node
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
57 - addBranch:child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
58
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
59 // Print the tree to a stream (file, whatever). Call the root with level
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
60 // set to zero, and set the indent string however you like; the indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
61 // string should be something like " " or "\t" to show how to indent to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
62 // the next level. This method recursively traverses the tree's children.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
63 - dumpTree:(NXStream *)file level:(int)lev indent:(const char *)ind;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
64
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
65 // set whether or not we print the children (we don't if collapsed)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
66 // when dumping. This does NOT affect the tree's width or depth!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
67 - collapse;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
68 - uncollapse;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
69 - (BOOL)collapsed;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
70
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
71 // when dumping the tree, if you want to add extra data to the output
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
72 // before the newline and before children are printed, add it here. If
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
73 // you return NO, then the children won't be printed; this is how the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
74 // collapse stuff works.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
75 - (BOOL)moreData:(NXStream *)file level:(int)lev indent:(const char *)ind;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
76
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
77 // How deep or wide is the tree?
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
78 - (int) width;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
79 - (int) depth;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
80
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
81 // Return the List object that contains ids of all the kids.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
82 - branches;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
83
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
84 @end