My Project
Loading...
Searching...
No Matches
parseutil.cc
Go to the documentation of this file.
1/* emacs edit mode for this file is -*- C++ -*- */
2
3
4#include "config.h"
5
6
7#include <string.h>
8#include <stdlib.h>
9
10#include "cf_assert.h"
11
12#include "cf_defs.h"
13#include "parseutil.h"
14
16{
17public:
19 virtual ~PUtilBase() {}
20 virtual PUtilBase * copy() const = 0;
21 virtual CanonicalForm getval() const = 0;
22 virtual int getintval() const = 0;
23 virtual bool isInt() const = 0;
24 virtual bool isCF() const = 0;
25 virtual bool isVar() const = 0;
26};
27
28class PUtilInt : public PUtilBase
29{
30private:
31 int val;
32public:
33 PUtilInt() { val = 0; }
34 PUtilInt( int i ) { val = i; }
36 PUtilBase * copy() const { return new PUtilInt( val ); }
37 CanonicalForm getval() const { return CanonicalForm( val ); }
38 int getintval() const { return val; }
39 bool isInt() const { return true; }
40 bool isCF() const { return false; }
41 bool isVar() const { return false; }
42};
43
44class PUtilCF : public PUtilBase
45{
46private:
48public:
49 PUtilCF() { val = 0; }
50 PUtilCF( const CanonicalForm & cf ) { val = cf; }
52 PUtilBase * copy() const { return new PUtilCF( val ); }
53 CanonicalForm getval() const { return val; }
54 int getintval() const { return val.intval(); }
55 bool isInt() const { return false; }
56 bool isCF() const { return true; }
57 bool isVar() const { return false; }
58};
59
60class PUtilVar : public PUtilBase
61{
62private:
64public:
66 PUtilVar( const Variable & v ) { val = v; }
68 PUtilBase * copy() const { return new PUtilVar( val ); }
69 CanonicalForm getval() const { return CanonicalForm( val ); }
70 int getintval() const { return 0; }
71 bool isInt() const { return false; }
72 bool isCF() const { return false; }
73 bool isVar() const { return true; }
74};
75
77{
78public:
79 static PUtilBase * create( ) { return new PUtilInt( 0 ); }
80 static PUtilBase * create( int val ) { return new PUtilInt( val ); }
81 static PUtilBase * create( const CanonicalForm & cf ) { return new PUtilCF( cf ); }
82 static PUtilBase * create( const Variable & v ) { return new PUtilVar( v ); }
83 static PUtilBase * create( const char * str )
84 {
85 if ( strlen( str ) < 9 )
86 return new PUtilInt( atoi( str ) );
87 else
88 return new PUtilCF( CanonicalForm( str ) );
89 }
90};
91
93{
95}
96
98{
99 value = pu.value->copy();
100}
101
103{
105}
106
108{
110}
111
113{
115}
116
118{
119 delete value;
120}
121
123{
124 if ( this != &pu ) {
125 delete value;
126 value = pu.value->copy();
127 }
128 return *this;
129}
130
132{
133 delete value;
135 return *this;
136}
137
139{
140 delete value;
142 return *this;
143}
144
146{
147 delete value;
149 return *this;
150}
151
153{
154 return value->getval();
155}
156
158{
159 return value->getintval();
160}
int i
Definition: cfEzgcd.cc:132
CanonicalForm cf
Definition: cfModGcd.cc:4083
assertions for Factory
factory switches.
FILE * f
Definition: checklibs.c:9
factory's main class
Definition: canonicalform.h:86
long intval() const
conversion functions
virtual bool isInt() const =0
virtual bool isVar() const =0
virtual PUtilBase * copy() const =0
virtual CanonicalForm getval() const =0
virtual bool isCF() const =0
virtual int getintval() const =0
virtual ~PUtilBase()
Definition: parseutil.cc:19
PUtilBase * copy() const
Definition: parseutil.cc:52
bool isVar() const
Definition: parseutil.cc:57
PUtilCF(const CanonicalForm &cf)
Definition: parseutil.cc:50
bool isCF() const
Definition: parseutil.cc:56
~PUtilCF()
Definition: parseutil.cc:51
PUtilCF()
Definition: parseutil.cc:49
CanonicalForm getval() const
Definition: parseutil.cc:53
int getintval() const
Definition: parseutil.cc:54
bool isInt() const
Definition: parseutil.cc:55
CanonicalForm val
Definition: parseutil.cc:47
static PUtilBase * create()
Definition: parseutil.cc:79
static PUtilBase * create(const char *str)
Definition: parseutil.cc:83
static PUtilBase * create(int val)
Definition: parseutil.cc:80
static PUtilBase * create(const CanonicalForm &cf)
Definition: parseutil.cc:81
static PUtilBase * create(const Variable &v)
Definition: parseutil.cc:82
PUtilBase * copy() const
Definition: parseutil.cc:36
PUtilInt(int i)
Definition: parseutil.cc:34
bool isInt() const
Definition: parseutil.cc:39
PUtilInt()
Definition: parseutil.cc:33
int val
Definition: parseutil.cc:31
bool isVar() const
Definition: parseutil.cc:41
CanonicalForm getval() const
Definition: parseutil.cc:37
bool isCF() const
Definition: parseutil.cc:40
int getintval() const
Definition: parseutil.cc:38
~PUtilInt()
Definition: parseutil.cc:35
PUtilVar(const Variable &v)
Definition: parseutil.cc:66
~PUtilVar()
Definition: parseutil.cc:67
int getintval() const
Definition: parseutil.cc:70
bool isCF() const
Definition: parseutil.cc:72
bool isVar() const
Definition: parseutil.cc:73
CanonicalForm getval() const
Definition: parseutil.cc:69
PUtilVar()
Definition: parseutil.cc:65
Variable val
Definition: parseutil.cc:63
PUtilBase * copy() const
Definition: parseutil.cc:68
bool isInt() const
Definition: parseutil.cc:71
int getintval()
Definition: parseutil.cc:157
ParseUtil & operator=(const ParseUtil &)
Definition: parseutil.cc:122
PUtilBase * value
Definition: parseutil.h:17
CanonicalForm getval()
Definition: parseutil.cc:152
factory's class for variables
Definition: variable.h:33
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39