source: git/factory/cf_iter.cc @ 72dd6e

spielwiese
Last change on this file since 72dd6e was 493c477, checked in by Jens Schmidt <schmidt@…>, 27 years ago
o header fixed git-svn-id: file:///usr/local/Singular/svn/trunk@404 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.8 KB
Line 
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
14CFIterator::CFIterator()
15{
16    data = 0; cursor = 0;
17    ispoly = false; hasterms = false;
18}
19
20CFIterator::CFIterator( const CFIterator & i )
21{
22    data = i.data;
23    cursor = i.cursor;
24    ispoly = i.ispoly;
25    hasterms = i.hasterms;
26}
27
28CFIterator::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
41CFIterator::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
73CFIterator::~CFIterator()
74{
75    data = 0; cursor = 0;
76}
77
78CFIterator&
79CFIterator::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
90CFIterator&
91CFIterator::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
105CFIterator&
106CFIterator::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
118CFIterator&
119CFIterator::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
131int
132CFIterator::hasTerms() const
133{
134    return hasterms;
135}
136
137CanonicalForm
138CFIterator::coeff() const
139{
140    ASSERT( hasterms, "illegal term" );
141    if ( ispoly )
142        return cursor->coeff;
143    else
144        return data;
145}
146
147int
148CFIterator::exp() const
149{
150    ASSERT( hasterms, "illegal term" );
151    if ( ispoly )
152        return cursor->exp;
153    else
154        return 0;
155}
Note: See TracBrowser for help on using the repository browser.