1 #ifndef __BIAWEBDOCITEMLIST__
2 #define __BIAWEBDOCITEMLIST__
8 #include "biawebstrings.hpp"
9 #include "biawebdocument.hpp"
11 // to implement a list of items (documents) with creation/modified date/time display
13 // to implement a single document item
16 // Just the required fields to build the item
22 DocListItem (std::string title, std::string url,
23 std::time_t ctime, std::time_t mtime ) {
30 std::time_t get_mtime() {
33 void set_mtime(std::time_t mtime) {
36 std::time_t get_ctime() {
39 void set_ctime(std::time_t ctime) {
43 std::string get_url() {
47 void set_url(std::string url) {
51 std::string get_title() {
54 void set_title(std::string title) {
59 std::string to_html (std::string templatedir);
62 // output to HTML vide the template
63 std::string DocListItem::to_html (std::string templatedir) {
64 std::ifstream templ (templatedir + "/doclistitem.tpl.html");
65 std::string templstr ((std::istreambuf_iterator<char> (templ)),
66 (std::istreambuf_iterator<char> ()) );
69 // Allocate enough size for the output buffer
70 std::unique_ptr<char[]> outputstr (new char [templstr.size() +
77 strftime (ctm_str, 100, DATE_FORMAT, std::localtime (&this->ctime));
78 strftime (mtm_str, 100, DATE_FORMAT, std::localtime (&this->mtime));
80 sprintf (outputstr.get(), templstr.c_str(),
85 std::string outputhtml;
86 outputhtml.append (outputstr.get());
90 // to implement a document list (or table)
94 std::list<DocListItem> items;
96 void set_title (std::string title) {
99 // add a document item
100 void add_document_item (DocListItem docitem) {
101 this->items.insert (this->items.cend(), docitem);
103 // render to HTML from a template
104 std::string to_html (std::string templatedir);
107 std::string DocList::to_html (std::string templatedir) {
108 std::ifstream templ (templatedir + "/doclist.tpl.html");
109 std::string templstr ( (std::istreambuf_iterator<char> (templ) ),
110 (std::istreambuf_iterator<char> ()));
112 std::string docitems = "";
113 std::string outputhtml = "";
114 // if the number of elements is non zero
115 if (this->items.size () != 0) {
116 for (DocListItem item : this->items)
117 docitems += item.to_html (templatedir);
119 // Allocate space for output buffer
120 std::unique_ptr<char[]> outputstr (new char [
125 sprintf (outputstr.get(), templstr.c_str(),
129 outputhtml.append (outputstr.get());