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 56 of file TowerCalculator.h.

Member Enumeration Documentation

◆ State

Constructor & Destructor Documentation

◆ TowerCalculator()

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

Definition at line 53 of file TowerCalculator.cpp.

References currentValue, core::EventReceiver::EventReceiver(), NEXT, and state.

Here is the call graph for this function:

Member Function Documentation

◆ calculate() [1/2]

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

Definition at line 65 of file TowerCalculator.cpp.

65 {
66 if (!values.empty() && state == State::NEXT) {
67 currentValue = values.front();
68 values.pop_front();
69
71 multiplicator = 1;
72 divisor = 2;
73
74 std::cout << std::endl << "Starting calculation with value = " << currentValue << std::endl;
75
76 span();
77 }
78 }

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

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 59 of file TowerCalculator.cpp.

59 {
60 values.push_back(startValue);
61
62 calculate();
63 }

References calculate(), and values.

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 80 of file TowerCalculator.cpp.

80 {
81 switch (state) {
82 case State::MULTIPLY:
83 if (multiplicator < 10) {
84 std::cout << currentValue << " * " << multiplicator << " = ";
86 std::cout << currentValue << std::endl;
88 } else {
90 }
91 span();
92 break;
93 case State::DIVIDE:
94 if (divisor < 10) {
95 std::cout << currentValue << " / " << divisor << " = ";
97 std::cout << currentValue << std::endl;
98 divisor++;
99 } else {
101 }
102 span();
103 break;
104 case State::NEXT:
105 calculate();
106 break;
107 }
108 }

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 71 of file TowerCalculator.h.

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

◆ divisor

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

Definition at line 76 of file TowerCalculator.h.

Referenced by calculate(), and onEvent().

◆ multiplicator

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

Definition at line 75 of file TowerCalculator.h.

Referenced by calculate(), and onEvent().

◆ state

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

Definition at line 78 of file TowerCalculator.h.

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

◆ values

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

Definition at line 73 of file TowerCalculator.h.

Referenced by calculate(), and calculate().


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