SNode.C
Loading...
Searching...
No Matches
TowerCalculator.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#include <iostream>
25#include <string>
26
27#endif // DOXYGEN_SHOULD_SKIP_THIS
28
29namespace apps::towercalculator {
30
32 : core::EventReceiver("TowerCalculator")
33 , currentValue(0)
35 }
36
37 void TowerCalculator::calculate(long startValue) {
38 values.push_back(startValue);
39
41 }
42
44 if (!values.empty() && state == State::NEXT) {
45 currentValue = values.front();
46 values.pop_front();
47
49 multiplicator = 1;
50 divisor = 2;
51
52 std::cout << std::endl << "Starting calculation with value = " << currentValue << std::endl;
53
54 span();
55 }
56 }
57
58 void TowerCalculator::onEvent([[maybe_unused]] const utils::Timeval& currentTime) {
59 switch (state) {
60 case State::MULTIPLY:
61 if (multiplicator < 10) {
62 std::cout << currentValue << " * " << multiplicator << " = ";
64 std::cout << currentValue << std::endl;
66 } else {
68 }
69 span();
70 break;
71 case State::DIVIDE:
72 if (divisor < 10) {
73 std::cout << currentValue << " / " << divisor << " = ";
75 std::cout << currentValue << std::endl;
76 divisor++;
77 } else {
79 }
80 span();
81 break;
82 case State::NEXT:
84 break;
85 }
86 }
87
88} // namespace apps::towercalculator
void onEvent(const utils::Timeval &currentTime) override