The NotesKeeper class.
More...
#include <NotesKeeper.h>
|
| NotesKeeper (const std::shared_ptr< AuxFunc > &af) |
| NotesKeeper constructor.
|
|
virtual | ~NotesKeeper () |
| NotesKeeper destructor.
|
|
void | loadBase () |
| Loads notes base to memory.
|
|
void | editNote (const NotesBaseEntry &nbe, const std::string ¬e) |
| Edits note.
|
|
NotesBaseEntry | getNote (const std::string &collection_name, const std::filesystem::path &book_file_full_path, const std::string &book_path) |
| Gets NotesBaseEntry object from base or creats it.
|
|
std::string | readNote (const NotesBaseEntry &nbe) |
| Returns content of note file.
|
|
std::string | readNoteText (const NotesBaseEntry &nbe) |
| Returns note text (if any).
|
|
void | removeNotes (const NotesBaseEntry &nbe, const std::filesystem::path &reserve_directory, const bool &make_reserve) |
| Removes notes.
|
|
void | removeCollection (const std::string &collection_name, const std::filesystem::path &reserve_directory, const bool &make_reserve) |
| Removes notes for all books in particular collection.
|
|
void | refreshCollection (const std::string &collection_name, const std::filesystem::path &reserve_directory, const bool &make_reserve) |
| Compares notes base and collection base and removes notes for absent books.
|
|
std::vector< NotesBaseEntry > | getNotesForCollection (const std::string &collection_name) |
| Returns all notes for particular collection.
|
|
The NotesKeeper class.
This class contains various methods for collections notes operating. It is recommended to start from loadBase() method. To create new note call getNote() and editNote() methods. getNote() method also can be used to obtain note for particular book in collection. editNote() method can be used to remove note.
◆ NotesKeeper()
NotesKeeper::NotesKeeper |
( |
const std::shared_ptr< AuxFunc > & | af | ) |
|
◆ editNote()
void NotesKeeper::editNote |
( |
const NotesBaseEntry & | nbe, |
|
|
const std::string & | note ) |
Edits note.
If note file does not exist, this method will creat it and add NotesBaseEntry object to base. If note file exists, it will be overwritten. If note string is empty, note file will be removed, and NotesBaseEntry object will be removed from base.
- Parameters
-
◆ getNote()
NotesBaseEntry NotesKeeper::getNote |
( |
const std::string & | collection_name, |
|
|
const std::filesystem::path & | book_file_full_path, |
|
|
const std::string & | book_path ) |
Gets NotesBaseEntry object from base or creats it.
If note exists, returns its NotesBaseEntry object. If note does not exist, creats new NotesBaseEntry object.
- Parameters
-
collection_name | collection name, book came from. |
book_file_full_path | book file absolute path. |
book_path | book path in file (if any, empty string otherwise). |
- Returns
- NotesBaseEntry object for note.
◆ getNotesForCollection()
std::vector< NotesBaseEntry > NotesKeeper::getNotesForCollection |
( |
const std::string & | collection_name | ) |
|
Returns all notes for particular collection.
- Parameters
-
collection_name | collection name. |
- Returns
- Vector of NotesBaseEntry objects.
◆ loadBase()
void NotesKeeper::loadBase |
( |
| ) |
|
Loads notes base to memory.
This method should be called before any other methods of this class.
◆ readNote()
Returns content of note file.
Note file contains header and note text. Header contains collection name, book file absolute path, book path in file (if any). Header is separated from note text by "\n\n" sequence.
- Parameters
-
- Returns
- String containing note file raw content.
◆ readNoteText()
Returns note text (if any).
- Parameters
-
- Returns
- String containing note text.
◆ refreshCollection()
void NotesKeeper::refreshCollection |
( |
const std::string & | collection_name, |
|
|
const std::filesystem::path & | reserve_directory, |
|
|
const bool & | make_reserve ) |
Compares notes base and collection base and removes notes for absent books.
- Parameters
-
collection_name | collection to compare bases. |
reserve_directory | absolute path to directory for reserve copies of notes to be removed. If directory does not exist, it will be created. |
make_reserve | if set to true, refreshCollection() will create reserve copies of notes to be removed. |
◆ removeCollection()
void NotesKeeper::removeCollection |
( |
const std::string & | collection_name, |
|
|
const std::filesystem::path & | reserve_directory, |
|
|
const bool & | make_reserve ) |
Removes notes for all books in particular collection.
- Parameters
-
collection_name | collection name. |
reserve_directory | absolute path to directory for reserve copies of notes to be removed. If directory does not exist, it will be created. |
make_reserve | if set to true, removeCollection() will create reserve copies of notes to be removed. |
◆ removeNotes()
void NotesKeeper::removeNotes |
( |
const NotesBaseEntry & | nbe, |
|
|
const std::filesystem::path & | reserve_directory, |
|
|
const bool & | make_reserve ) |
Removes notes.
It is recommended to use this method after book removing from collection.
- Warning
- If nbe parametr book_file_full_path contains path to rar archive, this method will remove notes for all books in archive.
- Parameters
-
nbe | NotesBaseEntry object (see getNote() and getNotesForCollection()). |
reserve_directory | absolute path to directory for reserve copies of notes to be removed. If directory does not exist, it will be created. |
make_reserve | if set to true, removeNotes() will create reserve copies of notes to be removed. |