Fix clear() call super antipattern in handlers

This commit is contained in:
Jean-Francois Dockes 2018-11-14 15:29:07 +01:00
parent 23141307f7
commit 218b3fbfe2
8 changed files with 14 additions and 18 deletions

View File

@ -65,10 +65,9 @@ class MimeHandlerExec : public RecollFilter {
virtual bool next_document();
virtual bool skip_to_document(const std::string& ipath);
virtual void clear() {
virtual void clear_impl() override {
m_fn.erase();
m_ipath.erase();
RecollFilter::clear();
}
protected:

View File

@ -37,14 +37,12 @@ class MimeHandlerHtml : public RecollFilter {
return false;
}
virtual bool next_document();
const std::string& get_html()
{
const std::string& get_html() {
return m_html;
}
virtual void clear() {
virtual void clear_impl() override {
m_filename.erase();
m_html.erase();
RecollFilter::clear();
}
protected:
virtual bool set_document_file_impl(const std::string& mt,

View File

@ -66,7 +66,7 @@ MimeHandlerMail::~MimeHandlerMail()
{
clear();
}
void MimeHandlerMail::clear()
void MimeHandlerMail::clear_impl()
{
delete m_bincdoc; m_bincdoc = 0;
if (m_fd >= 0) {
@ -82,7 +82,6 @@ void MimeHandlerMail::clear()
delete *it;
}
m_attachments.clear();
RecollFilter::clear();
}
bool MimeHandlerMail::set_document_file_impl(const string& mt, const string &fn)

View File

@ -46,7 +46,7 @@ public:
}
virtual bool next_document();
virtual bool skip_to_document(const std::string& ipath);
virtual void clear();
virtual void clear_impl() override;
protected:
virtual bool set_document_file_impl(const std::string& mt,

View File

@ -232,7 +232,7 @@ MimeHandlerMbox::~MimeHandlerMbox()
clear();
}
void MimeHandlerMbox::clear()
void MimeHandlerMbox::clear_impl()
{
m_fn.erase();
if (m_vfp) {
@ -242,7 +242,6 @@ void MimeHandlerMbox::clear()
m_msgnum = m_lineno = 0;
m_ipath.erase();
m_offsets.clear();
RecollFilter::clear();
}
bool MimeHandlerMbox::set_document_file_impl(const string& mt, const string &fn)

View File

@ -39,7 +39,7 @@ public:
m_ipath = ipath;
return true;
}
virtual void clear();
virtual void clear_impl() override;
typedef long long mbhoff_type;
protected:

View File

@ -43,12 +43,11 @@ class MimeHandlerText : public RecollFilter {
}
virtual bool next_document();
virtual bool skip_to_document(const std::string& s);
virtual void clear() {
virtual void clear_impl() override {
m_paging = false;
m_text.erase();
m_fn.erase();
m_offs = 0;
RecollFilter::clear();
}
protected:

View File

@ -115,15 +115,17 @@ public:
return m_id;
}
// "Call super" anti-pattern again. Must be called from derived
// classes which reimplement clear()
virtual void clear() {
// Classes which need to do local work in clear() need
// to implement clear_impl()
virtual void clear() final {
clear_impl();
Dijon::Filter::clear();
m_forPreview = m_havedoc = false;
m_dfltInputCharset.clear();
m_reason.clear();
}
virtual void clear_impl() {}
// This only makes sense if the contents are currently txt/plain
// It converts from keyorigcharset to UTF-8 and sets keycharset.
bool txtdcode(const std::string& who);