bgneal@1: // Copyright (C) 2012 by Brian Neal. bgneal@1: // This file is part of Cpp-Enigma, the Enigma Machine simulation. bgneal@1: // Cpp-Enigma is released under the MIT License (see License.txt). bgneal@1: // bgneal@1: // rotor_factory.cpp - Implementation file for the rotor & reflector factory functions. bgneal@1: bgneal@1: #include bgneal@1: #include "rotor_factory.h" bgneal@1: #include "rotor_data.h" bgneal@1: #include "rotor.h" bgneal@1: bgneal@1: //////////////////////////////////////////////////////////////////////////////// bgneal@1: bgneal@1: std::unique_ptr enigma::create_rotor(const char* name, int ring_setting) bgneal@1: { bgneal@1: auto iter = simulated_rotors.find(name); bgneal@1: if (iter == simulated_rotors.end()) bgneal@1: { bgneal@1: throw rotor_error("unknown rotor type: " + std::string(name)); bgneal@1: } bgneal@1: bgneal@1: const rotor_data& rd(iter->second); bgneal@1: return std::unique_ptr{new rotor{name, rd.wiring, ring_setting, rd.stepping}}; bgneal@1: } bgneal@1: bgneal@1: //////////////////////////////////////////////////////////////////////////////// bgneal@1: bgneal@1: std::unique_ptr enigma::create_reflector(const char* name) bgneal@1: { bgneal@1: auto iter = simulated_reflectors.find(name); bgneal@1: if (iter == simulated_reflectors.end()) bgneal@1: { bgneal@1: throw rotor_error("unknown reflector type: " + std::string(name)); bgneal@1: } bgneal@1: bgneal@1: return std::unique_ptr{new rotor{name, iter->second}}; bgneal@1: }