-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathorlist.cc
More file actions
83 lines (76 loc) · 3.22 KB
/
orlist.cc
File metadata and controls
83 lines (76 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*****************************************************************************
* orlist.cc *
* *
* Description: OrList is a specialized class type which supports OR lists. *
* This file contains the OrList member functions, which pro- *
* vide the capability to undo previous choices, and select new *
* ones. *
* *
* Created by: David Rosenfeld *
* Date: 9/18/96 *
*****************************************************************************/
#include "clstepcore/complexSupport.h"
/**
* Check if we matched nm. We have two possibilities here: If we have a
* choice selected, we only check the selected choice. Say we're an OR
* between SimpleLists C and D, and nm = C. If choice = D, we can't check
* C. This is because we're already using this OR to match D, and it can
* not match C. If however, this OR doesn't have any choice selected (it
* = SATISFIED), we can check all our children. Since we don't need to
* have a particular choice selected (D), so long as we could be used to
* match C, we potentially have a match. (This all makes sense in the
* context of a sub w/ >1 super, in which case we build a combo-CList and
* may need to check if all sub-CLists matched the multi-sub, C.)
*/
bool OrList::hit( char * nm ) {
EntList * child = getChild( choice );
if( child ) {
// I.e., if we have a choice selected, check it only.
return ( child->hit( nm ) );
} else {
child = childList;
while( child ) {
if( child->viable > UNSATISFIED && child->hit( nm ) ) {
// See MultList::hit() on why we must skip UNSATs.
return true;
}
child = child->next;
}
}
return false;
}
/**
* Unmarks all the nodes of ents marked by the descendants of this.
*/
void OrList::unmarkAll( EntNode * ents ) {
EntList * child;
if( ( child = getChild( choice ) ) != NULL ) {
// choice = the last selected path which we'll now undo.
child->unmarkAll( ents );
}
}
/**
* Accepts the first choice of our childList which marks any unmarked
* nodes. If none of our current choices mark anything, choice is set to
* LISTEND. If choice was set to LISTEND before calling aC(), we reset
* choice to choice1, and search again.
*/
bool OrList::acceptChoice( EntNode * ents ) {
EntList * child;
if( choice == LISTEND ) {
choice = choice1;
}
child = getChild( choice );
while( child ) {
if( child->viable >= MATCHSOME && child->acceptChoice( ents ) ) {
// acceptChoice() returns true if we marked something.
return true;
}
child = child->next;
choice++;
}
// If we got here, we must have gotten to the end of the childList without
// finding a choice which marks something.
choice = LISTEND;
return false;
}