source: git/factory/parseutil.cc @ b1dfaf

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