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 1726 by tim, Fri Nov 5 23:38:27 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() :
7 +    modified_(false) { }
8  
9 < namespace oopse {
9 > Exclude::~Exclude() { }
10  
11 < Exclude::Exclude() : modified_(false){  
10 < }
11 > int *Exclude::getExcludeList() {
12  
12 Exclude::~Exclude() {
13 }
14  
15 int* Exclude::getExcludeList(){
16  
17    std::set<std::pair<int, int> >::iterator  i;
18
13      if (modified_) {
14 <        excludeSet_.clear();        
15 <        std::copy(excludeSet_.begin(), excludeSet_.end(), std::back_inserter(excludeSet_.begin()));
14 >        excludeList_.clear();
15 >        std::copy(excludeSet_.begin(), excludeSet_.end(),
16 >                  std::back_inserter(excludeList_.end()));
17          modified_ = false;
18 <    } else {
19 <        return excludeSet_.size() > 0 ? &excludeSet_[0] : NULL;
20 <    }
18 >    }
19 >
20 >    return excludeList_.size() > 0 ? &excludeList_[0] : NULL;    
21   }
22  
23   void Exclude::addPair(int i, int j) {
29
24      std::set<std::pair<int, int> >::iterator iter;
31    iter = findPair(i ,j );
32    
33    if (iter != excludeSet_.end()) {
25  
26 +    iter = findPair(i, j);
27 +
28 +    if (iter != excludeSet_.end()) {
29          if (i == j) {
30              return;
31 <        }else if (i > j) {
31 >        } else if (i > j) {
32              std::swap(i, j);
33          }
34 <        
34 >
35          excludeSet_.insert(make_pair(i, j));
36          modified_ = true;
37      }
44
38   }
39  
40   void Exclude::removePair(int i, int j) {
41      std::set<std::pair<int, int> >::iterator iter;
42 <    iter = findPair(i ,j );
43 <    
42 >
43 >    iter = findPair(i, j);
44 >
45      if (iter != excludeSet_.end()) {
46          excludeSet_.erase(iter);
47          modified_ = true;
48      }
55
49   }
50  
51 < std::set<std::pair<int, int> >::iterator Exclude::findPair(int i, int j) {
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 <  std::set<std::pair<int, int> >::iterator  position;
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 <  if (i != j) {  
61 <    if (i < j)
62 <      position = excludeSet_.find(make_pair(i, j));
65 <    else
66 <      position = excludeSet_.find(make_pair(j, i));
67 <
68 <      return excludeSet_.end;
69 <  } else
70 <    return excludeSet_.end();
60 >        return excludeSet_.end;
61 >    } else
62 >        return excludeSet_.end();
63   }
64  
65   int Exclude::getSize() {
66 <  return excludeSet_.size();
66 >    return excludeSet_.size();
67   }
68  
69 + std::ostream& operator <<(std::ostream& o, Exclude& e) {
70 +    std::set<std::pair<int, int> >::iterator i;
71  
78 std::ostream& operator <<(std::ostream& o, Exclude& e){
79    std::set<std::pair<int, int> >::iterator  i;
72      int index;
73  
74      index = 0;
75 <    for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) {  
76 <        o<< "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n";
75 >
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 <    }  
80 >    }
81  
82      return o;
83   }
84  
91
85   }
86 +
87 +  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines