| 1 | #include <iostream> | 
| 2 | #include <stdlib.h> | 
| 3 |  | 
| 4 | #include "Exclude.hpp" | 
| 5 |  | 
| 6 | Exclude* Exclude::_instance = 0; | 
| 7 |  | 
| 8 | Exclude* Exclude::Instance() { | 
| 9 | if (_instance == 0) { | 
| 10 | _instance = new Exclude; | 
| 11 | } | 
| 12 | return _instance; | 
| 13 | } | 
| 14 |  | 
| 15 | Exclude::Exclude(){ | 
| 16 | exPairs = NULL; | 
| 17 | newFortranArrayNeeded = 1; | 
| 18 | } | 
| 19 |  | 
| 20 | Exclude::~Exclude() { | 
| 21 | if (exPairs != NULL) { | 
| 22 | delete[] exPairs; | 
| 23 | } | 
| 24 | delete _instance; | 
| 25 | } | 
| 26 |  | 
| 27 | int* Exclude::getFortranArray(){ | 
| 28 |  | 
| 29 | set<pair<int, int> >::iterator  i; | 
| 30 | int j; | 
| 31 |  | 
| 32 | if (newFortranArrayNeeded != 0) { | 
| 33 | delete[] exPairs; | 
| 34 | exPairs = new int[2*getSize()]; | 
| 35 | j = 0; | 
| 36 | for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { | 
| 37 | exPairs[j] = (*i).first; | 
| 38 | j++; | 
| 39 | exPairs[j] = (*i).second; | 
| 40 | j++; | 
| 41 | } | 
| 42 | newFortranArrayNeeded = 0; | 
| 43 | } | 
| 44 |  | 
| 45 | return exPairs; | 
| 46 | } | 
| 47 |  | 
| 48 |  | 
| 49 | void Exclude::addPair(int i, int j) { | 
| 50 |  | 
| 51 | if (!hasPair(i, j)) { | 
| 52 |  | 
| 53 | if (i != j) { | 
| 54 |  | 
| 55 | if (i < j) | 
| 56 | excludeSet.insert(make_pair(i, j)); | 
| 57 | else | 
| 58 | excludeSet.insert(make_pair(j, i)); | 
| 59 | } | 
| 60 |  | 
| 61 | newFortranArrayNeeded = 1; | 
| 62 | } | 
| 63 |  | 
| 64 | } | 
| 65 |  | 
| 66 |  | 
| 67 | void Exclude::printMe( void ){ | 
| 68 |  | 
| 69 | set<pair<int, int> >::iterator  i; | 
| 70 | int index; | 
| 71 |  | 
| 72 | index = 0; | 
| 73 | for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { | 
| 74 |  | 
| 75 | std::cerr << "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n"; | 
| 76 | index++; | 
| 77 |  | 
| 78 | } | 
| 79 | } | 
| 80 |  | 
| 81 | int Exclude::hasPair(int i, int j) { | 
| 82 |  | 
| 83 | set<pair<int, int> >::iterator  position; | 
| 84 |  | 
| 85 | if (i != j) { | 
| 86 | if (i < j) | 
| 87 | position = excludeSet.find(make_pair(i, j)); | 
| 88 | else | 
| 89 | position = excludeSet.find(make_pair(j, i)); | 
| 90 |  | 
| 91 | if (position != excludeSet.end()) | 
| 92 | return 1; | 
| 93 | else | 
| 94 | return 0; | 
| 95 | } else | 
| 96 | return 0; | 
| 97 | } | 
| 98 |  | 
| 99 | int Exclude::getSize() { | 
| 100 | return excludeSet.size(); | 
| 101 | } |