Samchon Framework for CPP  1.0.0
Invoke.cpp
1 #include <samchon/protocol/Invoke.hpp>
2 
3 #include <samchon/library/XML.hpp>
4 #include <samchon/library/StringUtil.hpp>
5 
6 using namespace std;
7 using namespace samchon;
8 using namespace samchon::library;
9 using namespace samchon::protocol;
10 
11 /* -----------------------------------------------------------------------
12  CONSTRUCTORS
13 ----------------------------------------------------------------------- */
14 Invoke::Invoke()
15  : super()
16 {
17 }
18 Invoke::Invoke(const std::string &listener)
19  : super()
20 {
21  this->listener = listener;
22 }
23 
24 void Invoke::construct(shared_ptr<XML> xml)
25 {
26  this->listener = xml->getProperty("listener");
27 
28  super::construct(xml);
29 }
30 auto Invoke::createChild(shared_ptr<XML>) -> InvokeParameter*
31 {
32  return new InvokeParameter();
33 }
34 
35 /*#define INVOKE_CONSTRUCT_BODY($TYPE) \
36 void Invoke::construct($TYPE val) \
37 { \
38  emplace_back(new InvokeParameter("", val)); \
39 }
40 
41 INVOKE_CONSTRUCT_BODY(bool)
42 INVOKE_CONSTRUCT_BODY(char)
43 INVOKE_CONSTRUCT_BODY(short)
44 INVOKE_CONSTRUCT_BODY(long)
45 INVOKE_CONSTRUCT_BODY(long long)
46 INVOKE_CONSTRUCT_BODY(int)
47 INVOKE_CONSTRUCT_BODY(float)
48 INVOKE_CONSTRUCT_BODY(double)
49 
50 INVOKE_CONSTRUCT_BODY(unsigned char)
51 INVOKE_CONSTRUCT_BODY(unsigned short)
52 INVOKE_CONSTRUCT_BODY(unsigned long)
53 INVOKE_CONSTRUCT_BODY(unsigned long long)
54 INVOKE_CONSTRUCT_BODY(unsigned int)
55 INVOKE_CONSTRUCT_BODY(long double)
56 INVOKE_CONSTRUCT_BODY(const char*)
57 
58 INVOKE_CONSTRUCT_BODY(const string &)
59 INVOKE_CONSTRUCT_BODY(const ByteArray &)
60 INVOKE_CONSTRUCT_BODY(const shared_ptr<XML> &)*/
61 
62 /* -----------------------------------------------------------------------
63  GETTERS
64 ----------------------------------------------------------------------- */
65 auto Invoke::getListener() const -> std::string
66 {
67  return listener;
68 }
69 
70 void Invoke::setListener(const string &listener)
71 {
72  this->listener = listener;
73 }
74 
75 /* -----------------------------------------------------------------------
76  EXPORTERS
77 ----------------------------------------------------------------------- */
78 auto Invoke::TAG() const -> string
79 {
80  return "invoke";
81 }
82 auto Invoke::CHILD_TAG() const -> string
83 {
84  return "parameter";
85 }
86 
87 auto Invoke::toXML() const -> shared_ptr<XML>
88 {
89  std::shared_ptr<XML> &xml = super::toXML();
90 
91  xml->setProperty("listener", listener);
92 
93  return xml;
94 }
95 auto Invoke::toSQL() const -> std::string
96 {
97  string sql;
98  //= StringUtil::substituteSQL("INSERT INTO @invokeTable VALUES ({1})\n", this->listener);
99 
100  if (empty() == false)
101  {
102  sql += "INSERT INTO @parameterTable VALUES\n";
103  for (size_t i = 0; i < size(); i++)
104  sql += "\t" + at(i)->toSQL() + ((i == size() - 1) ? ";\n\n" : ",\n");
105  }
106 
107  return sql;
108 }
virtual auto CHILD_TAG() const -> std::string override
A tag name of children.
Definition: Invoke.cpp:82
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
auto getListener() const -> std::string
Get listener.
Definition: Invoke.cpp:65
auto toSQL() const -> std::string
Get a string of sql statement used to archive history log.
Definition: Invoke.cpp:95
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:52
virtual auto createChild(std::shared_ptr< library::XML >) -> InvokeParameter *override
Factory method of a child Entity.
Definition: Invoke.cpp:30
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityGroup.
Definition: Invoke.cpp:87
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
Definition: Invoke.cpp:78
Package of network protocol and libraries.
Definition: protocol.hpp:185
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
Definition: Invoke.cpp:24
void setListener(const std::string &)
Set listener.
Definition: Invoke.cpp:70
XML is a class representing xml object.
Definition: XML.hpp:72
std::string listener
Represent who listens, often be a function name.
Definition: Invoke.hpp:57
A parameter of an Invoke.
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
Definition: EntityGroup.hpp:90
Invoke()
Default Constructor.
Definition: Invoke.cpp:14
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7