EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
Loading...
Searching...
No Matches
EnigmaMachine.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <memory>
9#include <span>
10#include <string_view>
11#include <vector>
12
13#include "EnigmaCore_EXPORT.hpp"
14#include "EnigmaTypes.hpp"
15#include "IEnigmaObserver.hpp"
16
17// Forward declarations for internal implementation details
18class RotorBox;
19class PlugBoard;
21class IAssetProvider;
22
31class ENIGMACORE_EXPORT EnigmaMachine : public IEnigmaObserver {
32protected:
39 explicit EnigmaMachine(const EnigmaMachineConfig& config, ILogger* logger = nullptr);
40
46 explicit EnigmaMachine(EnigmaMachineConfig&& config, ILogger* logger = nullptr);
47
48private:
49 std::unique_ptr<RotorBox> rotorBox;
50 std::unique_ptr<PlugBoard> plugBoard;
51 std::vector<IEnigmaObserver*> observers;
52 ILogger* logger = nullptr;
53
54public:
60 explicit EnigmaMachine(ILogger* logger = nullptr);
61
70 EnigmaMachine(const IAssetProvider& provider, std::string_view fileName, std::string_view assetPath = "",
71 ILogger* logger = nullptr);
72
81 explicit EnigmaMachine(std::string_view fileName, std::string_view assetPath = "", ILogger* logger = nullptr);
82
83 // Rule of Five (Required due to unique_ptr)
84 ~EnigmaMachine() override;
85 EnigmaMachine(const EnigmaMachine&) = delete;
87 EnigmaMachine(EnigmaMachine&& other) noexcept;
88 EnigmaMachine& operator=(EnigmaMachine&& other) noexcept;
89
96 AlphabetIndex keyTransform(AlphabetIndex input);
97
102 void processBuffer(std::span<AlphabetIndex> buffer);
103
108 void setLogger(ILogger* logger);
109
114 void registerObserver(IEnigmaObserver* observer);
115
120 void removeObserver(IEnigmaObserver* observer);
121
122 // IEnigmaObserver implementation
123 void onRotorStepped(int rotorIndex, AlphabetIndex position) override;
124 void onCharEncrypted(char input, char output) override;
125};
Class representing the Enigma machine.
std::unique_ptr< RotorBox > rotorBox
EnigmaMachine & operator=(const EnigmaMachine &)=delete
std::unique_ptr< PlugBoard > plugBoard
EnigmaMachine(const EnigmaMachine &)=delete
~EnigmaMachine() override
std::vector< IEnigmaObserver * > observers
Interface for providing configuration/asset data. Abstracts the source of assets (filesystem,...
Class representing the PlugBoard (Steckerbrett) of the Enigma machine.
Definition PlugBoard.hpp:22
Class representing a box of rotors in the Enigma machine.
Definition RotorBox.hpp:24
Configuration Data Transfer Object (DTO) for the Enigma Machine. Holds the raw configuration data req...
Interface for observing Enigma Machine events. Implement this interface to receive notifications abou...
virtual void onRotorStepped(int rotorIndex, AlphabetIndex position)=0
Called when a rotor steps.
virtual void onCharEncrypted(char input, char output)=0
Called when a character is encrypted/decrypted.