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

Comparing branches/new_design/OOPSE-3.0/src/brains/Exclude.cpp (file contents):
Revision 1683, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1727 by tim, Thu Nov 11 16:41:58 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines