ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/brains/Exclude.cpp
Revision: 1832
Committed: Thu Dec 2 16:04:19 2004 UTC (19 years, 9 months ago) by tim
File size: 1787 byte(s)
Log Message:
still have two linking problem

File Contents

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