EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
Transformer Class Referenceabstract

Base class for transformers (rotors and reflectors). This class provides the interface for transforming positions and initializing transformation lookup tables (LUT). More...

#include <Transformer.hpp>

+ Inheritance diagram for Transformer:

Public Member Functions

 Transformer ()
 Constructor for the Transformer class. Initializes the transformer type to NotDefined.
 
virtual ~Transformer ()=default
 
virtual AlphabetIndex transform (AlphabetIndex position, bool reverse=false) const =0
 
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 int rotate ()=0
 
virtual void setPosition (int)
 
virtual int getPosition () const
 
int sizeOfLookupTable () const
 Calculates the size of the transformation lookup table (LUT).
 
TransformerType getType () const
 Returns the type of the transformer.
 

Protected Member Functions

void setTransformValue (int row, int col, AlphabetIndex value)
 Sets a value in the transformation lookup table.
 
AlphabetIndex getTransformValue (int row, int col) const
 Gets a value from the transformation lookup table.
 
void fillTransformRow (int row, AlphabetIndex value)
 Fills a row of the transformation lookup table with a specific value.
 
void copyTransformRow (int row, const std::array< AlphabetIndex, TRANSFORMER_SIZE > &values)
 Copies a whole array into a row of the transformation lookup table.
 
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 algorithms like std::find.
 

Protected Attributes

TransformerType type
 

Private Attributes

std::array< std::array< AlphabetIndex, TRANSFORMER_SIZE >, 2 > lookupTable
 

Detailed Description

Base class for transformers (rotors and reflectors). This class provides the interface for transforming positions and initializing transformation lookup tables (LUT).

Definition at line 24 of file Transformer.hpp.

Constructor & Destructor Documentation

◆ Transformer()

Transformer::Transformer ( )

Constructor for the Transformer class. Initializes the transformer type to NotDefined.

Definition at line 12 of file Transformer.cpp.

References type, and Undefined.

◆ ~Transformer()

virtual Transformer::~Transformer ( )
virtualdefault

Member Function Documentation

◆ copyTransformRow()

void Transformer::copyTransformRow ( int  row,
const std::array< AlphabetIndex, TRANSFORMER_SIZE > &  values 
)
protected

Copies a whole array into a row of the transformation lookup table.

Parameters
rowThe row index to copy into.
valuesThe array of values to copy.

Definition at line 38 of file Transformer.cpp.

References lookupTable.

Referenced by Reflector::Reflector(), Reflector::Reflector(), Rotor::Rotor(), and Rotor::Rotor().

+ Here is the caller graph for this function:

◆ fillTransformRow()

void Transformer::fillTransformRow ( int  row,
AlphabetIndex  value 
)
protected

Fills a row of the transformation lookup table with a specific value.

Parameters
rowThe row index to fill.
valueThe value to fill the row with.

Definition at line 33 of file Transformer.cpp.

References lookupTable.

Referenced by Reflector::Reflector(), and Reflector::Reflector().

+ Here is the caller graph for this function:

◆ getPosition()

virtual int Transformer::getPosition ( ) const
inlinevirtual

Reimplemented in Rotor.

Definition at line 106 of file Transformer.hpp.

◆ getTransformRow()

const std::array< AlphabetIndex, TRANSFORMER_SIZE > & Transformer::getTransformRow ( int  row) const
protected

Gets a read-only reference to a row in the transformation lookup table. Useful for using standard algorithms like std::find.

Gets a read-only reference to a row in the transformation lookup table.

Parameters
rowThe row index to retrieve.
Returns
const std::array<AlphabetIndex, TRANSFORMER_SIZE>& Reference to the row array.

Definition at line 45 of file Transformer.cpp.

References lookupTable.

Referenced by Rotor::initReverseLookupTable().

+ Here is the caller graph for this function:

◆ getTransformValue()

AlphabetIndex Transformer::getTransformValue ( int  row,
int  col 
) const
protected

Gets a value from the transformation lookup table.

Parameters
rowThe row index (0 for forward, 1 for reverse).
colThe column index (input position 0-25).
Returns
AlphabetIndex The value at the specified position.

Definition at line 28 of file Transformer.cpp.

References lookupTable.

Referenced by Reflector::transformForward(), Rotor::transformForward(), Reflector::transformReverse(), and Rotor::transformReverse().

+ Here is the caller graph for this function:

◆ getType()

TransformerType Transformer::getType ( ) const

Returns the type of the transformer.

Returns
TransformerType Returns the type of the transformer (Rotor, Reflector, or NotDefined).

Definition at line 18 of file Transformer.cpp.

References type.

◆ rotate()

virtual int Transformer::rotate ( )
pure virtual

Implemented in Reflector, and Rotor.

◆ setPosition()

virtual void Transformer::setPosition ( int  )
inlinevirtual

Reimplemented in Rotor.

Definition at line 105 of file Transformer.hpp.

◆ setTransformValue()

void Transformer::setTransformValue ( int  row,
int  col,
AlphabetIndex  value 
)
protected

Sets a value in the transformation lookup table.

Parameters
rowThe row index (0 for forward, 1 for reverse).
colThe column index (input position 0-25).
valueThe value to set (output position).

Definition at line 23 of file Transformer.cpp.

References lookupTable.

Referenced by Rotor::initReverseLookupTable().

+ Here is the caller graph for this function:

◆ sizeOfLookupTable()

int Transformer::sizeOfLookupTable ( ) const

Calculates the size of the transformation lookup table (LUT).

Returns
int Returns the size of the transformation lookup table.

Definition at line 14 of file Transformer.cpp.

References lookupTable.

◆ transform()

virtual AlphabetIndex Transformer::transform ( AlphabetIndex  position,
bool  reverse = false 
) const
pure virtual

this method is const-qualified, ensuring that the signal transformation does not modify the internal state of the transformer.

Implemented in Reflector, and Rotor.

◆ transformForward()

virtual AlphabetIndex Transformer::transformForward ( AlphabetIndex  position) const
pure virtual

Transforms the given position forward.

Parameters
positionThe current position (0 to TRANSFORMER_SIZE - 1).
Returns
AlphabetIndex The transformed position (0 to TRANSFORMER_SIZE - 1).

This method defines the primary signal path from right to left through the transformer.

Implemented in Reflector, and Rotor.

◆ transformReverse()

virtual AlphabetIndex Transformer::transformReverse ( AlphabetIndex  position) const
pure virtual

Transforms the given position in reverse.

Parameters
positionThe current position (0 to TRANSFORMER_SIZE - 1).
Returns
AlphabetIndex The transformed position (0 to TRANSFORMER_SIZE - 1).

This method defines the return signal path from left to right through the transformer.

Implemented in Reflector, and Rotor.

Member Data Documentation

◆ lookupTable

std::array<std::array<AlphabetIndex, TRANSFORMER_SIZE>, 2> Transformer::lookupTable
private

◆ type

TransformerType Transformer::type
protected

The documentation for this class was generated from the following files: