diff --git a/include/dindexer-machinery/scantask/generalfiller.hpp b/include/dindexer-machinery/scantask/generalfiller.hpp new file mode 100644 index 0000000..96181cf --- /dev/null +++ b/include/dindexer-machinery/scantask/generalfiller.hpp @@ -0,0 +1,72 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id904376BAD85D4782B83CAAEC2EF344D9 +#define id904376BAD85D4782B83CAAEC2EF344D9 + +#include "dindexer-machinery/scantask/leanbase.hpp" +#include +#include +#include +#include + +namespace mchlib { + namespace scantask { + template + class GeneralFiller : public LeanBase { + public: + using FillingTaskPtr = std::shared_ptr>; + + template + GeneralFiller ( std::shared_ptr

parFill, std::shared_ptr... parFillList ); + virtual ~GeneralFiller ( void ) noexcept; + + private: + virtual void on_data_fill ( void ) override; + virtual T& on_data_get ( void ) override; + + std::vector m_to_fill; + }; + + template + template + GeneralFiller::GeneralFiller (std::shared_ptr

parFill, std::shared_ptr... parFillList) : + m_to_fill { std::move(parFill), std::move(parFillList)... } + { + } + + template + GeneralFiller::~GeneralFiller() noexcept { + m_to_fill.clear(); + } + + template + void GeneralFiller::on_data_fill() { + for (auto& itm : m_to_fill) { + itm->get_or_create(); + } + } + + template + T& GeneralFiller::on_data_get() { + assert(not m_to_fill.empty()); + return m_to_fill.front()->get_or_create(); + } + } //namespace scantask +} //namespace mchlib + +#endif diff --git a/include/dindexer-machinery/scantask/mime.hpp b/include/dindexer-machinery/scantask/mime.hpp index bb4bd7a..1bccde7 100644 --- a/include/dindexer-machinery/scantask/mime.hpp +++ b/include/dindexer-machinery/scantask/mime.hpp @@ -34,7 +34,6 @@ namespace mchlib { explicit Mime ( DirTreeTaskPtr parDirTree ); virtual ~Mime ( void ) noexcept; - private: virtual void on_data_fill ( void ) override; virtual std::vector& on_data_get ( void ) override; diff --git a/src/scan/main.cpp b/src/scan/main.cpp index e90aafc..4a53468 100644 --- a/src/scan/main.cpp +++ b/src/scan/main.cpp @@ -31,6 +31,7 @@ #include "dindexer-machinery/scantask/hashing.hpp" #include "dindexer-machinery/scantask/contenttype.hpp" #include "dindexer-machinery/scantask/mime.hpp" +#include "dindexer-machinery/scantask/generalfiller.hpp" #include #include #include @@ -52,6 +53,7 @@ int main (int parArgc, char* parArgv[]) { using std::placeholders::_1; using std::placeholders::_2; using boost::program_options::variables_map; + using FileRecordDataFiller = mchlib::scantask::GeneralFiller; variables_map vm; try { @@ -84,11 +86,11 @@ int main (int parArgc, char* parArgv[]) { std::shared_ptr hashing(new mchlib::scantask::Hashing(scan_dirtree, true)); std::shared_ptr content_type(new mchlib::scantask::ContentType(scan_dirtree, media_type)); std::shared_ptr mime(new mchlib::scantask::Mime(scan_dirtree)); + std::shared_ptr filerecdata(new FileRecordDataFiller(mime, hashing)); std::cout << "Content type: " << mchlib::content_type_to_char(content_type->get_or_create()) << std::endl; - mime->get_or_create(); - const auto& hashes = hashing->get_or_create(); + const auto& hashes = filerecdata->get_or_create(); for (const auto& hash : hashes) { std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << " mime: " << hash.mime_type << "\n"; }