SNode.C
Loading...
Searching...
No Matches
apps::towercalculator::TowerCalculator Class Reference

#include <TowerCalculator.h>

Inheritance diagram for apps::towercalculator::TowerCalculator:
Collaboration diagram for apps::towercalculator::TowerCalculator:

Public Member Functions

void * operator new (std::size_t size)=delete
 
 TowerCalculator ()
 
void calculate (long startValue)
 
- Public Member Functions inherited from core::EventReceiver
 EventReceiver (const std::string &name)
 
 EventReceiver (EventReceiver &)=delete
 
 EventReceiver (EventReceiver &&)=delete
 
EventReceiveroperator= (EventReceiver &)=delete
 
EventReceiveroperator= (EventReceiver &&)=delete
 
virtual void destruct ()
 
void span ()
 
void relax ()
 
const std::string & getName () const
 

Protected Types

enum class  State { NEXT , MULTIPLY , DIVIDE }
 

Protected Member Functions

void calculate ()
 
void onEvent (const utils::Timeval &currentTime) override
 
- Protected Member Functions inherited from core::EventReceiver
virtual ~EventReceiver ()=default
 

Protected Attributes

long currentValue
 
std::deque< long > values
 
int multiplicator = 1
 
int divisor = 2
 
State state
 

Additional Inherited Members

- Static Public Member Functions inherited from core::EventReceiver
static void atNextTick (const std::function< void(void)> &callBack)
 

Detailed Description

Definition at line 34 of file TowerCalculator.h.

Member Enumeration Documentation

◆ State

Constructor & Destructor Documentation

◆ TowerCalculator()

apps::towercalculator::TowerCalculator::TowerCalculator ( )

Definition at line 31 of file TowerCalculator.cpp.

References currentValue, NEXT, state, and TowerCalculator().

Referenced by TowerCalculator().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ calculate() [1/2]

void apps::towercalculator::TowerCalculator::calculate ( )
protected

Definition at line 43 of file TowerCalculator.cpp.

43 {
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 }

References currentValue, divisor, multiplicator, MULTIPLY, core::EventReceiver::span(), and state.

Referenced by calculate(), and onEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate() [2/2]

void apps::towercalculator::TowerCalculator::calculate ( long startValue)

Definition at line 37 of file TowerCalculator.cpp.

37 {
38 values.push_back(startValue);
39
40 calculate();
41 }

References calculate().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onEvent()

void apps::towercalculator::TowerCalculator::onEvent ( const utils::Timeval & currentTime)
overrideprotectedvirtual

Implements core::EventReceiver.

Definition at line 58 of file TowerCalculator.cpp.

58 {
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:
83 calculate();
84 break;
85 }
86 }

References calculate(), currentValue, DIVIDE, divisor, multiplicator, MULTIPLY, NEXT, core::EventReceiver::span(), and state.

Here is the call graph for this function:

◆ operator new()

void * apps::towercalculator::TowerCalculator::operator new ( std::size_t size)
delete

Member Data Documentation

◆ currentValue

long apps::towercalculator::TowerCalculator::currentValue
protected

Definition at line 49 of file TowerCalculator.h.

Referenced by calculate(), onEvent(), and TowerCalculator().

◆ divisor

int apps::towercalculator::TowerCalculator::divisor = 2
protected

Definition at line 54 of file TowerCalculator.h.

Referenced by calculate(), and onEvent().

◆ multiplicator

int apps::towercalculator::TowerCalculator::multiplicator = 1
protected

Definition at line 53 of file TowerCalculator.h.

Referenced by calculate(), and onEvent().

◆ state

State apps::towercalculator::TowerCalculator::state
protected

Definition at line 56 of file TowerCalculator.h.

Referenced by calculate(), onEvent(), and TowerCalculator().

◆ values

std::deque<long> apps::towercalculator::TowerCalculator::values
protected

Definition at line 51 of file TowerCalculator.h.


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