annotate lisp/oobr/tree-nx/Tree.h @ 120:cca96a509cfe r20-1b12

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