Mercurial > public > cpp-enigma
diff 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 |
line wrap: on
line diff
--- a/enigma/machine.cpp Fri Jun 29 20:08:10 2012 -0500 +++ b/enigma/machine.cpp Fri Jun 29 20:29:41 2012 -0500 @@ -5,6 +5,7 @@ // machine.cpp - The implementation file for the main Enigma machine class. #include <cstddef> +#include <sstream> #include "machine.h" #include "rotor.h" #include "rotor_factory.h" @@ -99,3 +100,22 @@ l_rotor = rotors[1].get(); } } + +//////////////////////////////////////////////////////////////////////////////// + +std::string enigma_machine::str(bool army) const +{ + std::ostringstream os; + + os << reflector->name() << ' '; + + for (const auto& r : rotors) + { + os << r->name() << '/' << r->get_ring_setting() << ' '; + } + + os << get_display() << ' ' << (army ? pb.army_str() : pb.navy_str()); + + return os.str(); +} +