-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotor.h
132 lines (113 loc) · 3.67 KB
/
Rotor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
-----------------------------------------------------------------------------------
Laboratoire : 02
Fichier : Rotor.h
Auteur(s) : Doran Kayoumi, Jérémie Melly, Pierre-Olivier Sandoz
Date : 07.03.2019
But : Déclaration ce la class Rotor
Remarque(S) : -
Compilateur : MinGW-g++ 6.3.0
-----------------------------------------------------------------------------------
*/
#ifndef LABO2_ROTOR_H
#define LABO2_ROTOR_H
#include <string>
#include <vector>
#include <iostream>
class Rotor {
const static std::string ENTRY;
/**
* @note The following vector is used to contain the default configuration for the rotor
* class.
* In an ideal world, it should look something like :
* "ID" : {
* "<WIRING>",
* '<NOTCH>'
* }, ...
*
* To reach something like this, it would probably be better to swap the vector for a
* MAP container. Which should allow to use multiple data types (string for the wiring
* and char for the notch) and avoid unnecessary convertions in the code.
*
* A MAP wasn't used because it wasn't something we saw during our classes (INF1, INF2, ASD1)
*/
const static std::vector<std::vector<std::string>> DEFAULT_CONFIG;
/**
* @brief Get configuration (i.e wiring and notch) of a specific Rotor
*
* @param ID of the wanted configuration
* @return Vector of strings containing the config (wiring and notch)
*/
std::vector<std::string> static getConfig(const std::string &ID);
/**
* @brief Display the current state of a Rotor object
*
* @param os ostream (e.g. cout)
* @param r The rotor object wanted to be displayed
* @return The current ostream, which will allow to chain multiple
* ostream calls.
*/
friend std::ostream &operator<<(std::ostream &os, const Rotor &r);
public:
/**
* @brief Rotor object constructor
*
* @param ID of the rotor, this will allow to retrieve the correct configuration
* @param position starting position of the rotor
*/
Rotor(const std::string &ID, char position);
/**
* @brief Mimic the mechanical rotation of a rotor by increasing it's position by one
*
* @note if the position reaches 'Z', it will go back to 'A'
*/
void turn();
/**
* @brief Convert a char
*
* @note The char enters via the ENTRY and
* then passes through the WIRING
*
* @param toConvert char value to convert
* @return the converted value
*/
char convert(char toConvert) const;
/**
* @brief Decodes a char (reverse function of `convert`)
*
* @note The char entres via the WIRING and
* then passes through the ENTRY
*
* @param toDecode char to decode
* @return the decoted value
*/
char decode(char toDecode) const;
/**
* @brief Check if the rotor reached its NOTCH
*
* @return true if the NOTCH was passed, otherwise false
*/
bool reachedNotch();
/**
* @brief Set the position of the rotor
*
* @param position to set
*/
void setPosition(char position);
/**
* @brief Define the assignment operator for a Rotor
*
* @note the assignment operator was defined because most of the attributes of a
* Rotor object is const and the default = doesn't know how to handle them
*
* @param ROTOR to assign
* @return A reference of this (current Rotor) so the assignment can be chained
*/
Rotor &operator=(const Rotor &ROTOR);
private:
const std::string ID;
const std::string WIRING;
const char NOTCH;
char position;
};
#endif