Public Member Functions | |
ModN (int mod, int value=0) | |
ModN & | operator++ () |
ModN & | operator-- () |
bool | operator== (const ModN &operand) const |
operator int () const | |
bool | completed () |
Private Attributes | |
int | fMod |
int | fValue |
bool | fCompleted |
Models a "mod n set" (see e.g., John K. Truss "Discrete Mathematics for Computer Scientists", p.7)
Definition at line 24 of file Life001.cpp.
ModN::ModN | ( | int | mod, | |
int | value = 0 | |||
) | [inline] |
mod | The mod of the set | |
value | The value of the variable |
Definition at line 31 of file Life001.cpp.
ModN& ModN::operator++ | ( | ) | [inline] |
Asserts maintenance of affiliation to the set, i.e. "wraps around" Side effect: Updates inner state of completed which is used for iteration.
Definition at line 37 of file Life001.cpp.
References fCompleted, fMod, and fValue.
ModN& ModN::operator-- | ( | ) | [inline] |
Asserts maintenance of affiliation to the set, i.e. "wraps around" Side effect: Updates inner state of completed which is used for iteration.
Definition at line 48 of file Life001.cpp.
References fCompleted, fMod, and fValue.
bool ModN::operator== | ( | const ModN & | operand | ) | const [inline] |
We compare mod and the value. FIXME: Probably should throw exception if mods are not the same.
Definition at line 58 of file Life001.cpp.
ModN::operator int | ( | ) | const [inline] |
As a convenience so ModN can be used directly within integer algebraic expressions. There is a danger though, since comparisons might lead to confusing results e.g.
ModN mod34(4,3) int i = 4; mod43 == i; // ok, false, mod43 is 3, let's increment...
mod43++; mod43 == i; // oops, false too, because of wrap around, i.e. mod43 now is 0!
Definition at line 68 of file Life001.cpp.
References fValue.
bool ModN::completed | ( | ) | [inline] |
Simulates iterator behaviour. Is set to true if the last increment or decrement lead to wraparound. FIXME: better introduce iterators! This class actually is an iterator.
Definition at line 77 of file Life001.cpp.
References fCompleted.
int ModN::fMod [private] |
Definition at line 79 of file Life001.cpp.
Referenced by operator++(), operator--(), and operator==().
int ModN::fValue [private] |
Definition at line 80 of file Life001.cpp.
Referenced by operator int(), operator++(), operator--(), and operator==().
bool ModN::fCompleted [private] |
Definition at line 81 of file Life001.cpp.
Referenced by completed(), operator++(), and operator--().