comparison enigma/machine.h @ 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 424111a36ed7
comparison
equal deleted inserted replaced
10:232dbe7a3fe0 11:da231533c5c7
14 #include "rotor.h" 14 #include "rotor.h"
15 #include "plugboard.h" 15 #include "plugboard.h"
16 16
17 namespace enigma 17 namespace enigma
18 { 18 {
19 typedef std::vector<std::unique_ptr<rotor>> rotor_vector; 19 typedef std::vector<std::shared_ptr<rotor>> rotor_vector;
20 20
21 class enigma_machine_error : public enigma_error 21 class enigma_machine_error : public enigma_error
22 { 22 {
23 public: 23 public:
24 explicit enigma_machine_error(const std::string& what_arg) 24 explicit enigma_machine_error(const std::string& what_arg)
28 28
29 class enigma_machine 29 class enigma_machine
30 { 30 {
31 public: 31 public:
32 // construct an Enigma machine from component parts: 32 // construct an Enigma machine from component parts:
33 enigma_machine(rotor_vector rv, 33 enigma_machine(const rotor_vector& rv,
34 std::unique_ptr<rotor> reflector, 34 std::shared_ptr<rotor> reflector,
35 const plugboard& pb); 35 const plugboard& pb);
36 36
37 // construct an Enigma machine with a default plugboard (no cables connected): 37 // construct an Enigma machine with a default plugboard (no cables connected):
38 enigma_machine(rotor_vector rv, 38 enigma_machine(const rotor_vector& rv,
39 std::unique_ptr<rotor> reflector); 39 std::shared_ptr<rotor> reflector);
40 40
41 // key-sheet style constructors: 41 // key-sheet style constructors:
42 enigma_machine(const std::vector<std::string>& rotor_types, 42 enigma_machine(const std::vector<std::string>& rotor_types,
43 const std::vector<int>& ring_settings, 43 const std::vector<int>& ring_settings,
44 const std::string& reflector_name = "B", 44 const std::string& reflector_name = "B",
132 std::string army_str() const { return str(true); } 132 std::string army_str() const { return str(true); }
133 std::string navy_str() const { return str(false); } 133 std::string navy_str() const { return str(false); }
134 134
135 private: 135 private:
136 rotor_vector rotors; 136 rotor_vector rotors;
137 std::unique_ptr<rotor> reflector; 137 std::shared_ptr<rotor> reflector;
138 plugboard pb; 138 plugboard pb;
139 rotor* r_rotor; // rightmost rotor 139 rotor* r_rotor; // rightmost rotor
140 rotor* m_rotor; // 2nd to right rotor 140 rotor* m_rotor; // 2nd to right rotor
141 rotor* l_rotor; // 3rd to right rotor 141 rotor* l_rotor; // 3rd to right rotor
142 142