MLBookProc 1.1
 
Loading...
Searching...
No Matches
NotesKeeper Class Reference

The NotesKeeper class. More...

#include <NotesKeeper.h>

Public Member Functions

 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 &note)
 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< NotesBaseEntrygetNotesForCollection (const std::string &collection_name)
 Returns all notes for particular collection.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ NotesKeeper()

NotesKeeper::NotesKeeper ( const std::shared_ptr< AuxFunc > & af)

NotesKeeper constructor.

Parameters
afsmart pointer to AuxFunc object.

Member Function Documentation

◆ 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
nbeNotesBaseEntry object (see getNote() and getNotesForCollection()).
notenote text.

◆ 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_namecollection name, book came from.
book_file_full_pathbook file absolute path.
book_pathbook 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_namecollection 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()

std::string NotesKeeper::readNote ( const NotesBaseEntry & nbe)

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
nbeNotesBaseEntry object (see getNote() and getNotesForCollection()).
Returns
String containing note file raw content.

◆ readNoteText()

std::string NotesKeeper::readNoteText ( const NotesBaseEntry & nbe)

Returns note text (if any).

Parameters
nbeNotesBaseEntry object (see getNote() and getNotesForCollection()).
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_namecollection to compare bases.
reserve_directoryabsolute path to directory for reserve copies of notes to be removed. If directory does not exist, it will be created.
make_reserveif 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_namecollection name.
reserve_directoryabsolute path to directory for reserve copies of notes to be removed. If directory does not exist, it will be created.
make_reserveif 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
nbeNotesBaseEntry object (see getNote() and getNotesForCollection()).
reserve_directoryabsolute path to directory for reserve copies of notes to be removed. If directory does not exist, it will be created.
make_reserveif set to true, removeNotes() will create reserve copies of notes to be removed.