@@ -17,52 +17,52 @@ const char *get_type_name(const WMS::Step &step) {
1717 return string_map[unsigned (step.get_type ())];
1818};
1919
20- void print_step_details (const WMS::Step &step) {
20+ void print_step_details (WMS::Step &step) {
2121 std::cout << std::fixed << std::setprecision (2 );
2222 std::cout << " Step '" << get_type_name (step) << " ' "
2323 << " running for " << (step.get_duration () / 1000.0 ) << " seconds\n " ;
2424}
25+
2526} // namespace
2627
2728namespace WMS {
2829
2930bool WashProgramme::add (Step &step) {
30- // if the array is not full, only add valid steps
31+ // If the array is not full and the step is valid, add it to the array
3132 if (next == std::end (steps) || !step.is_valid ()) {
3233 return false ;
3334 }
34- *next = step;
35+ *next = & step;
3536 ++next;
3637 return true ;
3738}
3839
3940#if 1
4041void WashProgramme::run () {
41- for (auto & step : steps) {
42- if (step. is_valid ()) {
43- print_step_details (step);
42+ for (auto step : steps) { // could be auto* step - very much a matter of style
43+ if (step) { // Check for nullptr array members
44+ print_step_details (* step);
4445 if (display) {
45- display->display (unsigned (step. get_type ()));
46+ display->display (unsigned (step-> get_type ()));
4647 }
47- step. run ();
48+ step-> run ();
4849 }
4950 }
5051}
5152#else
52- // The run() method now uses the iterator 'next' to determine the end of the
53- // steps array (called the sential value). This means that the array can be
54- // partially filled and the programme will only run the steps that have been
55- // added. Also we don;t have to check if the step is valid as we know that the
56- // array is only partially filled with valid steps.
53+ // Alternative implementation using iterators
54+ // This does not need to check for nullptrs
5755void WashProgramme::run() {
5856 for (auto step = std::begin(steps); step != next; ++step) {
59- print_step_details(*step);
57+ Step ¤t_step = **step;
58+ print_step_details(current_step);
6059 if (display) {
61- display->display(unsigned(step-> get_type()));
60+ display->display(unsigned(current_step. get_type()));
6261 }
63- step-> run();
62+ current_step. run();
6463 }
6564}
65+
6666 #endif
6767
6868void connect (WashProgramme &wash, Devices::SevenSegment &sseg) {
0 commit comments