An interface supporting conversion to html.
IHTMEntity is an interface supporting conversion method to html tags. The IHTMLEntity is used to documentation or printing data of the entity to web-screen; In C++, documentation is main reason to implementing the IHTMLEntity and in JS, printing on web-screen is main reason.
IHTMLEntity provides abstract method toHTML() and varadic template methods for constituting a table. I'm planning to support lots of utility methods for html tags but I've not exprienced developing the homepage or html service. If you're familiar with the html, please contribute to the IHTMLEntity interface.
- Example source
3 #include <samchon/protocol/Entity.hpp> 4 #include <samchon/protocol/IHTMLEntity.hpp> 5 #include <samchon/protocol/SharedEntityArray.hpp> 7 #include <samchon/library/XML.hpp> 11 # pragma comment(lib, "x64/Debug/SamchonFramework.lib") 13 # pragma comment(lib, "x64/Release/SamchonFramework.lib") 17 # pragma comment(lib, "Debug/SamchonFramework.lib") 19 # pragma comment(lib, "Release/SamchonFramework.lib") 46 Member(
const string &
id,
const string &name,
int age,
int grade)
54 virtual ~Member() =
default;
56 virtual void construct(shared_ptr<XML> xml)
override 58 this->
id = xml->getProperty(
"id");
59 this->name = xml->getProperty(
"name");
60 this->age = xml->getProperty<
int>(
"age");
61 this->grade = xml->getProperty<
int>(
"grade");
67 virtual auto key() const ->
std::
string override 75 virtual auto TAG() const ->
string override 79 virtual auto toXML() const -> shared_ptr<XML>
81 shared_ptr<XML> &xml = super::toXML();
82 xml->setProperty(
"id",
id);
83 xml->setProperty(
"name", name);
84 xml->setProperty(
"age", age);
85 xml->setProperty(
"grade", grade);
89 virtual auto toHTML() const ->
string 91 return toTR(
id, name, age, grade);
113 this->chief =
nullptr;
115 virtual ~MemberArray() =
default;
119 virtual void construct(shared_ptr<XML> xml)
override 121 super::construct(xml);
123 this->application = xml->getProperty(
"application");
124 this->department = xml->getProperty<
int>(
"department");
126 if(xml->hasProperty(
"chief") ==
true && this->has( xml->getProperty(
"chief") ) ==
true)
127 this->chief = this->
get( xml->getProperty(
"cheif") ).
get();
132 virtual auto createChild(shared_ptr<XML> =
nullptr) -> Member*
override 141 virtual auto TAG() const ->
string override 143 return "memberArray";
145 virtual auto CHILD_TAG() const ->
string override 152 virtual auto toXML() const -> shared_ptr<XML>
154 shared_ptr<XML> &xml = super::toXML();
155 xml->setProperty(
"application", application);
156 xml->setProperty(
"department", department);
159 xml->setProperty(
"cheif", chief->key());
163 virtual auto toHTML() const ->
string 165 string html =
"<table>\n";
166 html +=
toTH(
"ID",
"Name",
"Age",
"Grade") +
"\n";
168 for (
size_t i = 0; i < 2; i++)
169 html += at(i)->toHTML() +
"\n";
178 string str = string(
"") +
179 "<memberArray application='framework' department='7' cheif='samchon'>\n" +
180 " <member id='samchon' name='Jeongho Nam' age='27' grade='5' />" +
181 " <member id='submaster' name='No Name' age='100' grade='4' />" +
182 " <member id='john' name='John Doe' age='33' grade='2' />" +
183 " <member id='bad_man' name='Bad Man' age='44' grade='-1' />" +
184 " <member id='guest' name='Guest' age='0' grade='0' />" +
186 shared_ptr<XML> xml(
new XML(str));
188 MemberArray memberArray;
189 memberArray.construct(xml);
191 memberArray.emplace_back(
new Member(
"freshman",
"A fresh man", 20, 2));
192 memberArray.emplace_back(
new Member(
"senior",
"A senior", 70, 2));
194 cout << memberArray.toXML()->toString() << endl << endl;
195 cout << memberArray.toHTML() << endl;
An entity, a standard data class.
static auto toTR(const T &val, const _Args &...args) -> std::string
Get a string represents a <tr> tag.
An Entity and a container of children Entity objects.
static auto toTH(const T &val, const _Args &...args) -> std::string
Get a string represents a <th> tag.
Package of network protocol and libraries.
virtual auto toHTML() const -> std::string=0
Get an html string represents the Entity.
An interface supporting conversion to html.
Result of the example
- Author
- Jeongho Nam http://samchon.org
Definition at line 41 of file IHTMLEntity.hpp.
template<typename T , typename... _Args>
static auto samchon::protocol::IHTMLEntity::toTH |
( |
const T & |
val, |
|
|
const _Args &... |
args |
|
) |
| -> std::string
|
|
inlinestatic |
Get a string represents a <th> tag.
- Template Parameters
-
_Ty | Type of an argument to be contained with a <td> tag. |
_Args | Left varadic template arguments' type |
Returns a string represents a title columns with <th> tag by varadic template method.
Supported parameters: that can converted to string
-
number
-
(unsigned) short
-
(unsigned) long
-
(unsigned) long long
-
(unsigned) int
-
float
-
double
-
long double
-
string
- Parameters
-
val | An element to be contained with <td> a tag. |
args | Left argument to be contained with <td> tags. |
- Returns
- A string of <th> tag represents title columns.
Definition at line 89 of file IHTMLEntity.hpp.
template<typename T , typename... _Args>
static auto samchon::protocol::IHTMLEntity::toTR |
( |
const T & |
val, |
|
|
const _Args &... |
args |
|
) |
| -> std::string
|
|
inlinestatic |
Get a string represents a <tr> tag.
- Template Parameters
-
_Ty | Type of an argument to be contained with a <tr> tag. |
_Args | Left varadic template arguments' type |
Returns a string represents a data columns of a row with <tr> tag by varadic template method.
Supported parameters: that can converted to string
-
number
-
(unsigned) short
-
(unsigned) long
-
(unsigned) long long
-
(unsigned) int
-
float
-
double
-
long double
-
string
- Parameters
-
val | An element to be contained with <tr> a tag. |
args | Left argument to be contained with <tr> tags. |
- Returns
- A string of <th> tag represents data columns of a row.
Definition at line 142 of file IHTMLEntity.hpp.