Mercurial > public > cpp-enigma
annotate enigma/rotor_factory.cpp @ 15:9e02d8696e67
Added enigma_machine::step().
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 04 Jul 2012 19:52:41 -0500 |
parents | 1459e74fda3f |
children |
rev | line source |
---|---|
bgneal@1 | 1 // Copyright (C) 2012 by Brian Neal. |
bgneal@1 | 2 // This file is part of Cpp-Enigma, the Enigma Machine simulation. |
bgneal@1 | 3 // Cpp-Enigma is released under the MIT License (see License.txt). |
bgneal@1 | 4 // |
bgneal@1 | 5 // rotor_factory.cpp - Implementation file for the rotor & reflector factory functions. |
bgneal@1 | 6 |
bgneal@1 | 7 #include <string> |
bgneal@1 | 8 #include "rotor_factory.h" |
bgneal@1 | 9 #include "rotor_data.h" |
bgneal@1 | 10 #include "rotor.h" |
bgneal@1 | 11 |
bgneal@1 | 12 //////////////////////////////////////////////////////////////////////////////// |
bgneal@1 | 13 |
bgneal@1 | 14 std::unique_ptr<enigma::rotor> enigma::create_rotor(const char* name, int ring_setting) |
bgneal@1 | 15 { |
bgneal@1 | 16 auto iter = simulated_rotors.find(name); |
bgneal@1 | 17 if (iter == simulated_rotors.end()) |
bgneal@1 | 18 { |
bgneal@1 | 19 throw rotor_error("unknown rotor type: " + std::string(name)); |
bgneal@1 | 20 } |
bgneal@1 | 21 |
bgneal@1 | 22 const rotor_data& rd(iter->second); |
bgneal@1 | 23 return std::unique_ptr<rotor>{new rotor{name, rd.wiring, ring_setting, rd.stepping}}; |
bgneal@1 | 24 } |
bgneal@1 | 25 |
bgneal@1 | 26 //////////////////////////////////////////////////////////////////////////////// |
bgneal@1 | 27 |
bgneal@1 | 28 std::unique_ptr<enigma::rotor> enigma::create_reflector(const char* name) |
bgneal@1 | 29 { |
bgneal@1 | 30 auto iter = simulated_reflectors.find(name); |
bgneal@1 | 31 if (iter == simulated_reflectors.end()) |
bgneal@1 | 32 { |
bgneal@1 | 33 throw rotor_error("unknown reflector type: " + std::string(name)); |
bgneal@1 | 34 } |
bgneal@1 | 35 |
bgneal@1 | 36 return std::unique_ptr<rotor>{new rotor{name, iter->second}}; |
bgneal@1 | 37 } |