source: git/factory/parseutil.cc @ 16f511

spielwiese
Last change on this file since 16f511 was 16f511, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Fixed the usage of "config.h" (if defined HAVE_CONFIG_H)
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifdef HAVE_CONFIG_H
4#include "config.h"
5#endif /* HAVE_CONFIG_H */
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
15class PUtilBase
16{
17public:
18    PUtilBase() {};
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; }
35    ~PUtilInt() {}
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:
47    CanonicalForm val;
48public:
49    PUtilCF() { val = 0; }
50    PUtilCF( const CanonicalForm & cf ) { val = cf; }
51    ~PUtilCF() {}
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:
63    Variable val;
64public:
65    PUtilVar() { val = Variable(); }
66    PUtilVar( const Variable & v ) { val = v; }
67    ~PUtilVar() {}
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
76class PUtilFactory
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
92ParseUtil::ParseUtil()
93{
94    value = PUtilFactory::create();
95}
96
97ParseUtil::ParseUtil( const ParseUtil &pu )
98{
99    value = pu.value->copy();
100}
101
102ParseUtil::ParseUtil( const CanonicalForm &f )
103{
104    value = PUtilFactory::create( f );
105}
106
107ParseUtil::ParseUtil( int i )
108{
109    value = PUtilFactory::create( i );
110}
111
112ParseUtil::ParseUtil( char * str )
113{
114    value = PUtilFactory::create( str );
115}
116
117ParseUtil::~ParseUtil()
118{
119    delete value;
120}
121
122ParseUtil& ParseUtil::operator= ( const ParseUtil &pu )
123{
124    if ( this != &pu ) {
125        delete value;
126        value = pu.value->copy();
127    }
128    return *this;
129}
130
131ParseUtil& ParseUtil::operator= ( const CanonicalForm &f )
132{
133    delete value;
134    value = PUtilFactory::create( f );
135    return *this;
136}
137
138ParseUtil& ParseUtil::operator= ( int i )
139{
140    delete value;
141    value = PUtilFactory::create( i );
142    return *this;
143}
144
145ParseUtil& ParseUtil::operator= ( const Variable & v )
146{
147    delete value;
148    value = PUtilFactory::create( v );
149    return *this;
150}
151
152CanonicalForm ParseUtil::getval()
153{
154    return value->getval();
155}
156
157int ParseUtil::getintval()
158{
159    return value->getintval();
160}
Note: See TracBrowser for help on using the repository browser.