source: git/factory/parseutil.cc @ d54166

fieker-DuValspielwiese
Last change on this file since d54166 was 9d7aaa, checked in by Jens Schmidt <schmidt@…>, 27 years ago
#include <config.h> added git-svn-id: file:///usr/local/Singular/svn/trunk@155 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.6 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2// $Id: parseutil.cc,v 1.1 1997-04-15 09:34:26 schmidt Exp $
3
4/*
5$Log: not supported by cvs2svn $
6Revision 1.0  1996/05/17 10:59:47  stobbe
7Initial revision
8
9*/
10
11#include <config.h>
12
13#include <string.h>
14#include <stdlib.h>
15
16#include "assert.h"
17
18#include "cf_defs.h"
19#include "parseutil.h"
20
21class PUtilBase
22{
23public:
24    PUtilBase() {};
25    virtual ~PUtilBase() {}
26    virtual PUtilBase * copy() const = 0;
27    virtual CanonicalForm getval() const = 0;
28    virtual int getintval() const = 0;
29    virtual bool isInt() const = 0;
30    virtual bool isCF() const = 0;
31    virtual bool isVar() const = 0;
32};
33
34class PUtilInt : public PUtilBase
35{
36private:
37    int val;
38public:
39    PUtilInt() { val = 0; }
40    PUtilInt( int i ) { val = i; }
41    ~PUtilInt() {}
42    PUtilBase * copy() const { return new PUtilInt( val ); }
43    CanonicalForm getval() const { return CanonicalForm( val ); }
44    int getintval() const { return val; }
45    bool isInt() const { return true; }
46    bool isCF() const { return false; }
47    bool isVar() const { return false; }
48};
49
50class PUtilCF : public PUtilBase
51{
52private:
53    CanonicalForm val;
54public:
55    PUtilCF() { val = 0; }
56    PUtilCF( const CanonicalForm & cf ) { val = cf; }
57    ~PUtilCF() {}
58    PUtilBase * copy() const { return new PUtilCF( val ); }
59    CanonicalForm getval() const { return val; }
60    int getintval() const { return val.intval(); }
61    bool isInt() const { return false; }
62    bool isCF() const { return true; }
63    bool isVar() const { return false; }
64};
65
66class PUtilVar : public PUtilBase
67{
68private:
69    Variable val;
70public:
71    PUtilVar() { val = Variable(); }
72    PUtilVar( const Variable & v ) { val = v; }
73    ~PUtilVar() {}
74    PUtilBase * copy() const { return new PUtilVar( val ); }
75    CanonicalForm getval() const { return CanonicalForm( val ); }
76    int getintval() const { return 0; }
77    bool isInt() const { return false; }
78    bool isCF() const { return false; }
79    bool isVar() const { return true; }
80};
81
82class PUtilFactory
83{
84public:
85    static PUtilBase * create( ) { return new PUtilInt( 0 ); }
86    static PUtilBase * create( int val ) { return new PUtilInt( val ); }
87    static PUtilBase * create( const CanonicalForm & cf ) { return new PUtilCF( cf ); }
88    static PUtilBase * create( const Variable & v ) { return new PUtilVar( v ); }
89    static PUtilBase * create( const char * str )
90    {
91        if ( strlen( str ) < 9 )
92            return new PUtilInt( atoi( str ) );
93        else
94            return new PUtilCF( CanonicalForm( str ) );
95    }
96};
97
98ParseUtil::ParseUtil()
99{
100    value = PUtilFactory::create();
101}
102
103ParseUtil::ParseUtil( const ParseUtil &pu )
104{
105    value = pu.value->copy();
106}
107
108ParseUtil::ParseUtil( const CanonicalForm &f )
109{
110    value = PUtilFactory::create( f );
111}
112
113ParseUtil::ParseUtil( int i )
114{
115    value = PUtilFactory::create( i );
116}
117
118ParseUtil::ParseUtil( char * str )
119{
120    value = PUtilFactory::create( str );
121}
122
123ParseUtil::~ParseUtil()
124{
125    delete value;
126}
127
128ParseUtil& ParseUtil::operator= ( const ParseUtil &pu )
129{
130    if ( this != &pu ) {
131        delete value;
132        value = pu.value->copy();
133    }
134    return *this;
135}
136
137ParseUtil& ParseUtil::operator= ( const CanonicalForm &f )
138{
139    delete value;
140    value = PUtilFactory::create( f );
141    return *this;
142}
143
144ParseUtil& ParseUtil::operator= ( int i )
145{
146    delete value;
147    value = PUtilFactory::create( i );
148    return *this;
149}
150
151ParseUtil& ParseUtil::operator= ( const Variable & v )
152{
153    delete value;
154    value = PUtilFactory::create( v );
155    return *this;
156}
157
158CanonicalForm ParseUtil::getval()
159{
160    return value->getval();
161}
162
163int ParseUtil::getintval()
164{
165    return value->getintval();
166}
Note: See TracBrowser for help on using the repository browser.