Samchon Framework for CPP  1.0.0
InvokeParameter.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/protocol/Entity.hpp>
5 
6 #include <sstream>
7 #include <samchon/ByteArray.hpp>
8 #include <samchon/WeakString.hpp>
9 
10 namespace samchon
11 {
12 namespace protocol
13 {
14  class Invoke;
15 
58  class SAMCHON_FRAMEWORK_API InvokeParameter
59  : public virtual Entity
60  {
61  friend class Invoke;
62 
63  protected:
64  typedef Entity super;
65 
69  std::string name;
70 
81  std::string type;
82 
86  std::string str;
87 
91  std::shared_ptr<library::XML> xml;
92 
97 
98  public:
99  /* ----------------------------------------------------------
100  CONSTRUCTORS
101  ---------------------------------------------------------- */
105  InvokeParameter();
106 
121  InvokeParameter(const std::string &, const std::string &, const std::string &);
122 
156  template <typename T>
157  InvokeParameter(const std::string &name, const T &val)
158  : super()
159  {
160  this->name = name;
161 
162  construct_by_varadic_template(val);
163  };
164 
165  InvokeParameter(const std::string &, const char*);
166 
167  //MOVE CONSTRUCTORS
171  InvokeParameter(const std::string &, std::string &&);
172 
176  InvokeParameter(const std::string &, ByteArray &&);
177 
178  virtual ~InvokeParameter() = default;
179 
180  virtual void construct(std::shared_ptr<library::XML>) override;
181 
182  auto reservedByteArraySize() const->size_t;
183  void setByteArray(ByteArray &&);
184 
185  protected:
186  template <typename T>
187  void construct_by_varadic_template(const T &val)
188  {
189  this->type = "number";
190 
191  std::stringstream sstream;
192  sstream << val;
193 
194  this->str = move(sstream.str());
195  };
196  template<> void construct_by_varadic_template(const std::string &str)
197  {
198  this->type = "string";
199  this->str = str;
200  };
201  template<> void construct_by_varadic_template(const WeakString &wstr)
202  {
203  this->type = "string";
204  this->str = wstr.str();
205  };
206  template<> void construct_by_varadic_template(const ByteArray &byteArray)
207  {
208  this->type = "ByteArray";
209  this->byteArray = byteArray;
210  };
211 
212  template<> void construct_by_varadic_template(const std::shared_ptr<library::XML> &xml)
213  {
214  this->type = "XML";
215  this->xml = xml;
216  };
217 
218  public:
219  /* ----------------------------------------------------------
220  GETTERS
221  ---------------------------------------------------------- */
222  virtual auto key() const->std::string override;
223 
227  auto getName() const->std::string;
228 
232  auto getType() const->std::string;
233 
239  template<typename T> auto getValue() const -> T
240  {
241  std::stringstream sstream;
242  sstream << this->str;
243 
244  T val;
245  sstream >> val;
246 
247  return val;
248  };
249  template<> auto getValue() const -> std::string
250  {
251  return str;
252  };
253  template<> auto getValue() const -> WeakString
254  {
255  return str;
256  };
257  template<> auto getValue() const -> std::shared_ptr<library::XML>
258  {
259  return xml;
260  };
261  template<> auto getValue() const -> ByteArray
262  {
263  return byteArray;
264  };
265 
270  auto getValueAsXML() const->std::shared_ptr<library::XML>;
271 
277  template <typename T> auto referValue() const -> const T&;
278  template<> auto referValue() const -> const std::string&
279  {
280  return str;
281  };
282  template<> auto referValue() const -> const ByteArray&
283  {
284  return byteArray;
285  };
286 
292  template <typename T> auto moveValue()->T;
293  template<> auto moveValue() -> std::string
294  {
295  return move(str);
296  };
297  template<> auto moveValue() -> ByteArray
298  {
299  return move(byteArray);
300  };
301 
302  public:
303  /* ----------------------------------------------------------
304  EXPORTERS
305  ---------------------------------------------------------- */
306  virtual auto TAG() const->std::string override;
307 
308  virtual auto toXML() const->std::shared_ptr<library::XML> override;
309 
313  auto toSQL() const->std::string;
314  };
315 };
316 };
An entity, a standard data class.
Definition: Entity.hpp:48
std::string str
A string value if the type is "string" or "number".
std::string name
A name can represent the parameter.
ByteArray byteArray
A binary value if the type is "ByteArray".
auto str() const -> std::string
Get the string content.
Definition: WeakString.cpp:546
InvokeParameter(const std::string &name, const T &val)
Construct with its name and a value.
std::shared_ptr< library::XML > xml
An XML object if the type is "XML".
Standard message of network I/O.
Definition: Invoke.hpp:47
Binary data class.
Definition: ByteArray.hpp:30
XML is a class representing xml object.
Definition: XML.hpp:72
std::string type
Type of the parameter.
A parameter of an Invoke.
auto getValue() const -> T
Get value.
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7
A string class only references characeters, reference only.
Definition: WeakString.hpp:32