ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/brains/Exclude.cpp
Revision: 1856
Committed: Mon Dec 6 04:49:53 2004 UTC (19 years, 7 months ago) by tim
File size: 1913 byte(s)
Log Message:
fix a bug in Exclude List

File Contents

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