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