diff enigma/machine.cpp @ 11:da231533c5c7

To support hill climbing and fewer enigma machine constructor calls, the enigma machine now uses shared_ptr instead of unique_ptr.
author Brian Neal <bgneal@gmail.com>
date Fri, 29 Jun 2012 23:20:33 -0500
parents b90a41f0cd94
children b9d124a15926
line wrap: on
line diff
--- a/enigma/machine.cpp	Fri Jun 29 21:26:24 2012 -0500
+++ b/enigma/machine.cpp	Fri Jun 29 23:20:33 2012 -0500
@@ -15,15 +15,12 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 enigma_machine::enigma_machine(
-      rotor_vector rv,
-      std::unique_ptr<rotor> reflector,
+      const rotor_vector& rv,
+      std::shared_ptr<rotor> reflector,
       const plugboard& pb)
- : rotors(std::move(rv)),
-   reflector(std::move(reflector)),
-   pb(pb),
-   r_rotor(0),
-   m_rotor(0),
-   l_rotor(0)
+ : rotors(rv),
+   reflector(reflector),
+   pb(pb)
 {
    rotor_count_check();
 }
@@ -31,14 +28,11 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 enigma_machine::enigma_machine(
-      rotor_vector rv,
-      std::unique_ptr<rotor> reflector)
- : rotors(std::move(rv)),
-   reflector(std::move(reflector)),
-   pb(),
-   r_rotor(0),
-   m_rotor(0),
-   l_rotor(0)
+      const rotor_vector& rv,
+      std::shared_ptr<rotor> reflector)
+ : rotors(rv),
+   reflector(reflector),
+   pb()
 {
    rotor_count_check();
 }
@@ -52,10 +46,7 @@
       const std::string& plugboard_settings)
  : rotors(),
    reflector(create_reflector(reflector_name.c_str())),
-   pb(plugboard_settings),
-   r_rotor(0),
-   m_rotor(0),
-   l_rotor(0)
+   pb(plugboard_settings)
 {
    for (const auto& name : rotor_types)
    {