ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/brains/Exclude.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-4/src/brains/Exclude.cpp (file contents):
Revision 1683, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1719 by tim, Fri Nov 5 23:38:27 2004 UTC

# Line 3 | Line 3 | Exclude* Exclude::_instance = 0;
3  
4   #include "brains/Exclude.hpp"
5  
6 Exclude* Exclude::_instance = 0;
6  
7 < Exclude* Exclude::Instance() {
9 <  if (_instance == 0) {
10 <    _instance = new Exclude;
11 <  }
12 <  return _instance;
13 < }
7 > namespace oopse {
8  
9 < Exclude::Exclude(){  
16 <  exPairs = NULL;
17 <  newFortranArrayNeeded = 1;
9 > Exclude::Exclude() : modified_(false){  
10   }
11  
12   Exclude::~Exclude() {
21  if (exPairs != NULL) {
22    delete[] exPairs;
23  }
24  delete _instance;
13   }
14    
15 < int* Exclude::getFortranArray(){
15 > int* Exclude::getExcludeList(){
16    
17 <  set<pair<int, int> >::iterator  i;
30 <  int j;
17 >    std::set<std::pair<int, int> >::iterator  i;
18  
19 <  if (newFortranArrayNeeded != 0) {
20 <    delete[] exPairs;
21 <    exPairs = new int[2*getSize()];  
22 <    j = 0;
23 <    for(i = excludeSet.begin(); i != excludeSet.end(); ++i) {  
24 <      exPairs[j] = (*i).first;
38 <      j++;
39 <      exPairs[j] = (*i).second;
40 <      j++;
19 >    if (modified_) {
20 >        excludeSet_.clear();        
21 >        std::copy(excludeSet_.begin(), excludeSet_.end(), std::back_inserter(excludeSet_.begin()));
22 >        modified_ = false;
23 >    } else {
24 >        return excludeSet_.size() > 0 ? &excludeSet_[0] : NULL;
25      }
42    newFortranArrayNeeded = 0;
43  }
44
45  return exPairs;  
26   }
27  
48
28   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    }
29  
30 <    newFortranArrayNeeded = 1;
31 <  }
30 >    std::set<std::pair<int, int> >::iterator iter;
31 >    iter = findPair(i ,j );
32 >    
33 >    if (iter != excludeSet_.end()) {
34  
35 +        if (i == j) {
36 +            return;
37 +        }else if (i > j) {
38 +            std::swap(i, j);
39 +        }
40 +        
41 +        excludeSet_.insert(make_pair(i, j));
42 +        modified_ = true;
43 +    }
44 +
45   }
46  
47 + void Exclude::removePair(int i, int j) {
48 +    std::set<std::pair<int, int> >::iterator iter;
49 +    iter = findPair(i ,j );
50 +    
51 +    if (iter != excludeSet_.end()) {
52 +        excludeSet_.erase(iter);
53 +        modified_ = true;
54 +    }
55  
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  }  
56   }
57  
58 < int Exclude::hasPair(int i, int j) {
58 > std::set<std::pair<int, int> >::iterator Exclude::findPair(int i, int j) {
59  
60 <  set<pair<int, int> >::iterator  position;
60 >  std::set<std::pair<int, int> >::iterator  position;
61  
62    if (i != j) {  
63      if (i < j)
64 <      position = excludeSet.find(make_pair(i, j));
64 >      position = excludeSet_.find(make_pair(i, j));
65      else
66 <      position = excludeSet.find(make_pair(j, i));
66 >      position = excludeSet_.find(make_pair(j, i));
67  
68 <    if (position != excludeSet.end())
92 <      return 1;
93 <    else
94 <      return 0;
68 >      return excludeSet_.end;
69    } else
70 <    return 0;
70 >    return excludeSet_.end();
71   }
72  
73   int Exclude::getSize() {
74 <  return excludeSet.size();
74 >  return excludeSet_.size();
75   }
76 +
77 +
78 + std::ostream& operator <<(std::ostream& o, Exclude& e){
79 +    std::set<std::pair<int, int> >::iterator  i;
80 +    int index;
81 +
82 +    index = 0;
83 +    for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) {  
84 +        o<< "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n";
85 +        index++;
86 +    }  
87 +
88 +    return o;
89 + }
90 +
91 +
92 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines