ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Exclude.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Exclude.cpp (file contents):
Revision 408 by mmeineke, Wed Mar 26 20:45:07 2003 UTC vs.
Revision 1097 by gezelter, Mon Apr 12 20:32:20 2004 UTC

# Line 1 | Line 1
1 < #include <cstdlib>
1 > #include <iostream>
2 > #include <stdlib.h>
3  
4   #include "Exclude.hpp"
5  
6 < double* Exclude::exPair;
6 > Exclude* Exclude::_instance = 0;
7  
8 < Exclude::Exclude( int theIndex ){
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 <  exI = index*2;
28 <  exJ = index*2 + 1;
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  
13 void Exclude::createArray( int nExcludes ){
48  
49 <  exPair = new int[nExcludes*2];
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 < void destroyArray( void ){
67 <  delete[] exPair;
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 < void Exclude::setPair( int i, int j ){
81 > int Exclude::hasPair(int i, int j) {
82  
83 <  exPair[exI] = i;
84 <  exPair[exJ] = j;
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines