comparison enigma/machine.h @ 7:db1216d380b3

Added a set_rotor() that takes a string for convenience.
author Brian Neal <bgneal@gmail.com>
date Fri, 29 Jun 2012 20:08:10 -0500
parents 2792ca4ffa84
children b90a41f0cd94
comparison
equal deleted inserted replaced
6:3370383116db 7:db1216d380b3
61 61
62 rotors[0]->set_display(c0); 62 rotors[0]->set_display(c0);
63 rotors[1]->set_display(c1); 63 rotors[1]->set_display(c1);
64 rotors[2]->set_display(c2); 64 rotors[2]->set_display(c2);
65 rotors[3]->set_display(c3); 65 rotors[3]->set_display(c3);
66 }
67
68 // Set the rotor display (starting position) using a string; the
69 // string length must match the number of rotors in use or a
70 // enigma_machine_error exception will be thrown:
71 void set_display(const std::string& val)
72 {
73 if (val.size() == 3 && rotors.size() == 3)
74 {
75 set_display(val[0], val[1], val[2]);
76 }
77 else if (val.size() == 4 && rotors.size() == 4)
78 {
79 set_display(val[0], val[1], val[2], val[3]);
80 }
81 else
82 {
83 throw enigma_machine_error("set_display invalid size");
84 }
66 } 85 }
67 86
68 // return the rotor display (starting position) as a string 87 // return the rotor display (starting position) as a string
69 std::string get_display() const 88 std::string get_display() const
70 { 89 {