EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
Loading...
Searching...
No Matches
Transformer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <string>
5#include <toml.hpp>
6
7#include "EnigmaTypes.hpp"
8#include "config.hpp"
9
19
25private:
26 std::array<std::array<AlphabetIndex, TRANSFORMER_SIZE>, 2> lookupTable;
27
28protected:
30
38 void setTransformValue(int row, int col, AlphabetIndex value);
39
47 AlphabetIndex getTransformValue(int row, int col) const;
48
55 void fillTransformRow(int row, AlphabetIndex value);
56
63 void copyTransformRow(int row, const std::array<AlphabetIndex, TRANSFORMER_SIZE>& values);
64
72 const std::array<AlphabetIndex, TRANSFORMER_SIZE>& getTransformRow(int row) const;
73
74public:
80 virtual ~Transformer() = default;
81
86 virtual AlphabetIndex transform(AlphabetIndex position, bool reverse = false) const = 0;
87
94 virtual AlphabetIndex transformForward(AlphabetIndex position) const = 0;
95
102 virtual AlphabetIndex transformReverse(AlphabetIndex position) const = 0;
103
104 virtual int rotate() = 0;
105 virtual void setPosition(int /*position*/) {};
106 virtual int getPosition() const { return 0; };
107
113 int sizeOfLookupTable() const;
114
120 TransformerType getType() const;
121};
TransformerType
Enum representing the type of transformer.
Class representing a reflector in the Enigma machine. This class inherits from the Transformer class ...
Definition Reflector.hpp:17
Base class for transformers (rotors and reflectors). This class provides the interface for transformi...
virtual ~Transformer()=default
TransformerType getType() const
Returns the type of the transformer.
void setTransformValue(int row, int col, AlphabetIndex value)
Sets a value in the transformation lookup table.
virtual AlphabetIndex transformForward(AlphabetIndex position) const =0
Transforms the given position forward.
virtual AlphabetIndex transformReverse(AlphabetIndex position) const =0
Transforms the given position in reverse.
virtual AlphabetIndex transform(AlphabetIndex position, bool reverse=false) const =0
Transformer()
Constructor for the Transformer class. Initializes the transformer type to NotDefined.
std::array< std::array< AlphabetIndex, TRANSFORMER_SIZE >, 2 > lookupTable
TransformerType type
const std::array< AlphabetIndex, TRANSFORMER_SIZE > & getTransformRow(int row) const
Gets a read-only reference to a row in the transformation lookup table. Useful for using standard alg...
AlphabetIndex getTransformValue(int row, int col) const
Gets a value from the transformation lookup table.
void copyTransformRow(int row, const std::array< AlphabetIndex, TRANSFORMER_SIZE > &values)
Copies a whole array into a row of the transformation lookup table.
virtual int rotate()=0
virtual int getPosition() const
virtual void setPosition(int)
int sizeOfLookupTable() const
Calculates the size of the transformation lookup table (LUT).
void fillTransformRow(int row, AlphabetIndex value)
Fills a row of the transformation lookup table with a specific value.
Global configuration constants for the Enigma machine.