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

Export as Comma Separated Values. More...

#include <remwharead/export/csv.hpp>

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

Public Member Functions

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

Additional Inherited Members

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

Detailed Description

Export as Comma Separated Values.

Since
0.6.0

Member Function Documentation

◆ ExportBase()

remwharead::Export::ExportBase::ExportBase
explicit

Export list of Database::entry.

Parameters
entriesList of Database::entry to export.
outOutput stream.
23  : _entries(sort_entries(entries))
24  , _out(out)
25 {}
list< Database::entry > sort_entries(list< Database::entry > entries) const
Sort entries from newest to oldest and remove duplicates.
Definition: export.cpp:28

◆ print()

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

Print output to std::ostream.

Implements remwharead::Export::ExportBase.

26 {
27  try
28  {
29  _out << R"("URI","Archived URI","Date & time","Tags",)"
30  << R"("Title","Description","Full text")" << "\r\n";
31  for (const Database::entry &entry : _entries)
32  {
33  _out << '"' << quote(entry.uri) << "\",\""
34  << quote(entry.archive_uri) << "\",\""
35  << timepoint_to_string(entry.datetime) << "\",\""
36  << quote(Database::tags_to_string(entry.tags)) << "\",\""
37  << quote(entry.title) << "\",\""
38  << quote(entry.description) << "\",\""
39  << quote(entry.fulltext_oneline()) << '"'<< "\r\n";
40  }
41  }
42  catch (std::exception &e)
43  {
44  cerr << "Error in " << __func__ << ": " << e.what() << endl;
45  }
46 }
static string tags_to_string(const vector< string > &tags)
Returns tags as comma separated string.
Definition: sqlite.cpp:169

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