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