MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / addBook

Method addBook

src/RecentBooksStore.cpp:24–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22RecentBooksStore RecentBooksStore::instance;
23
24void RecentBooksStore::addBook(const std::string& path, const std::string& title, const std::string& author,
25 const std::string& coverBmpPath) {
26 // Drop stale entries first so a new add can't evict a valid book in their stead.
27 pruneMissing();
28
29 // Remove existing entry if present
30 auto it =
31 std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; });
32 if (it != recentBooks.end()) {
33 recentBooks.erase(it);
34 }
35
36 // Add to front
37 recentBooks.insert(recentBooks.begin(), {path, title, author, coverBmpPath});
38
39 // Trim to max size
40 if (recentBooks.size() > MAX_RECENT_BOOKS) {
41 recentBooks.resize(MAX_RECENT_BOOKS);
42 }
43
44 saveToFile();
45}
46
47void RecentBooksStore::updateBook(const std::string& path, const std::string& title, const std::string& author,
48 const std::string& coverBmpPath) {

Callers 4

onEnterMethod · 0.80
onEnterMethod · 0.80
loopMethod · 0.80
onEnterMethod · 0.80

Calls 3

endMethod · 0.80
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected