comparison enigma/machine.cpp @ 8:b90a41f0cd94

Created enigma_machine::army_str() & navy_str() functions for logging.
author Brian Neal <bgneal@gmail.com>
date Fri, 29 Jun 2012 20:29:41 -0500
parents 2792ca4ffa84
children da231533c5c7
comparison
equal deleted inserted replaced
7:db1216d380b3 8:b90a41f0cd94
3 // Cpp-Enigma is released under the MIT License (see License.txt). 3 // Cpp-Enigma is released under the MIT License (see License.txt).
4 // 4 //
5 // machine.cpp - The implementation file for the main Enigma machine class. 5 // machine.cpp - The implementation file for the main Enigma machine class.
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <sstream>
8 #include "machine.h" 9 #include "machine.h"
9 #include "rotor.h" 10 #include "rotor.h"
10 #include "rotor_factory.h" 11 #include "rotor_factory.h"
11 12
12 using namespace enigma; 13 using namespace enigma;
97 r_rotor = rotors[3].get(); 98 r_rotor = rotors[3].get();
98 m_rotor = rotors[2].get(); 99 m_rotor = rotors[2].get();
99 l_rotor = rotors[1].get(); 100 l_rotor = rotors[1].get();
100 } 101 }
101 } 102 }
103
104 ////////////////////////////////////////////////////////////////////////////////
105
106 std::string enigma_machine::str(bool army) const
107 {
108 std::ostringstream os;
109
110 os << reflector->name() << ' ';
111
112 for (const auto& r : rotors)
113 {
114 os << r->name() << '/' << r->get_ring_setting() << ' ';
115 }
116
117 os << get_display() << ' ' << (army ? pb.army_str() : pb.navy_str());
118
119 return os.str();
120 }
121