MCPcopy Create free account
hub / github.com/apache/thrift / calculate

Method calculate

tutorial/cpp/CppServer.cpp:58–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 }
57
58 int32_t calculate(const int32_t logid, const Work& work) override {
59 cout << "calculate(" << logid << ", " << work << ")" << '\n';
60 int32_t val;
61
62 switch (work.op) {
63 case Operation::ADD:
64 val = work.num1 + work.num2;
65 break;
66 case Operation::SUBTRACT:
67 val = work.num1 - work.num2;
68 break;
69 case Operation::MULTIPLY:
70 val = work.num1 * work.num2;
71 break;
72 case Operation::DIVIDE:
73 if (work.num2 == 0) {
74 InvalidOperation io;
75 io.whatOp = work.op;
76 io.why = "Cannot divide by 0";
77 throw io;
78 }
79 val = work.num1 / work.num2;
80 break;
81 default:
82 InvalidOperation io;
83 io.whatOp = work.op;
84 io.why = "Invalid Operation";
85 throw io;
86 }
87
88 SharedStruct ss;
89 ss.key = logid;
90 ss.value = to_string(val);
91
92 log[logid] = ss;
93
94 return val;
95 }
96
97 void getStruct(SharedStruct& ret, const int32_t logid) override {
98 cout << "getStruct(" << logid << ")" << '\n';

Callers 1

mainFunction · 0.45

Calls 1

to_stringFunction · 0.50

Tested by

no test coverage detected