remwharead  0.8.5
Public Member Functions | List of all members
remwharead::Export::JSON Class Reference

Export as JSON array. More...

#include <remwharead/export/json.hpp>

Inheritance diagram for remwharead::Export::JSON:
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 JSON array.

Since
0.8.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::JSON::print ( ) const
overridevirtual

Print output to std::ostream.

Implements remwharead::Export::ExportBase.

29 {
30  try
31  {
32  Poco::JSON::Array root = Poco::JSON::Array();
33 
34  for (const Database::entry &entry : _entries)
35  {
36  Poco::JSON::Object json_entry = Poco::JSON::Object();
37 
38  json_entry.set("uri", entry.uri);
39  json_entry.set("archive_uri", entry.archive_uri);
40  json_entry.set("datetime", timepoint_to_string(entry.datetime));
41  Poco::JSON::Array tags = Poco::JSON::Array();
42  for (const string &tag : entry.tags)
43  {
44  tags.add(tag);
45  }
46  json_entry.set("tags", tags);
47  json_entry.set("title", entry.title);
48  json_entry.set("description", entry.description);
49  json_entry.set("fulltext", entry.fulltext);
50 
51  root.add(json_entry);
52  }
53 
54  root.stringify(_out);
55  _out << endl;
56  }
57  catch (std::exception &e)
58  {
59  cerr << "Error in " << __func__ << ": " << e.what() << endl;
60  }
61 }

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