--- trunk/OOPSE/libmdtools/Exclude.cpp 2003/03/26 20:45:07 408 +++ trunk/OOPSE/libmdtools/Exclude.cpp 2004/04/12 20:32:20 1097 @@ -1,26 +1,101 @@ -#include +#include +#include #include "Exclude.hpp" -double* Exclude::exPair; +Exclude* Exclude::_instance = 0; -Exclude::Exclude( int theIndex ){ +Exclude* Exclude::Instance() { + if (_instance == 0) { + _instance = new Exclude; + } + return _instance; +} + +Exclude::Exclude(){ + exPairs = NULL; + newFortranArrayNeeded = 1; +} + +Exclude::~Exclude() { + if (exPairs != NULL) { + delete[] exPairs; + } + delete _instance; +} - exI = index*2; - exJ = index*2 + 1; +int* Exclude::getFortranArray(){ + + set >::iterator i; + int j; + + if (newFortranArrayNeeded != 0) { + delete[] exPairs; + exPairs = new int[2*getSize()]; + j = 0; + for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { + exPairs[j] = (*i).first; + j++; + exPairs[j] = (*i).second; + j++; + } + newFortranArrayNeeded = 0; + } + + return exPairs; } -void Exclude::createArray( int nExcludes ){ - exPair = new int[nExcludes*2]; +void Exclude::addPair(int i, int j) { + + if (!hasPair(i, j)) { + + if (i != j) { + + if (i < j) + excludeSet.insert(make_pair(i, j)); + else + excludeSet.insert(make_pair(j, i)); + } + + newFortranArrayNeeded = 1; + } + } -void destroyArray( void ){ - delete[] exPair; + +void Exclude::printMe( void ){ + + set >::iterator i; + int index; + + index = 0; + for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { + + std::cerr << "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n"; + index++; + + } } -void Exclude::setPair( int i, int j ){ +int Exclude::hasPair(int i, int j) { - exPair[exI] = i; - exPair[exJ] = j; + set >::iterator position; + + if (i != j) { + if (i < j) + position = excludeSet.find(make_pair(i, j)); + else + position = excludeSet.find(make_pair(j, i)); + + if (position != excludeSet.end()) + return 1; + else + return 0; + } else + return 0; } + +int Exclude::getSize() { + return excludeSet.size(); +}