-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathprint.cc
More file actions
108 lines (100 loc) · 3.29 KB
/
print.cc
File metadata and controls
108 lines (100 loc) · 3.29 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*****************************************************************************
* print.cc *
* *
* Description: Contains the "<<" functions for all the EntList types. *
* *
* Created by: David Rosenfeld *
* Date: 10/31/96 *
*****************************************************************************/
#include "clstepcore/complexSupport.h"
// Local function prototypes:
static char * joinText( JoinType, char * );
/**
* Prints out a ComplexList, by iterating through its children.
*/
ostream & operator << ( ostream & os, ComplexList & clist ) {
os << "ComplexList - \"" << *( SimpleList * )clist.head->childList
<< "\" supertype\n";
// head->childList will call << for head's 1st child. We know by def
// that this is the supertype.
os << *clist.head;
return os;
}
/**
* Prints out an EntList. Calls appropriate function based on JoinType.
*/
ostream & operator << ( ostream & os, EntList & list ) {
if( list.join == SIMPLE ) {
os << *( SimpleList * )&list;
} else {
os << *( MultList * )&list;
}
return os;
}
/**
* Prints out a SimpleList.
*/
ostream & operator << ( ostream & os, SimpleList & slist ) {
os << slist.name;
return os;
}
/**
* Prints out a MultList.
*/
ostream & operator << ( ostream & os, MultList & mlist ) {
char jointype[7];
int k, lastSimple = 0;
// lastSimple - is the last child simple? If so, we need to print another
// line at the end. If not, the children of last child did already.
EntList * child = mlist.childList;
os << joinText( mlist.join, jointype ) << endl;
for( k = 0; k <= mlist.level; k++ ) {
// Indent 1 more than our level (hence the "<=" ):
os << " ";
}
while( child != NULL ) {
os << *child;
if( child->next == NULL ) {
lastSimple = ( child->join == SIMPLE );
break;
// We don't want to do the conditions below if we're done.
}
if( child->join == SIMPLE ) {
// If so, we're just going to continue printing the next child
// (if exists) in same line.
os << " ";
} else {
// If another MultList is coming, it printed a new line for its
// childList (as we're doing). We must now start a new line at
// our indent level:
for( k = 0; k <= mlist.level; k++ ) {
os << " ";
}
}
child = child->next;
}
if( lastSimple ) {
os << endl;
}
return os;
}
/**
* Copies and returns the string equivalent of a JoinType.
*/
static char * joinText( JoinType j, char * buf ) {
switch( j ) {
case SIMPLE:
strcpy( buf, "SIMPLE" );
return buf;
case AND:
strcpy( buf, "AND" );
return buf;
case OR:
strcpy( buf, "OR" );
return buf;
case ANDOR:
strcpy( buf, "ANDOR" );
return buf;
};
return NULL;
}