source: git/factory/cf_iter.cc @ 84250a6

spielwiese
Last change on this file since 84250a6 was b973c0, checked in by Jens Schmidt <schmidt@…>, 27 years ago
#include <config.h> added git-svn-id: file:///usr/local/Singular/svn/trunk@136 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.9 KB
Line 
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 $
6Revision 1.0  1996/05/17 10:59:44  stobbe
7Initial 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
21CFIterator::CFIterator()
22{
23    data = 0; cursor = 0;
24    ispoly = false; hasterms = false;
25}
26
27CFIterator::CFIterator( const CFIterator & i )
28{
29    data = i.data;
30    cursor = i.cursor;
31    ispoly = i.ispoly;
32    hasterms = i.hasterms;
33}
34
35CFIterator::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
48CFIterator::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
80CFIterator::~CFIterator()
81{
82    data = 0; cursor = 0;
83}
84
85CFIterator&
86CFIterator::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
97CFIterator&
98CFIterator::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
112CFIterator&
113CFIterator::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
125CFIterator&
126CFIterator::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
138int
139CFIterator::hasTerms() const
140{
141    return hasterms;
142}
143
144CanonicalForm
145CFIterator::coeff() const
146{
147    ASSERT( hasterms, "illegal term" );
148    if ( ispoly )
149        return cursor->coeff;
150    else
151        return data;
152}
153
154int
155CFIterator::exp() const
156{
157    ASSERT( hasterms, "illegal term" );
158    if ( ispoly )
159        return cursor->exp;
160    else
161        return 0;
162}
Note: See TracBrowser for help on using the repository browser.