remwharead  0.8.1
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

virtual 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...
 

Additional Inherited Members

- Protected Member Functions inherited from remwharead::Export::ExportBase
const 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...
 
- 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.
25  : _entries(sort_entries(entries))
26  , _out(out)
27  {}
const list< Database::entry > sort_entries(list< Database::entry > entries) const
Sort entries from newest to oldest and remove duplicates.
Definition: export.cpp:30

◆ print()

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

Print output to std::ostream.

Implements remwharead::Export::ExportBase.

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

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