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

Class representing a box of rotors in the Enigma machine. More...

#include <RotorBox.hpp>

Public Member Functions

 RotorBox (ILogger *logger=nullptr)
 Constructor for the RotorBox class. Initializes the rotor box with a default number of rotors (3) and their positions (all set to 0).
 
 RotorBox (const std::vector< AlphabetIndex > &rotorPositions, const std::vector< RotorConfig > &rotors, const ReflectorConfig &reflector, ILogger *logger=nullptr)
 Constructor for the RotorBox class. Initializes the rotor box with a specified number of rotors, their positions, and configurations.
 
 RotorBox (std::vector< AlphabetIndex > &&rotorPositions, std::vector< RotorConfig > &&rotors, ReflectorConfig &&reflector, ILogger *logger=nullptr)
 Constructor for the RotorBox class (move version).
 
 RotorBox (const RotorBox &)=delete
 
RotorBoxoperator= (const RotorBox &)=delete
 
 RotorBox (RotorBox &&)=default
 
RotorBoxoperator= (RotorBox &&)=default
 
 ~RotorBox ()=default
 
void registerObserver (IEnigmaObserver *observer)
 Registers an observer to receive notifications.
 
void removeObserver (IEnigmaObserver *observer)
 Removes an observer.
 
void printTransformers () const
 Prints the types of transformers in the transformer vector. This function iterates through the transformer vector and prints the type of each transformer.
 
AlphabetIndex keyTransform (AlphabetIndex input)
 Transforms the input key through the rotor box.
 
void setLogger (ILogger *logger)
 Sets the logger for the rotor box.
 

Private Member Functions

void initTransformers (const std::vector< RotorConfig > &rotors, const ReflectorConfig &reflector)
 Initializes the transformer vector with rotors and a reflector.
 
void updateRotors ()
 Updates the positions of the rotors.
 

Private Attributes

int rotorCount
 
std::vector< AlphabetIndex > rotorPositions
 
std::vector< std::unique_ptr< Transformer > > transformers
 
std::vector< IEnigmaObserver * > observers
 
ILogger * logger
 

Detailed Description

Class representing a box of rotors in the Enigma machine.

RotorBox Organization

This class manages multiple rotors and a reflector, allowing for the transformation of input keys. It handles the initialization of rotors, their positions, and the transformation process.

Definition at line 24 of file RotorBox.hpp.

Constructor & Destructor Documentation

◆ RotorBox() [1/5]

RotorBox::RotorBox ( ILogger *  logger = nullptr)
explicit

Constructor for the RotorBox class. Initializes the rotor box with a default number of rotors (3) and their positions (all set to 0).

Parameters
loggerOptional logger for event reporting.
Exceptions
std::runtime_errorIf initialization of transformers fails.

Initializes a standard 3-rotor configuration with empty/default wiring. Note: usage of this constructor is discouraged without subsequent initialization.

Definition at line 22 of file RotorBox.cpp.

References initTransformers(), rotorCount, and rotorPositions.

+ Here is the call graph for this function:

◆ RotorBox() [2/5]

RotorBox::RotorBox ( const std::vector< AlphabetIndex > &  rotorPositions,
const std::vector< RotorConfig > &  rotors,
const ReflectorConfig reflector,
ILogger *  logger = nullptr 
)

Constructor for the RotorBox class. Initializes the rotor box with a specified number of rotors, their positions, and configurations.

Parameters
rotorPositionsA vector containing the initial positions of each rotor.
rotorsA vector containing the configuration for each rotor.
reflectorConfiguration for the reflector.
loggerOptional logger for event reporting.
Exceptions
std::invalid_argumentIf the number of rotors does not match the number of positions.
std::runtime_errorIf initialization of transformers fails.

Initializes a custom rotor configuration. Validates that the number of provided positions matches the rotor count before proceeding with transformer initialization and position setting.

Definition at line 35 of file RotorBox.cpp.

References initTransformers(), rotorCount, rotorPositions, and transformers.

+ Here is the call graph for this function:

◆ RotorBox() [3/5]

RotorBox::RotorBox ( std::vector< AlphabetIndex > &&  rotorPositions,
std::vector< RotorConfig > &&  rotors,
ReflectorConfig &&  reflector,
ILogger *  logger = nullptr 
)

Constructor for the RotorBox class (move version).

Parameters
rotorPositionsA vector containing the initial positions of each rotor.
rotorsA vector containing the configuration for each rotor.
reflectorConfiguration for the reflector.
loggerOptional logger for event reporting.

Definition at line 52 of file RotorBox.cpp.

References rotorCount, rotorPositions, and transformers.

◆ RotorBox() [4/5]

RotorBox::RotorBox ( const RotorBox )
delete

◆ RotorBox() [5/5]

RotorBox::RotorBox ( RotorBox &&  )
default

◆ ~RotorBox()

RotorBox::~RotorBox ( )
default

Member Function Documentation

◆ initTransformers()

void RotorBox::initTransformers ( const std::vector< RotorConfig > &  rotors,
const ReflectorConfig reflector 
)
private

Initializes the transformer vector with rotors and a reflector.

Parameters
rotorsA vector containing the configuration for each rotor.
reflectorConfiguration for the reflector.

Populates the internal transformer vector with unique pointers to Rotor and Reflector objects.

Definition at line 85 of file RotorBox.cpp.

References rotorCount, and transformers.

Referenced by RotorBox(), and RotorBox().

+ Here is the caller graph for this function:

◆ keyTransform()

AlphabetIndex RotorBox::keyTransform ( AlphabetIndex  input)

Transforms the input key through the rotor box.

Parameters
inputThe input key to be transformed.
Returns
AlphabetIndex The transformed output key.

The signal path inside the RotorBox simulates the actual wiring:

  1. Mechanical Step: Rotate rotors BEFORE signal processing.
  2. Forward Pass: Right-to-Left from the entry wheel through all rotors.
  3. Reflector: Swaps the character and sends it back.
  4. Reverse Pass: Left-to-Right back through the rotors using inverse mappings.

Definition at line 112 of file RotorBox.cpp.

References rotorCount, transformers, and updateRotors().

+ Here is the call graph for this function:

◆ operator=() [1/2]

RotorBox & RotorBox::operator= ( const RotorBox )
delete

◆ operator=() [2/2]

RotorBox & RotorBox::operator= ( RotorBox &&  )
default

◆ printTransformers()

void RotorBox::printTransformers ( ) const

Prints the types of transformers in the transformer vector. This function iterates through the transformer vector and prints the type of each transformer.

Definition at line 95 of file RotorBox.cpp.

References logger, and transformers.

◆ registerObserver()

void RotorBox::registerObserver ( IEnigmaObserver observer)

Registers an observer to receive notifications.

Parameters
observerThe observer to register.

Definition at line 71 of file RotorBox.cpp.

References observers.

◆ removeObserver()

void RotorBox::removeObserver ( IEnigmaObserver observer)

Removes an observer.

Parameters
observerThe observer to remove.

Definition at line 73 of file RotorBox.cpp.

References observers.

◆ setLogger()

void RotorBox::setLogger ( ILogger *  logger)

Sets the logger for the rotor box.

Parameters
loggerThe logger to use.

Definition at line 132 of file RotorBox.cpp.

References logger.

◆ updateRotors()

void RotorBox::updateRotors ( )
private

Updates the positions of the rotors.

Updates the rotor positions according to Enigma stepping mechanics.

  1. The rightmost rotor always steps.
  2. A rotor steps the next rotor to its left if it is at its notch position.
  3. Double-stepping occurs when a rotor steps due to its own notch position and also causes the next rotor to step. After stepping, observers are notified of the new rotor positions.

Definition at line 142 of file RotorBox.cpp.

References logger, observers, rotorCount, and transformers.

Referenced by keyTransform().

+ Here is the caller graph for this function:

Member Data Documentation

◆ logger

ILogger* RotorBox::logger
private

Definition at line 30 of file RotorBox.hpp.

Referenced by printTransformers(), setLogger(), and updateRotors().

◆ observers

std::vector<IEnigmaObserver*> RotorBox::observers
private

Definition at line 29 of file RotorBox.hpp.

Referenced by registerObserver(), removeObserver(), and updateRotors().

◆ rotorCount

int RotorBox::rotorCount
private

Definition at line 26 of file RotorBox.hpp.

Referenced by RotorBox(), RotorBox(), RotorBox(), initTransformers(), keyTransform(), and updateRotors().

◆ rotorPositions

std::vector<AlphabetIndex> RotorBox::rotorPositions
private

Definition at line 27 of file RotorBox.hpp.

Referenced by RotorBox(), RotorBox(), and RotorBox().

◆ transformers

std::vector<std::unique_ptr<Transformer> > RotorBox::transformers
private

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