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