Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / GMLMIP-0.1 / formulas / satisfyingassignment.c @ 7c4d2eb4

History | View | Annotate | Download (1.12 KB)

1
#include "satisfyingassignment.h"
2

    
3
SatisfyingAssignment::SatisfyingAssignment(int _size, char* _array){
4
        size = _size;
5
        
6
        if(size)
7
                array = new char [size];
8
        else
9
                array = NULL;
10
        
11
        for(int i=0; i < size; i++)
12
                array[i]=_array[i];
13
}        
14

    
15
SatisfyingAssignment::SatisfyingAssignment(const SatisfyingAssignment& a){
16
        size = a.size;
17
        
18
        if(size)
19
                array = new char [size];
20
        else
21
                array = NULL;
22
        
23
        for(int i=0; i < size; i++)
24
                array[i]=a.array[i];
25
}
26

    
27
SatisfyingAssignment& SatisfyingAssignment::operator=(const SatisfyingAssignment& a){
28
        if(this != &a){
29
                if(array)
30
                        delete [] array;
31
                size = a.size;
32
                
33
                if(size)
34
                        array = new char [size];
35
                else
36
                        array = NULL;
37
        
38
                for(int i=0; i < size; i++)
39
                        array[i]=a.array[i];
40
        }
41
        return *this;
42
}
43

    
44

    
45
SatisfyingAssignment::~SatisfyingAssignment(){
46
        if(array)
47
                delete [] array;
48
}
49

    
50
char SatisfyingAssignment::get_array_i(int i){
51
        if(array)
52
                return array[i];
53
        return '\0';
54
}
55

    
56
bool SatisfyingAssignment::operator==(const SatisfyingAssignment& other) const{
57
                if(size == other.size){
58
                        for(int i = 0; i < size; i++)
59
                                if(array[i]!=other.array[i])
60
                                        return false;
61
                        return true;
62
                }
63
                return false;
64
                }