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 1804 by tim, Tue Nov 30 19:58:25 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines