Samchon Framework for CPP  1.0.0
InvokeParameter.cpp
1 #include <samchon/protocol/InvokeParameter.hpp>
2 
3 #include <samchon/ByteArray.hpp>
4 #include <samchon/library/XML.hpp>
5 #include <samchon/library/Base64.hpp>
6 #include <samchon/library/StringUtil.hpp>
7 
8 using namespace std;
9 using namespace samchon;
10 using namespace samchon::library;
11 using namespace samchon::protocol;
12 
13 /* ----------------------------------------------------------
14  CONSTRUCTORS
15 ---------------------------------------------------------- */
16 InvokeParameter::InvokeParameter(const string &name, const char *pChar)
17  : InvokeParameter(name, string(pChar))
18 {
19 }
20 
21 //CUSTOM CONSTRUCTOR
22 InvokeParameter::InvokeParameter(const string &name, const string &type, const string &val)
23  : super()
24 {
25  this->name = name;
26  this->type = type;
27  this->str = val;
28 }
29 
30 //MOVE CONSTRUCTORS
31 InvokeParameter::InvokeParameter(const string &name, string &&str)
32  : super()
33 {
34  this->name = name;
35  this->type = "string";
36 
37  this->str = move(str);
38 }
39 InvokeParameter::InvokeParameter(const string &name, ByteArray &&byteArray)
40  : super()
41 {
42  this->name = name;
43  this->type = "ByteArray";
44 
45  this->byteArray = move(byteArray);
46 }
47 
48 /* ----------------------------------------------------------
49  PROTECTED CONSTRUCTORS
50 ---------------------------------------------------------- */
52  : super()
53 {
54 }
55 
56 void InvokeParameter::construct(shared_ptr<XML> xml)
57 {
58  if(xml->hasProperty("name") == true)
59  this->name = xml->getProperty("name");
60  else
61  this->name = "";
62 
63  this->type = xml->getProperty("type");
64 
65  if(type == "XML")
66  this->xml = xml->begin()->second->at(0);
67  else if (type == "ByteArray")
68  {
69  size_t size = xml->getValue<size_t>();
70 
71  byteArray.reserve(size);
72  }
73  else
74  this->str = xml->getValue();
75 }
76 
77 auto InvokeParameter::reservedByteArraySize() const -> size_t
78 {
79  return (size_t)stoull(StringUtil::between(this->str, "size: #"));
80 }
81 void InvokeParameter::setByteArray(ByteArray &&byteArray)
82 {
83  this->byteArray = move(byteArray);
84 }
85 
86 /* ----------------------------------------------------------
87  GETTERS
88 ---------------------------------------------------------- */
89 auto InvokeParameter::key() const -> string
90 {
91  return name;
92 }
93 
94 auto InvokeParameter::getName() const -> std::string
95 {
96  return name;
97 }
98 auto InvokeParameter::getType() const -> std::string
99 {
100  return type;
101 }
102 
103 auto InvokeParameter::getValueAsXML() const -> shared_ptr<XML>
104 {
105  return xml;
106 }
107 
108 /* ----------------------------------------------------------
109  EXPORTS
110 ---------------------------------------------------------- */
111 auto InvokeParameter::TAG() const -> string
112 {
113  return "parameter";
114 }
115 
116 auto InvokeParameter::toXML() const -> shared_ptr<XML>
117 {
118  shared_ptr<XML> &xml = super::toXML();
119 
120  if(name.empty() == false)
121  xml->setProperty("name", name);
122  xml->setProperty("type", type);
123 
124  if (type == "XML")
125  {
126  xml->push_back(this->xml);
127  }
128  else if (type == "ByteArray")
129  {
130  xml->setValue(byteArray.size());
131  }
132  else
133  {
134  xml->setValue(str);
135  }
136 
137  return xml;
138 }
139 auto InvokeParameter::toSQL() const -> std::string
140 {
141  //NAME, TYPE, VALUE
142  std::string value;
143 
144  if (xml != nullptr)
145  value = move(xml->toString());
146  else
147  value = this->str;
148 
149  std::string &sql = StringUtil::substituteSQL("({1}, {2}, {3})", name, type, value);
150  return sql;
151 }
An entity, a standard data class.
Definition: Entity.hpp:48
std::string str
A string value if the type is "string" or "number".
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
Definition: Entity.cpp:30
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
std::string name
A name can represent the parameter.
ByteArray byteArray
A binary value if the type is "ByteArray".
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
auto getValueAsXML() const -> std::shared_ptr< library::XML >
Get value as XML object.
InvokeParameter()
Default Constructor.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the Entity.
std::shared_ptr< library::XML > xml
An XML object if the type is "XML".
Package of network protocol and libraries.
Definition: protocol.hpp:185
auto toSQL() const -> std::string
Get a string of sql statement used to archive history log.
Binary data class.
Definition: ByteArray.hpp:30
auto getType() const -> std::string
Get type.
auto getName() const -> std::string
Get name.
XML is a class representing xml object.
Definition: XML.hpp:72
std::string type
Type of the parameter.
virtual auto key() const -> std::string override
Get a key that can identify the Entity uniquely.
A parameter of an Invoke.
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7