Mercurial > public > cpp-enigma
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/enigma/rotor_factory.cpp Fri Jun 22 20:15:11 2012 -0500 @@ -0,0 +1,37 @@ +// Copyright (C) 2012 by Brian Neal. +// This file is part of Cpp-Enigma, the Enigma Machine simulation. +// Cpp-Enigma is released under the MIT License (see License.txt). +// +// rotor_factory.cpp - Implementation file for the rotor & reflector factory functions. + +#include <string> +#include "rotor_factory.h" +#include "rotor_data.h" +#include "rotor.h" + +//////////////////////////////////////////////////////////////////////////////// + +std::unique_ptr<enigma::rotor> enigma::create_rotor(const char* name, int ring_setting) +{ + auto iter = simulated_rotors.find(name); + if (iter == simulated_rotors.end()) + { + throw rotor_error("unknown rotor type: " + std::string(name)); + } + + const rotor_data& rd(iter->second); + return std::unique_ptr<rotor>{new rotor{name, rd.wiring, ring_setting, rd.stepping}}; +} + +//////////////////////////////////////////////////////////////////////////////// + +std::unique_ptr<enigma::rotor> enigma::create_reflector(const char* name) +{ + auto iter = simulated_reflectors.find(name); + if (iter == simulated_reflectors.end()) + { + throw rotor_error("unknown reflector type: " + std::string(name)); + } + + return std::unique_ptr<rotor>{new rotor{name, iter->second}}; +}