diff --git a/docs/adoc_8hpp_source.html b/docs/adoc_8hpp_source.html index 09fd490..5f6b3eb 100644 --- a/docs/adoc_8hpp_source.html +++ b/docs/adoc_8hpp_source.html @@ -70,10 +70,10 @@ $(function() {
adoc.hpp
-
1 /* This file is part of remwharead.
2  * Copyright © 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef REMWHAREAD_ADOC_HPP
18 #define REMWHAREAD_ADOC_HPP
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 #include "sqlite.hpp"
24 #include "export.hpp"
25 
26 namespace remwharead
27 {
28 namespace Export
29 {
30  using std::string;
31 
32  class AsciiDoc : protected ExportBase
33  {
34  public:
36 
37  void print() const override;
38 
39  private:
40  using tagmap = std::map<string,vector<Database::entry>>;
41  using replacemap = const std::map<const string, const string>;
42 
43  const string replace(string text, const replacemap &replacements) const;
45  const string replace_in_tag(const string &text) const;
47  const string replace_in_title(const string &text) const;
49  const string replace_in_uri(const string &text) const;
50  void print_tags(const tagmap &tags) const;
51  const string get_day(const Database::entry &entry) const;
52  const string get_time(const Database::entry &entry) const;
53  };
54 }
55 }
56 
57 #endif // REMWHAREAD_ADOC_HPP
ExportBase(const vector< Database::entry > &entries, ostream &out=cout)
Export vector of Database::entry.
Definition: export.cpp:24
-
Definition: adoc.hpp:32
-
Definition: export.hpp:32
-
Definition: sqlite.hpp:39
+
1 /* This file is part of remwharead.
2  * Copyright © 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef REMWHAREAD_ADOC_HPP
18 #define REMWHAREAD_ADOC_HPP
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 #include "sqlite.hpp"
24 #include "export.hpp"
25 
26 namespace remwharead
27 {
28 namespace Export
29 {
30  using std::string;
31 
33  class AsciiDoc : protected ExportBase
34  {
35  public:
37 
38  void print() const override;
39 
40  private:
41  using tagmap = std::map<string,vector<Database::entry>>;
42  using replacemap = const std::map<const string, const string>;
43 
45  const string replace(string text, const replacemap &replacements) const;
46 
48  const string replace_in_tag(const string &text) const;
49 
51  const string replace_in_title(const string &text) const;
52 
54  const string replace_in_uri(const string &text) const;
55 
57  void print_tags(const tagmap &tags) const;
58 
60  const string get_day(const Database::entry &entry) const;
61 
63  const string get_time(const Database::entry &entry) const;
64  };
65 }
66 }
67 
68 #endif // REMWHAREAD_ADOC_HPP
ExportBase(const vector< Database::entry > &entries, ostream &out=cout)
Export vector of Database::entry.
Definition: export.cpp:24
+
Export as AsciiDoc document.
Definition: adoc.hpp:33
+
Base class for exports.
Definition: export.hpp:33
+
Describes a database entry.
Definition: sqlite.hpp:40
Definition: search.cpp:23
void print() const override
Print output to std::ostream.
diff --git a/docs/annotated.html b/docs/annotated.html index e7ef739..c5ab386 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -70,15 +70,15 @@ $(function() {
[detail level 123]
- + - - + + - - - - + + + +
 Nremwharead
 NExport
 CAsciiDoc
 CAsciiDocExport as AsciiDoc document
 CBookmarksExport as Netscape bookmark file
 CCSV
 CExportBase
 CCSVExport as Comma Separated Values
 CExportBaseBase class for exports
 CSimpleExport as simple list
 CDatabase
 Centry
 Chtml_extract
 CURI
 CDatabaseStore and retrieve files from/to SQLite
 CentryDescribes a database entry
 Chtml_extractA processed HTML page
 CURIDownload, archive and process an URI
diff --git a/docs/bookmarks_8hpp_source.html b/docs/bookmarks_8hpp_source.html index e7b928c..f3cb7fd 100644 --- a/docs/bookmarks_8hpp_source.html +++ b/docs/bookmarks_8hpp_source.html @@ -72,7 +72,7 @@ $(function() {
1 /* This file is part of remwharead.
2  * Copyright © 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef REMWHAREAD_BOOKMARKS_HPP
18 #define REMWHAREAD_BOOKMARKS_HPP
19 
20 #include "export.hpp"
21 
22 namespace remwharead
23 {
24 namespace Export
25 {
27  class Bookmarks : protected ExportBase
28  {
29  public:
31  virtual void print() const override;
32  };
33 }
34 }
35 
36 #endif // REMWHAREAD_BOOKMARKS_HPP
ExportBase(const vector< Database::entry > &entries, ostream &out=cout)
Export vector of Database::entry.
Definition: export.cpp:24
virtual void print() const override
Print output to std::ostream.
Definition: bookmarks.cpp:29
-
Definition: export.hpp:32
+
Base class for exports.
Definition: export.hpp:33
Definition: search.cpp:23
Export as Netscape bookmark file.
Definition: bookmarks.hpp:27
diff --git a/docs/classremwharead_1_1Database-members.html b/docs/classremwharead_1_1Database-members.html index 72de4c4..6a2206f 100644 --- a/docs/classremwharead_1_1Database-members.html +++ b/docs/classremwharead_1_1Database-members.html @@ -73,9 +73,9 @@ $(function() {

This is the complete list of members for remwharead::Database, including all inherited members.

- - - + + +
Database() (defined in remwharead::Database)remwharead::Database
entry typedef (defined in remwharead::Database)remwharead::Database
operator bool() const (defined in remwharead::Database)remwharead::Database
Database()remwharead::Database
entry typedefremwharead::Database
operator bool() constremwharead::Database
retrieve(const time_point &start=time_point(), const time_point &end=system_clock::now()) constremwharead::Database
store(const entry &data) constremwharead::Database
diff --git a/docs/classremwharead_1_1Database.html b/docs/classremwharead_1_1Database.html index 9292c80..d9413e0 100644 --- a/docs/classremwharead_1_1Database.html +++ b/docs/classremwharead_1_1Database.html @@ -75,32 +75,148 @@ $(function() {
remwharead::Database Class Reference
+ +

Store and retrieve files from/to SQLite. + More...

+ +

#include <sqlite.hpp>

+

Classes

struct  entry
 Describes a database entry. More...
 
- + +

Public Types

-typedef struct remwharead::Database::entry entry
typedef struct remwharead::Database::entry entry
 Describes a database entry. More...
 
- + + + + + - - + + - - + +

Public Member Functions

operator bool () const
 Database ()
 Connects to the database and creates it if necessary. More...
 
 operator bool () const
 Returns true if connected to the database. More...
 
-void store (const entry &data) const
 Store in database.
void store (const entry &data) const
 Store a Database::entry in the database. More...
 
-const vector< entryretrieve (const time_point &start=time_point(), const time_point &end=system_clock::now()) const
 retrieve from database.
const vector< entryretrieve (const time_point &start=time_point(), const time_point &end=system_clock::now()) const
 Retrieve a vector of Database::entry from the database. More...
 
+

Detailed Description

+

Store and retrieve files from/to SQLite.

+

Member Typedef Documentation

+ +

◆ entry

+ +
+
+ +

Describes a database entry.

+ +
+
+

Constructor & Destructor Documentation

+ +

◆ Database()

+ +
+
+ + + + + + + +
remwharead::Database::Database ()
+
+ +

Connects to the database and creates it if necessary.

+
32  : _connected(false)
33  {
34  try
35  {
36  xdgHandle xdg;
37  xdgInitHandle(&xdg);
38  _dbpath = xdgDataHome(&xdg) / fs::path("remwharead");
39  xdgWipeHandle(&xdg);
40 
41  if (!fs::exists(_dbpath))
42  {
43  fs::create_directories(_dbpath);
44  }
45  _dbpath /= "database.sqlite";
46 
47  _con = std::make_unique<sqlite::connection>(_dbpath);
48  sqlite::execute(*_con, "CREATE TABLE IF NOT EXISTS remwharead("
49  "uri TEXT, archive_uri TEXT, datetime TEXT, "
50  "tags TEXT, title TEXT, description TEXT, "
51  "fulltext TEXT);", true);
52 
53  _connected = true;
54  }
55  catch (std::exception &e)
56  {
57  cerr << "Error in " << __func__ << ": " << e.what() << endl;
58  }
59  }
+
+
+

Member Function Documentation

+ +

◆ operator bool()

+ +
+
+ + + + + + + +
remwharead::Database::operator bool () const
+
+ +

Returns true if connected to the database.

+
62  {
63  return _connected;
64  }
+
+
+ +

◆ retrieve()

+ +
+
+ + + + + + + + + + + + + + + + + + +
const vector< Database::entry > remwharead::Database::retrieve (const time_point & start = time_point(),
const time_point & end = system_clock::now() 
) const
+
+ +

Retrieve a vector of Database::entry from the database.

+
116  {
117  try
118  {
119  const string query = "SELECT * FROM remwharead WHERE datetime "
120  "BETWEEN '" + timepoint_to_string(start, true)
121  + "' AND '" + timepoint_to_string(end, true)
122  + "' ORDER BY datetime DESC;";
123 
124  sqlite::query q(*_con, query);
125  sqlite::result_type res = q.get_result();
126  vector<entry> entries;
127 
128  while(res->next_row())
129  {
130  vector<string> tags;
131  const string strtags = res->get_string(3);
132  size_t pos = 0;
133  while (pos != std::string::npos)
134  {
135  const size_t newpos = strtags.find(',', pos);
136  tags.push_back(strtags.substr(pos, newpos - pos));
137  pos = newpos;
138  if (pos != std::string::npos)
139  {
140  ++pos;
141  }
142  }
143  entries.push_back
144  ({
145  res->get_string(0),
146  res->get_string(1),
147  string_to_timepoint(res->get_string(2), true),
148  tags,
149  res->get_string(4),
150  res->get_string(5),
151  res->get_string(6)
152  });
153  }
154 
155  return entries;
156  }
157  catch (std::exception &e)
158  {
159  cerr << "Error in " << __func__ << ": " << e.what() << endl;
160  }
161 
162  return {};
163  }
+
+
+ +

◆ store()

+ +
+
+ + + + + + + + +
void remwharead::Database::store (const entrydata) const
+
+ +

Store a Database::entry in the database.

+
88  {
89  try
90  {
91  const string strdatetime = timepoint_to_string(data.datetime, true);
92  string strtags;
93  for (const string &tag : data.tags)
94  {
95  strtags += tag;
96  if (tag != *(data.tags.rbegin()))
97  {
98  strtags += ",";
99  }
100  }
101 
102  sqlite::execute ins(*_con, "INSERT INTO remwharead "
103  "VALUES(?, ?, ?, ?, ?, ?, ?);");
104  ins % data.uri % data.archive_uri % strdatetime % strtags
105  % data.title % data.description % data.fulltext;
106  ins();
107  }
108  catch (std::exception &e)
109  {
110  cerr << "Error in " << __func__ << ": " << e.what() << endl;
111  }
112  }
+
+

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

Export as AsciiDoc document. + More...

+ +

#include <adoc.hpp>

Inheritance diagram for remwharead::Export::AsciiDoc:
-remwharead::Export::ExportBase +remwharead::Export::ExportBase
- - + + - +

Public Member Functions

-void print () const override
 Print output to std::ostream.
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...
 Export vector of Database::entry. More...
 
- +

@@ -100,7 +104,7 @@ Additional Inherited Members

 Sort entries from newest to oldest. More...
 
 ExportBase (const vector< Database::entry > &entries, ostream &out=cout)
 Export vector of Database::entry. More...
 Export vector of Database::entry. More...
 
- Protected Attributes inherited from remwharead::Export::ExportBase
@@ -110,7 +114,9 @@ const vector< _out
 
-

Member Function Documentation

+

Detailed Description

+

Export as AsciiDoc document.

+

Member Function Documentation

◆ ExportBase()

@@ -131,16 +137,45 @@ ostream & _out
-

Export vector of Database::entry.

+

Export vector of Database::entry.

Parameters
- +
entriesVector of Database::entry to export.
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::AsciiDoc::print () const
+
+overridevirtual
+
+ +

Print output to std::ostream.

+ +

Implements remwharead::Export::ExportBase.

+

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