Samchon Framework for CPP  1.0.0
Invoke.hpp
1 #pragma once
2 #include <samchon/protocol/SharedEntityArray.hpp>
3 # include <samchon/protocol/InvokeParameter.hpp>
4 
5 namespace samchon
6 {
7 namespace protocol
8 {
35  class Invoke
36  : public SharedEntityArray<InvokeParameter>
37  {
38  private:
40 
41  protected:
45  std::string listener;
46 
47  public:
48  /* --------------------------------------------------------------------
49  CONSTRUCTORS
50  -------------------------------------------------------------------- */
51  Invoke() : super()
52  {
53  };
54 
60  Invoke(const std::string &listener)
61  {
62  this->listener = listener;
63  };
64 
65  virtual ~Invoke() = default;
66 
67  virtual void construct(std::shared_ptr<library::XML> xml) override
68  {
69  listener = xml->getProperty("listener");
70 
71  super::construct(xml);
72  };
73 
74  protected:
75  virtual auto createChild(std::shared_ptr<library::XML>) -> InvokeParameter* override
76  {
77  return new InvokeParameter();
78  };
79 
80  /* --------------------------------------------------------------------
81  VARIADIC CONSTRUCTORS
82  -------------------------------------------------------------------- */
83  public:
106  template <typename T, typename ... _Args>
107  Invoke(const std::string &listener, const T &val, const _Args& ... args)
108  : Invoke(listener)
109  {
110  construct_by_vardic_template(val);
111  construct_by_vardic_template(args...);
112  };
113 
114  template <typename T>
115  Invoke(const std::string &listener, const T &val)
116  : Invoke(listener)
117  {
118  construct_by_vardic_template(val);
119  };
120 
121  private:
122  template <typename T, typename ... _Args>
123  void construct_by_vardic_template(const T &val, const _Args& ... args)
124  {
125  construct_by_vardic_template(val);
126  construct_by_vardic_template(args...);
127  };
128 
129  template <typename T>
130  void construct_by_vardic_template(const T &val)
131  {
132  emplace_back(new InvokeParameter("", val));
133  };
134 
135  public:
136  /* -----------------------------------------------------------------------
137  GETTERS
138  ----------------------------------------------------------------------- */
142  auto getListener() const -> std::string
143  {
144  return listener;
145  };
146 
150  void setListener(const std::string &val)
151  {
152  listener = val;
153  };
154 
155  /* -----------------------------------------------------------------------
156  EXPORTERS
157  ----------------------------------------------------------------------- */
158  virtual auto TAG() const->std::string override
159  {
160  return "invoke";
161  };
162  virtual auto CHILD_TAG() const->std::string override
163  {
164  return "parameter";
165  };
166 
167  virtual auto toXML() const->std::shared_ptr<library::XML> override
168  {
169  std::shared_ptr<library::XML> &xml = super::toXML();
170  xml->setProperty("listener", listener);
171 
172  return xml;
173  };
174  };
175 };
176 };
virtual void construct(std::shared_ptr< library::XML > xml) override
Construct data of the Entity from an XML object.
Definition: Invoke.hpp:67
Invoke(const std::string &listener)
Construct from a listener.
Definition: Invoke.hpp:60
void setListener(const std::string &val)
Set listener.
Definition: Invoke.hpp:150
Invoke(const std::string &listener, const T &val, const _Args &...args)
Construct from arguments.
Definition: Invoke.hpp:107
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
Definition: EntityGroup.hpp:71
auto getListener() const -> std::string
Get listener.
Definition: Invoke.hpp:142
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:40
virtual auto CHILD_TAG() const -> std::string override
A tag name of children.
Definition: Invoke.hpp:162
virtual auto createChild(std::shared_ptr< library::XML >) -> InvokeParameter *override
Factory method of a child Entity.
Definition: Invoke.hpp:75
Standard message of network I/O.
Definition: Invoke.hpp:35
std::string listener
Represent who listens, often be a function name.
Definition: Invoke.hpp:45
A parameter of an Invoke.
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.hpp:167