Loading...
Searching...
No Matches
parseutil.cc
Go to the documentation of this file.
/* emacs edit mode for this file is -*- C++ -*- */
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include "cf_assert.h"
#include "cf_defs.h"
#include "parseutil.h"
class PUtilBase
{
public:
PUtilBase() {};
virtual ~PUtilBase() {}
virtual PUtilBase * copy() const = 0;
virtual CanonicalForm getval() const = 0;
virtual int getintval() const = 0;
virtual bool isInt() const = 0;
virtual bool isCF() const = 0;
virtual bool isVar() const = 0;
};
class PUtilInt : public PUtilBase
{
private:
int val;
public:
PUtilInt() { val = 0; }
PUtilInt( int i ) { val = i; }
~PUtilInt() {}
PUtilBase * copy() const { return new PUtilInt( val ); }
CanonicalForm getval() const { return CanonicalForm( val ); }
int getintval() const { return val; }
bool isInt() const { return true; }
bool isCF() const { return false; }
bool isVar() const { return false; }
};
class PUtilCF : public PUtilBase
{
private:
CanonicalForm val;
public:
PUtilCF() { val = 0; }
PUtilCF( const CanonicalForm & cf ) { val = cf; }
~PUtilCF() {}
PUtilBase * copy() const { return new PUtilCF( val ); }
CanonicalForm getval() const { return val; }
int getintval() const { return val.intval(); }
bool isInt() const { return false; }
bool isCF() const { return true; }
bool isVar() const { return false; }
};
class PUtilVar : public PUtilBase
{
private:
Variable val;
public:
PUtilVar() { val = Variable(); }
PUtilVar( const Variable & v ) { val = v; }
~PUtilVar() {}
PUtilBase * copy() const { return new PUtilVar( val ); }
CanonicalForm getval() const { return CanonicalForm( val ); }
int getintval() const { return 0; }
bool isInt() const { return false; }
bool isCF() const { return false; }
bool isVar() const { return true; }
};
class PUtilFactory
{
public:
static PUtilBase * create( ) { return new PUtilInt( 0 ); }
static PUtilBase * create( int val ) { return new PUtilInt( val ); }
static PUtilBase * create( const CanonicalForm & cf ) { return new PUtilCF( cf ); }
static PUtilBase * create( const Variable & v ) { return new PUtilVar( v ); }
static PUtilBase * create( const char * str )
{
if ( strlen( str ) < 9 )
return new PUtilInt( atoi( str ) );
else
return new PUtilCF( CanonicalForm( str ) );
}
};
ParseUtil::ParseUtil()
{
value = PUtilFactory::create();
}
ParseUtil::ParseUtil( const ParseUtil &pu )
{
value = pu.value->copy();
}
ParseUtil::ParseUtil( const CanonicalForm &f )
{
value = PUtilFactory::create( f );
}
ParseUtil::ParseUtil( int i )
{
value = PUtilFactory::create( i );
}
ParseUtil::ParseUtil( char * str )
{
value = PUtilFactory::create( str );
}
ParseUtil::~ParseUtil()
{
delete value;
}
ParseUtil& ParseUtil::operator= ( const ParseUtil &pu )
{
if ( this != &pu ) {
delete value;
value = pu.value->copy();
}
return *this;
}
ParseUtil& ParseUtil::operator= ( const CanonicalForm &f )
{
delete value;
value = PUtilFactory::create( f );
return *this;
}
ParseUtil& ParseUtil::operator= ( int i )
{
delete value;
value = PUtilFactory::create( i );
return *this;
}
ParseUtil& ParseUtil::operator= ( const Variable & v )
{
delete value;
value = PUtilFactory::create( v );
return *this;
}
CanonicalForm ParseUtil::getval()
{
return value->getval();
}
int ParseUtil::getintval()
{
return value->getintval();
}
i
int i
Definition cfEzgcd.cc:132
cf
CanonicalForm cf
Definition cfModGcd.cc:4091
cf_assert.h
assertions for Factory
cf_defs.h
factory switches.
f
FILE * f
Definition checklibs.c:9
CanonicalForm
factory's main class
Definition canonicalform.h:86
PUtilBase
Definition parseutil.cc:16
PUtilBase::isInt
virtual bool isInt() const =0
PUtilBase::isVar
virtual bool isVar() const =0
PUtilBase::PUtilBase
PUtilBase()
Definition parseutil.cc:18
PUtilBase::copy
virtual PUtilBase * copy() const =0
PUtilBase::getval
virtual CanonicalForm getval() const =0
PUtilBase::isCF
virtual bool isCF() const =0
PUtilBase::getintval
virtual int getintval() const =0
PUtilBase::~PUtilBase
virtual ~PUtilBase()
Definition parseutil.cc:19
PUtilCF
Definition parseutil.cc:45
PUtilCF::copy
PUtilBase * copy() const
Definition parseutil.cc:52
PUtilCF::isVar
bool isVar() const
Definition parseutil.cc:57
PUtilCF::PUtilCF
PUtilCF(const CanonicalForm &cf)
Definition parseutil.cc:50
PUtilCF::isCF
bool isCF() const
Definition parseutil.cc:56
PUtilCF::~PUtilCF
~PUtilCF()
Definition parseutil.cc:51
PUtilCF::PUtilCF
PUtilCF()
Definition parseutil.cc:49
PUtilCF::getval
CanonicalForm getval() const
Definition parseutil.cc:53
PUtilCF::getintval
int getintval() const
Definition parseutil.cc:54
PUtilCF::isInt
bool isInt() const
Definition parseutil.cc:55
PUtilCF::val
CanonicalForm val
Definition parseutil.cc:47
PUtilFactory
Definition parseutil.cc:77
PUtilFactory::create
static PUtilBase * create()
Definition parseutil.cc:79
PUtilFactory::create
static PUtilBase * create(const char *str)
Definition parseutil.cc:83
PUtilFactory::create
static PUtilBase * create(int val)
Definition parseutil.cc:80
PUtilFactory::create
static PUtilBase * create(const CanonicalForm &cf)
Definition parseutil.cc:81
PUtilFactory::create
static PUtilBase * create(const Variable &v)
Definition parseutil.cc:82
PUtilInt
Definition parseutil.cc:29
PUtilInt::copy
PUtilBase * copy() const
Definition parseutil.cc:36
PUtilInt::PUtilInt
PUtilInt(int i)
Definition parseutil.cc:34
PUtilInt::isInt
bool isInt() const
Definition parseutil.cc:39
PUtilInt::PUtilInt
PUtilInt()
Definition parseutil.cc:33
PUtilInt::val
int val
Definition parseutil.cc:31
PUtilInt::isVar
bool isVar() const
Definition parseutil.cc:41
PUtilInt::getval
CanonicalForm getval() const
Definition parseutil.cc:37
PUtilInt::isCF
bool isCF() const
Definition parseutil.cc:40
PUtilInt::getintval
int getintval() const
Definition parseutil.cc:38
PUtilInt::~PUtilInt
~PUtilInt()
Definition parseutil.cc:35
PUtilVar
Definition parseutil.cc:61
PUtilVar::PUtilVar
PUtilVar(const Variable &v)
Definition parseutil.cc:66
PUtilVar::~PUtilVar
~PUtilVar()
Definition parseutil.cc:67
PUtilVar::getintval
int getintval() const
Definition parseutil.cc:70
PUtilVar::isCF
bool isCF() const
Definition parseutil.cc:72
PUtilVar::isVar
bool isVar() const
Definition parseutil.cc:73
PUtilVar::getval
CanonicalForm getval() const
Definition parseutil.cc:69
PUtilVar::PUtilVar
PUtilVar()
Definition parseutil.cc:65
PUtilVar::val
Variable val
Definition parseutil.cc:63
PUtilVar::copy
PUtilBase * copy() const
Definition parseutil.cc:68
PUtilVar::isInt
bool isInt() const
Definition parseutil.cc:71
ParseUtil::getintval
int getintval()
Definition parseutil.cc:157
ParseUtil::operator=
ParseUtil & operator=(const ParseUtil &)
Definition parseutil.cc:122
ParseUtil::value
PUtilBase * value
Definition parseutil.h:17
ParseUtil::~ParseUtil
~ParseUtil()
Definition parseutil.cc:117
ParseUtil::getval
CanonicalForm getval()
Definition parseutil.cc:152
ParseUtil::ParseUtil
ParseUtil()
Definition parseutil.cc:92
Variable
factory's class for variables
Definition factory.h:127
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
parseutil.h