# HG changeset patch # User Brian Neal # Date 1341030033 18000 # Node ID da231533c5c7691a48200e76d238665da5bc258f # Parent 232dbe7a3fe0f9c8f8796a59c4c99808087ae8c8 To support hill climbing and fewer enigma machine constructor calls, the enigma machine now uses shared_ptr instead of unique_ptr. diff -r 232dbe7a3fe0 -r da231533c5c7 enigma/machine.cpp --- 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 reflector, + const rotor_vector& rv, + std::shared_ptr 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 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 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) { diff -r 232dbe7a3fe0 -r da231533c5c7 enigma/machine.h --- a/enigma/machine.h Fri Jun 29 21:26:24 2012 -0500 +++ b/enigma/machine.h Fri Jun 29 23:20:33 2012 -0500 @@ -16,7 +16,7 @@ namespace enigma { - typedef std::vector> rotor_vector; + typedef std::vector> rotor_vector; class enigma_machine_error : public enigma_error { @@ -30,13 +30,13 @@ { public: // construct an Enigma machine from component parts: - enigma_machine(rotor_vector rv, - std::unique_ptr reflector, + enigma_machine(const rotor_vector& rv, + std::shared_ptr reflector, const plugboard& pb); // construct an Enigma machine with a default plugboard (no cables connected): - enigma_machine(rotor_vector rv, - std::unique_ptr reflector); + enigma_machine(const rotor_vector& rv, + std::shared_ptr reflector); // key-sheet style constructors: enigma_machine(const std::vector& rotor_types, @@ -134,7 +134,7 @@ private: rotor_vector rotors; - std::unique_ptr reflector; + std::shared_ptr reflector; plugboard pb; rotor* r_rotor; // rightmost rotor rotor* m_rotor; // 2nd to right rotor