mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-20 12:14:55 +00:00
Add GeneralFiller helper task to group tasks together.
This commit is contained in:
parent
5798e0d315
commit
85cbc76de4
3 changed files with 76 additions and 3 deletions
72
include/dindexer-machinery/scantask/generalfiller.hpp
Normal file
72
include/dindexer-machinery/scantask/generalfiller.hpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef id904376BAD85D4782B83CAAEC2EF344D9
|
||||||
|
#define id904376BAD85D4782B83CAAEC2EF344D9
|
||||||
|
|
||||||
|
#include "dindexer-machinery/scantask/leanbase.hpp"
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
#include <ciso646>
|
||||||
|
|
||||||
|
namespace mchlib {
|
||||||
|
namespace scantask {
|
||||||
|
template <typename T>
|
||||||
|
class GeneralFiller : public LeanBase<T> {
|
||||||
|
public:
|
||||||
|
using FillingTaskPtr = std::shared_ptr<LeanBase<T>>;
|
||||||
|
|
||||||
|
template <typename P, typename... PP>
|
||||||
|
GeneralFiller ( std::shared_ptr<P> parFill, std::shared_ptr<PP>... parFillList );
|
||||||
|
virtual ~GeneralFiller ( void ) noexcept;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void on_data_fill ( void ) override;
|
||||||
|
virtual T& on_data_get ( void ) override;
|
||||||
|
|
||||||
|
std::vector<FillingTaskPtr> m_to_fill;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
template <typename P, typename... PP>
|
||||||
|
GeneralFiller<T>::GeneralFiller (std::shared_ptr<P> parFill, std::shared_ptr<PP>... parFillList) :
|
||||||
|
m_to_fill { std::move(parFill), std::move(parFillList)... }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
GeneralFiller<T>::~GeneralFiller() noexcept {
|
||||||
|
m_to_fill.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void GeneralFiller<T>::on_data_fill() {
|
||||||
|
for (auto& itm : m_to_fill) {
|
||||||
|
itm->get_or_create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T& GeneralFiller<T>::on_data_get() {
|
||||||
|
assert(not m_to_fill.empty());
|
||||||
|
return m_to_fill.front()->get_or_create();
|
||||||
|
}
|
||||||
|
} //namespace scantask
|
||||||
|
} //namespace mchlib
|
||||||
|
|
||||||
|
#endif
|
|
@ -34,7 +34,6 @@ namespace mchlib {
|
||||||
explicit Mime ( DirTreeTaskPtr parDirTree );
|
explicit Mime ( DirTreeTaskPtr parDirTree );
|
||||||
virtual ~Mime ( void ) noexcept;
|
virtual ~Mime ( void ) noexcept;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void on_data_fill ( void ) override;
|
virtual void on_data_fill ( void ) override;
|
||||||
virtual std::vector<FileRecordData>& on_data_get ( void ) override;
|
virtual std::vector<FileRecordData>& on_data_get ( void ) override;
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "dindexer-machinery/scantask/hashing.hpp"
|
#include "dindexer-machinery/scantask/hashing.hpp"
|
||||||
#include "dindexer-machinery/scantask/contenttype.hpp"
|
#include "dindexer-machinery/scantask/contenttype.hpp"
|
||||||
#include "dindexer-machinery/scantask/mime.hpp"
|
#include "dindexer-machinery/scantask/mime.hpp"
|
||||||
|
#include "dindexer-machinery/scantask/generalfiller.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
@ -52,6 +53,7 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
using std::placeholders::_1;
|
using std::placeholders::_1;
|
||||||
using std::placeholders::_2;
|
using std::placeholders::_2;
|
||||||
using boost::program_options::variables_map;
|
using boost::program_options::variables_map;
|
||||||
|
using FileRecordDataFiller = mchlib::scantask::GeneralFiller<mchlib::scantask::DirTree::PathList>;
|
||||||
|
|
||||||
variables_map vm;
|
variables_map vm;
|
||||||
try {
|
try {
|
||||||
|
@ -84,11 +86,11 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
std::shared_ptr<mchlib::scantask::Hashing> hashing(new mchlib::scantask::Hashing(scan_dirtree, true));
|
std::shared_ptr<mchlib::scantask::Hashing> hashing(new mchlib::scantask::Hashing(scan_dirtree, true));
|
||||||
std::shared_ptr<mchlib::scantask::ContentType> content_type(new mchlib::scantask::ContentType(scan_dirtree, media_type));
|
std::shared_ptr<mchlib::scantask::ContentType> content_type(new mchlib::scantask::ContentType(scan_dirtree, media_type));
|
||||||
std::shared_ptr<mchlib::scantask::Mime> mime(new mchlib::scantask::Mime(scan_dirtree));
|
std::shared_ptr<mchlib::scantask::Mime> mime(new mchlib::scantask::Mime(scan_dirtree));
|
||||||
|
std::shared_ptr<FileRecordDataFiller> filerecdata(new FileRecordDataFiller(mime, hashing));
|
||||||
|
|
||||||
std::cout << "Content type: " << mchlib::content_type_to_char(content_type->get_or_create()) << std::endl;
|
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) {
|
for (const auto& hash : hashes) {
|
||||||
std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << " mime: " << hash.mime_type << "\n";
|
std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << " mime: " << hash.mime_type << "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue