-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetOfItems.h
74 lines (71 loc) · 1.59 KB
/
SetOfItems.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef SetOfItems_h
#define SetOfItems_h
#include "Item.h"
/*
* 项目集
*/
class SetOfItems{
private:
vector<Item> vitems;
int id;
int cnt;
public:
SetOfItems(){
cnt = 0;
}
vector<Item> getVitems() const {
return vitems;
}
int getProductionID(Item it){
for(int i=0;i<cnt;i++){
Item cur = vitems[i];
if(cur.equal(it)){
return i;
}
}
return -1;
}
int size() const {
return cnt;
}
void setID(int set_id){
id = set_id;
}
int getID() const {
return id;
}
void setVitems(vector<Item> vec_of_item){
vitems = vec_of_item;
}
// 将一个项目添加到项目集
void appendItem(Item it){
it.setID(cnt++);
vitems.push_back(it);
}
// 判断项目(Item)是否存在于项目集中
bool existItem(Item it) const {
for(auto vit: vitems){
if(vit == it) return true;
}
return false;
}
bool operator==(const SetOfItems& soi) const {
return vitems == soi.vitems;
// if(vitems.size() != soi.getVitems().size()){
// return false;
// }
// for(auto curItem: vitems){
// if(!soi.existItem(curItem))
// return false;
// }
// return true;
}
friend ostream& operator<<(ostream& os, const SetOfItems& soi){
os << "the set id is" << soi.getID() << endl;
for(auto it : soi.getVitems()){
os << it << endl;
}
return os;
}
};
#endif