-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.h
38 lines (30 loc) · 1.15 KB
/
Calculator.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
#ifndef MATH_H_
#define MATH_H_
#include <homegear-node/NodeFactory.h>
#include <homegear-node/INode.h>
class MyFactory : Flows::NodeFactory {
public:
Flows::INode *createNode(const std::string &path, const std::string &type, const std::atomic_bool *frontendConnected) override;
};
extern "C" Flows::NodeFactory *getFactory();
namespace Calculator {
class Calculator : public Flows::INode {
public:
Calculator(const std::string &path, const std::string &type, const std::atomic_bool *frontendConnected);
~Calculator() override;
bool init(const Flows::PNodeInfo &info) override;
void input(const Flows::PNodeInfo &info, uint32_t index, const Flows::PVariable &message) override;
private:
std::string _formula;
std::vector<uint32_t> _usedInputs;
std::map<uint32_t,std::string> _values;
std::mutex _valuesMutex;
bool calculateBracket(std::string &formula);
bool calculateMultiplication(std::string &formula);
bool calculateDivision(std::string &formula);
bool calculateAddition(std::string &formula);
bool calculateSubtraction(std::string &formula);
bool calculate(std::string &operation, double &value);
};
}
#endif