Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / GMLMIP-0.1 / rules / premise.c @ 7c4d2eb4

History | View | Annotate | Download (1.5 KB)

1 e034e268 Thorsten WiƟmann
#include "premise.h"
2
3
template<class T>
4
Premise<T>::Premise(){
5
        n = 0;
6
        m = 0;
7
        total_valuations = 1 << (n+m);
8
        a = NULL;
9
        b = NULL;
10
}
11
12
template<class T>
13
Premise<T>::Premise(int _n, int _m, T* _a, T* _b){
14
        n =_n;
15
        m =_m;
16
        if (n+m > 30) {
17
                cout << "Too many (>30) modal formulae in node." << endl;
18
                exit(1);
19
        }
20
        total_valuations = 1 << (n+m);
21
        
22
        if(n)
23
                a = new T [n];
24
        else
25
                a = NULL;
26
        if(m)
27
                b = new T [m];
28
        else
29
                b = NULL;
30
        
31
        for(int i=0; i < n; i++)
32
                a[i]=_a[i];
33
        for(int j=0; j < m; j++)
34
                b[j]=_b[j];
35
}
36
37
template<class T>
38
Premise<T>::Premise(const Premise<T>& p){
39
        n = p.n;
40
        m = p.m;
41
        total_valuations = p.total_valuations;
42
        
43
        if(n)
44
                a = new T [n];
45
        else
46
                a = NULL;
47
                
48
        if(m)
49
                b = new T [m];
50
        else
51
                b = NULL;
52
        
53
        for(int i=0; i < n; i++)
54
                a[i]=p.a[i];
55
        for(int j=0; j < m; j++)
56
                b[j]=p.b[j];
57
}
58
59
template<class T>
60
Premise<T>& Premise<T>::operator=(const Premise<T>& p){
61
        if(this != &p){
62
                if(a) 
63
                        delete [] a;
64
                if(b)
65
                        delete [] b;
66
                n = p.n;
67
                m = p.m;
68
                total_valuations = p.total_valuations;
69
70
                if(n)
71
                        a = new T [n];
72
                else
73
                        a = NULL;
74
                if(m)
75
                        b = new T [m];
76
                else
77
                        b = NULL;
78
                        
79
                for(int i=0; i < n; i++)
80
                        a[i]=p.a[i];
81
                for(int j=0; j < m; j++)
82
                        b[j]=p.b[j];
83
        }
84
        return *this;
85
}
86
87
template<class T>
88
Premise<T>::~Premise(){
89
        if(a)
90
                delete [] a;
91
        if(b)
92
                delete [] b;
93
}
94
95
template<class T>
96
T Premise<T>::get_a_i(int i){
97
        if(a)
98
                return a[i];
99
        return -1;
100
}
101
102
template<class T>
103
T Premise<T>::get_b_i(int i){
104
        if(b)
105
                return b[i];
106
        return -1;
107
}
108
109
template class Premise<int>;
110
template class Premise<Rational>;