Samchon Framework for CPP  1.0.0
IHTMLEntity.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <string>
5 #include <sstream>
6 
7 namespace samchon
8 {
9  class WeakString;
10 };
11 
12 namespace samchon
13 {
14 namespace protocol
15 {
41  class SAMCHON_FRAMEWORK_API IHTMLEntity
42  {
43  public:
44  /* ------------------------------------------------------------------------------------
45  CONSTRUCTORS
46  ------------------------------------------------------------------------------------ */
50  IHTMLEntity();
51  virtual ~IHTMLEntity() = default;
52 
53  /* ------------------------------------------------------------------------------------
54  EXPORTERS
55  ------------------------------------------------------------------------------------ */
88  template <typename T, typename ... _Args>
89  static auto toTH(const T &val, const _Args& ... args) -> std::string
90  {
91  std::string str;
92  size_t i = 0;
93  size_t size = sizeof...(args)+1;
94 
95  fetchTX("th", str, i, size, val, args...);
96  return str;
97  };
98  template <typename T>
99  static auto toTH(const T &val) -> std::string
100  {
101  std::string str =
102  "\t<th>\n" +
103  "\t\t" + toTD(val) + "\n" +
104  "\t</th>";
105 
106  return str;
107  };
108 
141  template <typename T, typename ... _Args>
142  static auto toTR(const T &val, const _Args& ... args) -> std::string
143  {
144  std::string str;
145  size_t i = 0;
146  size_t size = sizeof...(args)+1;
147 
148  fetchTX("tr", str, i, size, val, args...);
149  return str;
150  };
151  template <typename T>
152  static auto toTR(const T &val) -> std::string
153  {
154  std::string str =
155  "\t<tr>\n" +
156  "\t\t" + toTD(val) + "\n" +
157  "\t</tr>";
158 
159  return str;
160  };
161 
167  virtual auto toHTML() const->std::string = 0;
168 
169  protected:
170  template <typename T, typename ... _Args>
171  static void fetchTX(const std::string &tag, std::string &str, size_t &index, size_t size, const T &val, const _Args& ... args)
172  {
173  fetchTX(tag, str, index, size, val);
174 
175  index++;
176  fetchTX(tag, str, index, size, args...);
177  };
178  template <typename T>
179  static void fetchTX(const std::string &tag, std::string &str, size_t &index, size_t size, const T &val)
180  {
181  if (index == 0)
182  str += "\t<" + tag + ">\n";
183 
184  str += "\t\t" + toTD(val) + "\n";
185 
186  if (index == size - 1)
187  str += "\t</" + tag + ">";
188  };
189 
190  template <typename T>
191  static auto toTD(const T &val) -> std::string
192  {
193  std::stringstream ss;
194 
195  ss << "<td>" << val << "</td>";
196  return ss.str();
197  };
198  template<> static auto toTD(const WeakString &)->std::string;
199  };
200 };
201 };
static auto toTR(const T &val, const _Args &...args) -> std::string
Get a string represents a <tr> tag.
static auto toTH(const T &val, const _Args &...args) -> std::string
Get a string represents a <th> tag.
Definition: IHTMLEntity.hpp:89
An interface supporting conversion to html.
Definition: IHTMLEntity.hpp:41
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7
A string class only references characeters, reference only.
Definition: WeakString.hpp:32