-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombo.cpp
57 lines (46 loc) · 1.14 KB
/
combo.cpp
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
//Copyright (c) 2013 Bradley M. Small
#include "combo.h"
Combo::Combo(Cut cut, int Count) : count(Count) , comb(Count,cut), rolled(false){}
Combo::Combo(const Combo& other) : count(other.count), comb(other.comb), rolled(false){}
Combo& Combo::operator++() {
int rollCount( 0 );
for (std::vector<Cut>::reverse_iterator x = comb.rbegin(); x < comb.rend(); ++x){
++(*x);
if(!(*x).isRolled()) break;
++rollCount;
}
if (rollCount == count)
rolled = true;
return *this;
}
Combo& Combo::operator--() {
int rollCount( 0 );
for (std::vector<Cut>::reverse_iterator x = comb.rbegin(); x < comb.rend(); ++x){
--(*x);
if(!(*x).isRolled()) break;
++rollCount;
}
if (rollCount == count)
rolled = true;
return *this;
}
Combo Combo::operator++(int) {
Combo c(*this);
++(*this);
return c;
}
Combo Combo::operator--(int) {
Combo c(*this);
--(*this);
return c;
}
bool Combo::isRolled() {
return (rolled)?rolled=false, true:false;
}
std::ostream& operator<<(std::ostream& stream, const Combo &c) {
for (std::vector<Cut>::const_iterator x = c.comb.begin(); x < c.comb.end(); ++x){
stream << (*x);
}
stream << std::endl;
return stream;
}