ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/TreeNode.pm
Revision: 1.2
Committed: Fri Aug 20 09:07:24 1999 UTC (25 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.1: +15 -7 lines
Log Message:
Single node find() functionality tested

File Contents

# User Rev Content
1 williamc 1.1 #
2     # TreeNode - associate an object to a tree node in order to link it in
3     # to a searchable tree like structure
4     #
5     # Interface
6     # -----------
7     # new(name) : The name is just a plain string
8     # setparent(parentnode) : Set the parent node
9 williamc 1.2 # parent() : return the parent node
10 williamc 1.1 # grow(node) : grow a new node extending from this node
11     # nodeList() : return a list of attatched nodes
12     # setassociate(Object) : Associate node with an object reference
13     # associate() : return the associated object reference
14     # find(string) : return the tree node that matches the search string
15     # within the current tree
16     # name() : return the name of the object
17    
18     package TreeNode;
19 williamc 1.2 require 5.001;
20     use ActiveDoc::TreeMonkey;
21     use Utilities::List;
22 williamc 1.1
23     sub new {
24     my $class=shift;
25     my $name=shift;
26     $self={};
27     bless $self, $class;
28     $self->{name}=$name;
29 williamc 1.2 $self->{nodelist}=List->new();
30 williamc 1.1 $self->{monkey}=TreeMonkey->new();
31 williamc 1.2 $self->{parent}="/";
32 williamc 1.1 return $self;
33     }
34    
35     sub setparent() {
36     my $self=shift;
37     $self->{parent}=shift;
38     }
39    
40 williamc 1.2 sub parent() {
41 williamc 1.1 my $self=shift;
42     return $self->{parent};
43     }
44    
45     sub grow {
46     my $self=shift;
47     my $node=shift;
48    
49     $self->{nodelist}->add($node);
50     }
51    
52     sub nodeList {
53     my $self=shift;
54 williamc 1.2 return $self->{nodelist};
55 williamc 1.1 }
56    
57     sub associate {
58     my $self=shift;
59     return $self->{associate};
60     }
61    
62     sub setassociate {
63     my $self=shift;
64     $self->{associate}=shift;
65     }
66    
67 williamc 1.2 sub name {
68     my $self=shift;
69     return $self->{name};
70     }
71    
72 williamc 1.1 #
73     # find -
74     #
75     sub find {
76     my $self=shift;
77     my $string=shift;
78    
79     # get our tree monkey to do the job
80 williamc 1.2 $self->{monkey}->goto($self); #start at this node
81     $self->{monkey}->find($string);
82 williamc 1.1 }