ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/GroupChecker.pm
Revision: 1.4
Committed: Tue Feb 27 13:33:03 2007 UTC (18 years, 2 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.3: +4 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #
2 # Maintain a variable to indicate status of a number of requirements
3 #
4 # --------------
5 # Interface
6 #
7 # exclude(gp) : exclude a group
8 # unexclude(gp) : unexclude a group
9 # include(gp) : include a group
10 # uninclude(gp) : uninclude a group
11 # opencontext(gp) : Annonce group context
12 # closecontext(gp) : Close group context
13 # closelastcontext(set) : Close the last context added to group the group set
14 # status() : If include/excluded groups match the current gp context
15 # return 1 else 0
16 # getincluded() : return an array of included groups
17 # getexcluded() : return array of excluded groups
18 # clearinclude() : clear all entries from the include list
19 # clearexclude() : clear all entries from the exclude list
20 # ----------------------------------------------
21 # group names are characters. Anything before a :: will indicate the
22 # group set upon which the closecontext etc will operate. The group set is
23 # still part of the group name.
24 #
25
26
27 package GroupChecker;
28 BEGIN { print __PACKAGE__." still used.\n"; exit(1) }
29
30
31 require 5.001;
32 require Exporter;
33 @ISA=qw(Exporter);
34
35 sub new {
36 my $class=shift;
37 $self={};
38 bless $self, $class;
39 $self->{context}{none}=1;
40 return $self;
41 }
42
43 sub clearinclude {
44 my $self=shift;
45 undef %{$self->{include}};
46 }
47 sub clearexclude {
48 my $self=shift;
49 undef %{$self->{exclude}};
50 }
51
52 sub exclude {
53 my $self=shift;
54 my $gp=shift;
55
56 ${$self->{exclude}}{$gp}=1;
57 $self->_setstatus;
58 }
59
60 sub unexclude {
61 my $self=shift;
62 my $gp=shift;
63
64 delete ${$self->{exclude}}{$gp};
65 $self->_setstatus;
66 }
67
68 sub include {
69 my $self=shift;
70 my $gp=shift;
71
72 ${$self->{include}}{$gp}=1;
73 $self->_setstatus;
74 }
75
76 sub uninclude {
77 my $self=shift;
78 my $gp=shift;
79
80 delete ${$self->{include}}{$gp};
81 $self->_setstatus;
82 }
83
84 sub getexcluded {
85 my $self=shift;
86 return keys %{$self->{exclude}}
87 }
88
89 sub getincluded {
90 my $self=shift;
91 return keys %{$self->{include}}
92 }
93
94 sub opencontext {
95 my $self=shift;
96 my $gp=shift;
97 my $set;
98
99 if ( $gp=~/(.*)::/ ) {
100 $set=$1;
101 }
102 else {
103 $set='none';
104 }
105
106 push @{$self->{contextstack}{$set}}, $gp;
107 $self->{context}{$gp}=1;
108 $self->_setstatus();
109 }
110
111 sub closelastcontext {
112 my $self=shift;
113 my $set=shift;
114 my $gp;
115
116 if ( $set eq "" ) { $set='none' }
117 do {
118 $gp=pop @{$self->{contextstack}{$set}};
119 } while ( (! exists $self->{context}{$gp}) && ($gp eq "") );
120 $self->closecontext($gp);
121 }
122
123 sub closecontext {
124 my $self=shift;
125 my $gp=shift;
126
127 if ( $gp=~/(.*)::/ ) {
128 $set=$1;
129 }
130 else {
131 $set='none';
132 }
133 delete $self->{context}{$gp};
134 $self->_setstatus();
135 }
136
137 sub status {
138 my $self=shift;
139 return $self->{status};
140 }
141
142 # -------------- Support Routines -----------------------------------
143
144 sub _setstatus {
145 my $self=shift;
146 my $i;
147
148 $self->{status}=1;
149 foreach $i ( keys %{$self->{context}} ) {
150 if ( ( exists $self->{include}{$i} )
151 || ( exists $self->{include}{all} ) ) {
152 $self->{status}=( $self->{status} && 1);
153 }
154 if ( exists $self->{exclude}{$i} ) {
155 $self->{status}=0;
156 }
157 }
158 }