2 #include <samchon/protocol/IProtocol.hpp> 8 #include <samchon/library/StringUtil.hpp> 9 #include <samchon/protocol/ServerConnector.hpp> 17 class CalculatorApplication
18 :
public virtual protocol::IProtocol
21 std::shared_ptr<protocol::ServerConnector> connector;
27 CalculatorApplication()
29 connector.reset(
new protocol::ServerConnector(
this));
30 connector->connect(
"127.0.0.1", 17823);
32 virtual ~CalculatorApplication() =
default;
37 virtual void sendData(std::shared_ptr<protocol::Invoke> invoke)
override 39 connector->sendData(invoke);
42 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 44 std::function<void(double, double, double)> listener;
45 double x = invoke->at(0)->getValue<
double>();
46 double y = invoke->at(1)->getValue<
double>();;
47 double ret = invoke->at(2)->getValue<
double>();
49 if (invoke->getListener() ==
"printPlus")
50 listener = std::bind(&CalculatorApplication::printPlus,
this);
51 else if (invoke->getListener() ==
"printMinus")
52 listener = std::bind(&CalculatorApplication::printMinus,
this);
53 else if (invoke->getListener() ==
"printMultiply")
54 listener = std::bind(&CalculatorApplication::printMultiply,
this);
55 else if (invoke->getListener() ==
"printDivide")
56 listener = std::bind(&CalculatorApplication::printDivide,
this);
65 void printPlus(
double x,
double y,
double ret)
71 void printMinus(
double x,
double y,
double ret)
77 void printMultiply(
double x,
double y,
double ret)
83 void printDivide(
double x,
double y,
double ret)
96 CalculatorApplication();
virtual void replyData(std::shared_ptr< Invoke >)=0
static auto substitute(const std::string &format, const T &val, const _Args &...args) -> std::string
Substitutes "{n}" tokens within the specified string with the respective arguments passed in...
virtual void sendData(std::shared_ptr< Invoke >)=0