1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: cf_iter.cc,v 1.0 1996-05-17 10:59:44 stobbe Exp $ |
---|
3 | |
---|
4 | /* |
---|
5 | $Log: not supported by cvs2svn $ |
---|
6 | */ |
---|
7 | |
---|
8 | #include "assert.h" |
---|
9 | #include "cf_defs.h" |
---|
10 | #include "cf_iter.h" |
---|
11 | #include "int_cf.h" |
---|
12 | #include "int_poly.h" |
---|
13 | |
---|
14 | |
---|
15 | CFIterator::CFIterator() |
---|
16 | { |
---|
17 | data = 0; cursor = 0; |
---|
18 | ispoly = false; hasterms = false; |
---|
19 | } |
---|
20 | |
---|
21 | CFIterator::CFIterator( const CFIterator & i ) |
---|
22 | { |
---|
23 | data = i.data; |
---|
24 | cursor = i.cursor; |
---|
25 | ispoly = i.ispoly; |
---|
26 | hasterms = i.hasterms; |
---|
27 | } |
---|
28 | |
---|
29 | CFIterator::CFIterator( const CanonicalForm & f ) |
---|
30 | { |
---|
31 | if ( f.inBaseDomain() || f.inQuotDomain() ) { |
---|
32 | data = f; cursor = 0; |
---|
33 | ispoly = false; hasterms = true; |
---|
34 | } |
---|
35 | else { |
---|
36 | data = f; |
---|
37 | cursor = ((InternalPoly*)(f.value))->firstTerm; |
---|
38 | ispoly = true; hasterms = true; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | CFIterator::CFIterator( const CanonicalForm & f, const Variable & v ) |
---|
43 | { |
---|
44 | ASSERT( !f.inQuotDomain(), "illegal iterator" ); |
---|
45 | ASSERT( v.level() > 0, "illegal iterator" ); |
---|
46 | if ( f.inBaseDomain() ) { |
---|
47 | data = f; cursor = 0; |
---|
48 | ispoly = false; hasterms = true; |
---|
49 | } |
---|
50 | else { |
---|
51 | if ( f.mvar() == v ) { |
---|
52 | data = f; |
---|
53 | cursor = ((InternalPoly*)(f.value))->firstTerm; |
---|
54 | ispoly = true; hasterms = true; |
---|
55 | } |
---|
56 | else if ( v > f.mvar() ) { |
---|
57 | data = f; cursor = 0; |
---|
58 | ispoly = false; hasterms = true; |
---|
59 | } |
---|
60 | else { |
---|
61 | data = swapvar( f, v, f.mvar().next() ); |
---|
62 | if ( data.mvar() == f.mvar().next() ) { |
---|
63 | cursor = ((InternalPoly*)(data.value))->firstTerm; |
---|
64 | ispoly = true; hasterms = true; |
---|
65 | } |
---|
66 | else { |
---|
67 | cursor = 0; |
---|
68 | ispoly = false; hasterms = true; |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | CFIterator::~CFIterator() |
---|
75 | { |
---|
76 | data = 0; cursor = 0; |
---|
77 | } |
---|
78 | |
---|
79 | CFIterator& |
---|
80 | CFIterator::operator= ( const CFIterator & i ) |
---|
81 | { |
---|
82 | if ( this != &i ) { |
---|
83 | data = i.data; |
---|
84 | cursor = i.cursor; |
---|
85 | ispoly = i.ispoly; |
---|
86 | hasterms = i.hasterms; |
---|
87 | } |
---|
88 | return *this; |
---|
89 | } |
---|
90 | |
---|
91 | CFIterator& |
---|
92 | CFIterator::operator= ( const CanonicalForm & f ) |
---|
93 | { |
---|
94 | if ( f.inBaseDomain() || f.inQuotDomain() ) { |
---|
95 | data = f; cursor = 0; |
---|
96 | ispoly = false; hasterms = true; |
---|
97 | } |
---|
98 | else { |
---|
99 | data = f; |
---|
100 | cursor = ((InternalPoly*)(f.value))->firstTerm; |
---|
101 | ispoly = true; hasterms = true; |
---|
102 | } |
---|
103 | return *this; |
---|
104 | } |
---|
105 | |
---|
106 | CFIterator& |
---|
107 | CFIterator::operator++ () |
---|
108 | { |
---|
109 | ASSERT( hasterms, "illegal term" ); |
---|
110 | if ( ispoly ) { |
---|
111 | cursor = cursor->next; |
---|
112 | hasterms = cursor != 0; |
---|
113 | } |
---|
114 | else |
---|
115 | hasterms = false; |
---|
116 | return *this; |
---|
117 | } |
---|
118 | |
---|
119 | CFIterator& |
---|
120 | CFIterator::operator++ ( int ) |
---|
121 | { |
---|
122 | ASSERT( hasterms, "illegal term" ); |
---|
123 | if ( ispoly ) { |
---|
124 | cursor = cursor->next; |
---|
125 | hasterms = cursor != 0; |
---|
126 | } |
---|
127 | else |
---|
128 | hasterms = false; |
---|
129 | return *this; |
---|
130 | } |
---|
131 | |
---|
132 | int |
---|
133 | CFIterator::hasTerms() const |
---|
134 | { |
---|
135 | return hasterms; |
---|
136 | } |
---|
137 | |
---|
138 | CanonicalForm |
---|
139 | CFIterator::coeff() const |
---|
140 | { |
---|
141 | ASSERT( hasterms, "illegal term" ); |
---|
142 | if ( ispoly ) |
---|
143 | return cursor->coeff; |
---|
144 | else |
---|
145 | return data; |
---|
146 | } |
---|
147 | |
---|
148 | int |
---|
149 | CFIterator::exp() const |
---|
150 | { |
---|
151 | ASSERT( hasterms, "illegal term" ); |
---|
152 | if ( ispoly ) |
---|
153 | return cursor->exp; |
---|
154 | else |
---|
155 | return 0; |
---|
156 | } |
---|