diff 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
line wrap: on
line diff
--- a/enigma/machine.h	Tue Jun 26 21:22:42 2012 -0500
+++ b/enigma/machine.h	Fri Jun 29 20:08:10 2012 -0500
@@ -65,6 +65,25 @@
          rotors[3]->set_display(c3);
       }
 
+      // Set the rotor display (starting position) using a string; the
+      // string length must match the number of rotors in use or a
+      // enigma_machine_error exception will be thrown:
+      void set_display(const std::string& val)
+      {
+         if (val.size() == 3 && rotors.size() == 3)
+         {
+            set_display(val[0], val[1], val[2]);
+         }
+         else if (val.size() == 4 && rotors.size() == 4)
+         {
+            set_display(val[0], val[1], val[2], val[3]);
+         }
+         else
+         {
+            throw enigma_machine_error("set_display invalid size");
+         }
+      }
+
       // return the rotor display (starting position) as a string
       std::string get_display() const
       {