Mercurial > public > cpp-enigma
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:232dbe7a3fe0 | 11:da231533c5c7 |
---|---|
13 using namespace enigma; | 13 using namespace enigma; |
14 | 14 |
15 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
16 | 16 |
17 enigma_machine::enigma_machine( | 17 enigma_machine::enigma_machine( |
18 rotor_vector rv, | 18 const rotor_vector& rv, |
19 std::unique_ptr<rotor> reflector, | 19 std::shared_ptr<rotor> reflector, |
20 const plugboard& pb) | 20 const plugboard& pb) |
21 : rotors(std::move(rv)), | 21 : rotors(rv), |
22 reflector(std::move(reflector)), | 22 reflector(reflector), |
23 pb(pb), | 23 pb(pb) |
24 r_rotor(0), | |
25 m_rotor(0), | |
26 l_rotor(0) | |
27 { | 24 { |
28 rotor_count_check(); | 25 rotor_count_check(); |
29 } | 26 } |
30 | 27 |
31 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
32 | 29 |
33 enigma_machine::enigma_machine( | 30 enigma_machine::enigma_machine( |
34 rotor_vector rv, | 31 const rotor_vector& rv, |
35 std::unique_ptr<rotor> reflector) | 32 std::shared_ptr<rotor> reflector) |
36 : rotors(std::move(rv)), | 33 : rotors(rv), |
37 reflector(std::move(reflector)), | 34 reflector(reflector), |
38 pb(), | 35 pb() |
39 r_rotor(0), | |
40 m_rotor(0), | |
41 l_rotor(0) | |
42 { | 36 { |
43 rotor_count_check(); | 37 rotor_count_check(); |
44 } | 38 } |
45 | 39 |
46 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
50 const std::vector<int>& ring_settings, | 44 const std::vector<int>& ring_settings, |
51 const std::string& reflector_name, | 45 const std::string& reflector_name, |
52 const std::string& plugboard_settings) | 46 const std::string& plugboard_settings) |
53 : rotors(), | 47 : rotors(), |
54 reflector(create_reflector(reflector_name.c_str())), | 48 reflector(create_reflector(reflector_name.c_str())), |
55 pb(plugboard_settings), | 49 pb(plugboard_settings) |
56 r_rotor(0), | |
57 m_rotor(0), | |
58 l_rotor(0) | |
59 { | 50 { |
60 for (const auto& name : rotor_types) | 51 for (const auto& name : rotor_types) |
61 { | 52 { |
62 rotors.push_back(create_rotor(name.c_str())); | 53 rotors.push_back(create_rotor(name.c_str())); |
63 } | 54 } |