Samchon Framework for CPP  1.0.0
Reporter.hpp
1 #pragma once
2 
3 #include <samchon/example/interaction/ChiefDriver.hpp>
4 
5 #include <samchon/example/tsp/Scheduler.hpp>
6 #include <samchon/example/packer/Packer.hpp>
7 
8 #include <samchon/library/XML.hpp>
9 #include <samchon/protocol/Invoke.hpp>
10 
11 #include <iostream>
12 
13 namespace samchon
14 {
15 namespace example
16 {
17 namespace interaction
18 {
19  using namespace std;
20 
21  using namespace library;
22  using namespace protocol;
23 
43  class Reporter
44  : public ChiefDriver
45  {
46  private:
47  typedef ChiefDriver super;
48 
49  public:
50  /* ---------------------------------------------------------------------------------
51  CONSTRUCTORS
52  --------------------------------------------------------------------------------- */
57  : super(nullptr, 37200)
58  {
59  };
60  virtual ~Reporter() = default;
61 
62  protected:
63  virtual void addClient(Socket *socket) override
64  {
65  cout << "The chief has connected." << endl;
66 
67  super::addClient(socket);
68  };
69 
70  public:
71  /* ---------------------------------------------------------------------------------
72  INVOKE MESSAGE CHAIN
73  --------------------------------------------------------------------------------- */
74  virtual void replyData(shared_ptr<Invoke> invoke)
75  {
76  //PRINT
77  shared_ptr<XML> &xml = invoke->at(0)->getValueAsXML();
78 
79  if (xml->getTag() == "scheduler")
80  printTSP(xml);
81  else if (xml->getTag() == "packer")
82  printPacker(xml);
83  };
84 
85  protected:
91  void printTSP(shared_ptr<XML> xml)
92  {
93  tsp::Scheduler scheduler;
94  scheduler.construct(xml);
95 
96  cout << "----------------------------------------------------------------------------" << endl;
97  cout << " TSP SOLVER" << endl;
98  cout << "----------------------------------------------------------------------------" << endl;
99  cout << scheduler.toString() << endl << endl;
100  };
101 
107  void printPacker(shared_ptr<XML> xml)
108  {
109  packer::Packer packer;
110  packer.construct(xml);
111 
112  cout << "----------------------------------------------------------------------------" << endl;
113  cout << " PACKER" << endl;
114  cout << "----------------------------------------------------------------------------" << endl;
115  cout << packer.toString() << endl << endl;
116  };
117 
118  public:
119  /* ---------------------------------------------------------------------------------
120  MAIN
121  --------------------------------------------------------------------------------- */
125  static void main()
126  {
127  string ip;
128 
129  cout << "----------------------------------------------------------------------------" << endl;
130  cout << " REPOTER" << endl;
131  cout << "----------------------------------------------------------------------------" << endl;
132  cout << endl;
133 
134  Reporter reporter;
135  reporter.open();
136  };
137  };
138 };
139 };
140 };
void printTSP(shared_ptr< XML > xml)
Print TSP result on screen.
Definition: Reporter.hpp:91
Reporter()
Default Constructor.
Definition: Reporter.hpp:56
static void main()
Main function.
Definition: Reporter.hpp:125
void printPacker(shared_ptr< XML > xml)
Print Packer result on screen.
Definition: Reporter.hpp:107
A boundary class interacting with a Chief system.
Definition: ChiefDriver.hpp:46
A reporter printing optimization result on screen.
Definition: Reporter.hpp:43