remwharead  0.6.3
Public Member Functions | List of all members
remwharead::Export::CSV Class Reference

Export as Comma Separated Values. More...

#include <csv.hpp>

Inheritance diagram for remwharead::Export::CSV:
remwharead::Export::ExportBase

Public Member Functions

virtual void print () const override
 Print output to std::ostream. More...
 
 ExportBase (const vector< Database::entry > &entries, ostream &out=cout)
 Export vector of Database::entry. More...
 

Additional Inherited Members

- Protected Member Functions inherited from remwharead::Export::ExportBase
const vector< Database::entrysort_entries (vector< Database::entry > entries) const
 Sort entries from newest to oldest. More...
 
 ExportBase (const vector< Database::entry > &entries, ostream &out=cout)
 Export vector of Database::entry. More...
 
- Protected Attributes inherited from remwharead::Export::ExportBase
const vector< Database::entry_entries
 
ostream & _out
 

Detailed Description

Export as Comma Separated Values.

Member Function Documentation

◆ ExportBase()

remwharead::Export::ExportBase::ExportBase
explicit

Export vector of Database::entry.

Parameters
entriesVector of Database::entry to export.
outOutput stream.
25  : _entries(sort_entries(entries))
26  , _out(out)
27  {}
const vector< Database::entry > sort_entries(vector< Database::entry > entries) const
Sort entries from newest to oldest.
Definition: export.cpp:30

◆ print()

void remwharead::Export::CSV::print ( ) const
overridevirtual

Print output to std::ostream.

Implements remwharead::Export::ExportBase.

26  {
27  try
28  {
29  _out << "\"URI\",\"Archived URI\",\"Date & time\",\"Tags\","
30  << "\"Title\",\"Description\",\"Full text\"\r\n";
31  for (const Database::entry &entry : _entries)
32  {
33  string strtags;
34  for (const string &tag : entry.tags)
35  {
36  strtags += tag;
37  if (tag != *(entry.tags.rbegin()))
38  {
39  strtags += ",";
40  }
41  }
42  _out << '"' << quote(entry.uri) << "\",\""
43  << quote(entry.archive_uri) << "\",\""
44  << timepoint_to_string(entry.datetime) << "\",\""
45  << quote(strtags) << "\",\""
46  << quote(entry.title) << "\",\""
47  << quote(entry.description) << "\",\""
48  << quote(entry.fulltext_oneline()) << '"'<< "\r\n";
49  }
50  }
51  catch (std::exception &e)
52  {
53  cerr << "Error in " << __func__ << ": " << e.what() << endl;
54  }
55  }
struct remwharead::Database::entry entry
Describes a database entry.

The documentation for this class was generated from the following files: