MCPcopy Create free account
hub / github.com/cinemast/libjson-rpc-cpp / calculate

Method calculate

src/examples/stubserver.cpp:48–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46bool MyStubServer::isEqual(const string &str1, const string &str2) { return str1 == str2; }
47
48Json::Value MyStubServer::calculate(const Json::Value &args) {
49 Json::Value result;
50 if ((args.isMember("arg1") && args["arg1"].isInt()) && (args.isMember("arg2") && args["arg2"].isInt()) &&
51 (args.isMember("operator") && args["operator"].isString())) {
52 int calculated = 0;
53
54 switch (args["operator"].asString()[0]) {
55 case '+': {
56 calculated = args["arg1"].asInt() + args["arg2"].asInt();
57 break;
58 }
59 case '-': {
60 calculated = args["arg1"].asInt() - args["arg2"].asInt();
61 break;
62 }
63 case '*': {
64 calculated = args["arg1"].asInt() * args["arg2"].asInt();
65 break;
66 }
67 case '/': {
68 if (args["arg2"].asInt() != 0) {
69 calculated = args["arg1"].asInt() / args["arg2"].asInt();
70 }
71 break;
72 }
73 default:
74 break;
75 }
76
77 result.append(calculated);
78 }
79
80 return result;
81}
82
83Json::Value MyStubServer::buildObject(const string &name, int age) {
84 Json::Value result;

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected