changeset 14:919b7a0d1802

Ditched shared_ptr.
author Brian Neal <bgneal@gmail.com>
date Mon, 02 Jul 2012 19:23:49 -0500
parents b9d124a15926
children 9e02d8696e67
files enigma/machine.cpp enigma/machine.h
diffstat 2 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/enigma/machine.cpp	Mon Jul 02 19:14:36 2012 -0500
+++ b/enigma/machine.cpp	Mon Jul 02 19:23:49 2012 -0500
@@ -16,12 +16,12 @@
 
 enigma_machine::enigma_machine(
       const rotor_vector& rv,
-      std::shared_ptr<rotor> reflector,
+      const rotor& reflector,
       const plugboard& pb)
  : rotors(),
    pb(pb)
 {
-   rotors.push_back(*reflector);
+   rotors.push_back(reflector);
    for (const auto& r : rv)
    {
       rotors.push_back(*r);
@@ -33,11 +33,11 @@
 
 enigma_machine::enigma_machine(
       const rotor_vector& rv,
-      std::shared_ptr<rotor> reflector)
+      const rotor& reflector)
  : rotors(),
    pb()
 {
-   rotors.push_back(*reflector);
+   rotors.push_back(reflector);
    for (const auto& r : rv)
    {
       rotors.push_back(*r);
--- a/enigma/machine.h	Mon Jul 02 19:14:36 2012 -0500
+++ b/enigma/machine.h	Mon Jul 02 19:23:49 2012 -0500
@@ -16,7 +16,7 @@
 
 namespace enigma
 {
-   typedef std::vector<std::shared_ptr<rotor>> rotor_vector;
+   typedef std::vector<rotor*> rotor_vector;
 
    class enigma_machine_error : public enigma_error
    {
@@ -29,14 +29,16 @@
    class enigma_machine
    {
    public:
-      // construct an Enigma machine from component parts:
+      // Construct an Enigma machine from component parts.
+      // Note that the enigma_machine makes copies of the rotors and will not
+      // delete the rotor pointers:
       enigma_machine(const rotor_vector& rv,
-                     std::shared_ptr<rotor> reflector,
+                     const rotor& reflector,
                      const plugboard& pb);
 
       // construct an Enigma machine with a default plugboard (no cables connected):
       enigma_machine(const rotor_vector& rv,
-                     std::shared_ptr<rotor> reflector);
+                     const rotor& reflector);
 
       // key-sheet style constructors:
       enigma_machine(const std::vector<std::string>& rotor_types,