From fe7e9c4af96fa53d788aa35f782ad4fcb72a3d2b Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 9 Mar 2016 21:26:43 +0100 Subject: [PATCH] Turn around Set's tasks so that they provide a SetRecordDataFull. --- include/dindexer-machinery/mediatypes.hpp | 1 + .../scantask/contenttype.hpp | 15 ++++--- .../dindexer-machinery/scantask/mediatype.hpp | 15 +++++-- .../dindexer-machinery/scantask/setbasic.hpp | 42 +++++++++++++++++++ src/machinery/CMakeLists.txt | 1 + src/machinery/mediatypes.cpp | 4 ++ src/machinery/scantask/contenttype.cpp | 17 +++++--- src/machinery/scantask/mediatype.cpp | 18 ++++---- src/machinery/scantask/setbasic.cpp | 41 ++++++++++++++++++ src/scan/main.cpp | 10 +++-- 10 files changed, 138 insertions(+), 26 deletions(-) create mode 100644 include/dindexer-machinery/scantask/setbasic.hpp create mode 100644 src/machinery/scantask/setbasic.cpp diff --git a/include/dindexer-machinery/mediatypes.hpp b/include/dindexer-machinery/mediatypes.hpp index 6b69d6c..ede0b32 100644 --- a/include/dindexer-machinery/mediatypes.hpp +++ b/include/dindexer-machinery/mediatypes.hpp @@ -35,6 +35,7 @@ namespace mchlib { const std::string& media_type_to_str ( MediaTypes parType ); MediaTypes char_to_media_type ( char parMType ) a_pure; + char media_type_to_char ( MediaTypes parMType ) a_pure; } //namespace mchlib #endif diff --git a/include/dindexer-machinery/scantask/contenttype.hpp b/include/dindexer-machinery/scantask/contenttype.hpp index 011deff..d6ce3c5 100644 --- a/include/dindexer-machinery/scantask/contenttype.hpp +++ b/include/dindexer-machinery/scantask/contenttype.hpp @@ -18,27 +18,30 @@ #ifndef id148DBED10A0B45238E810683656BA7D5 #define id148DBED10A0B45238E810683656BA7D5 +#include "dindexer-machinery/scantask/leanbase.hpp" #include "dindexer-machinery/scantask/base.hpp" -#include "dindexer-machinery/guess_content_type.hpp" #include "dindexer-machinery/mediatypes.hpp" #include #include namespace mchlib { struct FileRecordData; + struct SetRecordDataFull; namespace scantask { - class ContentType : public Base { + class ContentType : public LeanBase { public: using DirTreeTaskPtr = std::shared_ptr>>; - using MediaTypeTaskPtr = std::shared_ptr>; + using MediaTypeTaskPtr = std::shared_ptr>; + using SetTaskType = std::shared_ptr>; - ContentType ( DirTreeTaskPtr parDirTree, MediaTypeTaskPtr parMediaType ); + ContentType ( SetTaskType parSet, DirTreeTaskPtr parDirTree, MediaTypeTaskPtr parMediaType ); private: - virtual void on_data_destroy ( mchlib::ContentTypes& parData ) override; - virtual void on_data_create ( mchlib::ContentTypes& parData ) override; + virtual void on_data_fill ( void ) override; + virtual SetRecordDataFull& on_data_get ( void ) override; + SetTaskType m_set_task; DirTreeTaskPtr m_dir_tree; MediaTypeTaskPtr m_media_type; }; diff --git a/include/dindexer-machinery/scantask/mediatype.hpp b/include/dindexer-machinery/scantask/mediatype.hpp index ee0c3cc..5b79c98 100644 --- a/include/dindexer-machinery/scantask/mediatype.hpp +++ b/include/dindexer-machinery/scantask/mediatype.hpp @@ -18,21 +18,28 @@ #ifndef id25B0BCA6D9464754920E1BC7C5D9DB57 #define id25B0BCA6D9464754920E1BC7C5D9DB57 +#include "dindexer-machinery/scantask/leanbase.hpp" #include "dindexer-machinery/scantask/base.hpp" #include "dindexer-machinery/mediatypes.hpp" #include +#include namespace mchlib { + struct SetRecordDataFull; + namespace scantask { - class MediaType : public Base { + class MediaType : public LeanBase { public: - MediaType ( char parDefault, bool parForce, std::string parSearchPath ); + using SetTaskType = std::shared_ptr>; + + MediaType ( SetTaskType parSet, char parDefault, bool parForce, std::string parSearchPath ); virtual ~MediaType ( void ) noexcept = default; private: - virtual void on_data_destroy ( MediaTypes& parData ) override; - virtual void on_data_create ( MediaTypes& parData ) override; + virtual void on_data_fill ( void ) override; + virtual SetRecordDataFull& on_data_get ( void ) override; + SetTaskType m_set_task; MediaTypes m_default; #if defined(WITH_MEDIA_AUTODETECT) std::string m_search_path; diff --git a/include/dindexer-machinery/scantask/setbasic.hpp b/include/dindexer-machinery/scantask/setbasic.hpp new file mode 100644 index 0000000..8ea75b9 --- /dev/null +++ b/include/dindexer-machinery/scantask/setbasic.hpp @@ -0,0 +1,42 @@ +/* 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 idB323CEFC89C2468CA0A341C312C6C2C0 +#define idB323CEFC89C2468CA0A341C312C6C2C0 + +#include "dindexer-machinery/scantask/base.hpp" +#include "dindexer-machinery/recorddata.hpp" +#include + +namespace mchlib { + namespace scantask { + class SetBasic : public Base { + typedef Base ParentType; + public: + explicit SetBasic ( std::string&& parName ); + virtual ~SetBasic ( void ) noexcept; + + private: + virtual void on_data_destroy ( SetRecordDataFull& parData ) override; + virtual void on_data_create ( SetRecordDataFull& parData ) override; + + std::string m_set_name; + }; + } //namespace scantask +} //namespace mchlib + +#endif diff --git a/src/machinery/CMakeLists.txt b/src/machinery/CMakeLists.txt index 9eaceb1..45d2839 100644 --- a/src/machinery/CMakeLists.txt +++ b/src/machinery/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(${PROJECT_NAME} SHARED scantask/hashing.cpp scantask/contenttype.cpp scantask/mime.cpp + scantask/setbasic.cpp ) #target_include_directories(${PROJECT_NAME} diff --git a/src/machinery/mediatypes.cpp b/src/machinery/mediatypes.cpp index cb28c0a..f6ab0dc 100644 --- a/src/machinery/mediatypes.cpp +++ b/src/machinery/mediatypes.cpp @@ -43,4 +43,8 @@ namespace mchlib { MediaTypes char_to_media_type (char parMType) { return static_cast(parMType); } + + char media_type_to_char (MediaTypes parMType) { + return static_cast(parMType); + } } //namespace mchlib diff --git a/src/machinery/scantask/contenttype.cpp b/src/machinery/scantask/contenttype.cpp index bca91ef..a3b5e22 100644 --- a/src/machinery/scantask/contenttype.cpp +++ b/src/machinery/scantask/contenttype.cpp @@ -16,26 +16,31 @@ */ #include "dindexer-machinery/scantask/contenttype.hpp" +#include "dindexer-machinery/guess_content_type.hpp" #include namespace mchlib { namespace scantask { - ContentType::ContentType (DirTreeTaskPtr parDirTree, MediaTypeTaskPtr parMediaType) : + ContentType::ContentType (SetTaskType parSet, DirTreeTaskPtr parDirTree, MediaTypeTaskPtr parMediaType) : + m_set_task(parSet), m_dir_tree(parDirTree), m_media_type(parMediaType) { + assert(m_set_task); assert(m_dir_tree); assert(m_media_type); } - void ContentType::on_data_destroy (mchlib::ContentTypes& parData) { - parData = ContentType_Unknown; + SetRecordDataFull& ContentType::on_data_get() { + return m_set_task->get_or_create(); } - void ContentType::on_data_create (mchlib::ContentTypes& parData) { - auto media_type = m_media_type->get_or_create(); + void ContentType::on_data_fill() { + auto& data = m_set_task->get_or_create(); + auto media_type = char_to_media_type(m_media_type->get_or_create().type); const auto& tree = m_dir_tree->get_or_create(); - parData = mchlib::guess_content_type(media_type, tree); + const auto cont_type = mchlib::guess_content_type(media_type, tree); + data.content_type = content_type_to_char(cont_type); } } //namespace scantask } //namespace mchlib diff --git a/src/machinery/scantask/mediatype.cpp b/src/machinery/scantask/mediatype.cpp index 194b7b5..1374c3f 100644 --- a/src/machinery/scantask/mediatype.cpp +++ b/src/machinery/scantask/mediatype.cpp @@ -20,38 +20,42 @@ #if defined(WITH_MEDIA_AUTODETECT) # include "dindexer-machinery/mediatype.hpp" #endif +#include "dindexer-machinery/recorddata.hpp" #include namespace mchlib { namespace scantask { - MediaType::MediaType (char parDefault, bool parForce, std::string parSearchPath) : + MediaType::MediaType (SetTaskType parSet, char parDefault, bool parForce, std::string parSearchPath) : + m_set_task(parSet), m_default(char_to_media_type(parDefault)) #if defined(WITH_MEDIA_AUTODETECT) , m_search_path(std::move(parSearchPath)) , m_force(parForce) #endif { + assert(m_set_task); #if !defined(WITH_MEDIA_AUTODETECT) static_cast(parForce); static_cast(parSearchPath); #endif } - void MediaType::on_data_destroy (MediaTypes& parData) { - parData = MediaType_Other; + SetRecordDataFull& MediaType::on_data_get() { + return m_set_task->get_or_create(); } - void MediaType::on_data_create (MediaTypes& parData) { + void MediaType::on_data_fill() { + auto& data = m_set_task->get_or_create(); #if defined(WITH_MEDIA_AUTODETECT) if (m_force) { - parData = m_default; + data.type = media_type_to_char(m_default); } else { const auto guessed_type = mchlib::guess_media_type(std::string(m_search_path)); - parData = guessed_type; + data.type = media_type_to_char(guessed_type); } #else - parData = m_default; + data.type = media_type_to_char(m_default); #endif } } //namespace scantask diff --git a/src/machinery/scantask/setbasic.cpp b/src/machinery/scantask/setbasic.cpp new file mode 100644 index 0000000..0538aed --- /dev/null +++ b/src/machinery/scantask/setbasic.cpp @@ -0,0 +1,41 @@ +/* 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 . + */ + +#include "dindexer-machinery/scantask/setbasic.hpp" +#include + +namespace mchlib { + namespace scantask { + SetBasic::SetBasic (std::string&& parName) : + m_set_name(std::move(parName)) + { + } + + SetBasic::~SetBasic() noexcept { + } + + void SetBasic::on_data_destroy (SetRecordDataFull& parData) { + static_cast(parData).name.clear(); + parData.name.clear(); + } + + void SetBasic::on_data_create (SetRecordDataFull& parData) { + parData.name = m_set_name; + static_cast(parData).name = parData.name; + } + } //namespace scantask +} //namespace mchlib diff --git a/src/scan/main.cpp b/src/scan/main.cpp index ca0f788..b218389 100644 --- a/src/scan/main.cpp +++ b/src/scan/main.cpp @@ -32,6 +32,7 @@ #include "dindexer-machinery/scantask/contenttype.hpp" #include "dindexer-machinery/scantask/mime.hpp" #include "dindexer-machinery/scantask/generalfiller.hpp" +#include "dindexer-machinery/scantask/setbasic.hpp" #include #include #include @@ -56,6 +57,7 @@ int main (int parArgc, char* parArgv[]) { using std::placeholders::_2; using boost::program_options::variables_map; using FileRecordDataFiller = stask::GeneralFiller; + using SetRecordDataFiller = stask::GeneralFiller; variables_map vm; try { @@ -83,14 +85,16 @@ int main (int parArgc, char* parArgv[]) { } const std::string search_path(vm["search-path"].as()); + std::shared_ptr setbasic(new stask::SetBasic(std::string(vm["setname"].as()))); std::shared_ptr scan_dirtree(new stask::DirTree(search_path)); - std::shared_ptr media_type(new stask::MediaType((vm.count("type") ? vm["type"].as() : 'O'), vm.count("type"), search_path)); + std::shared_ptr media_type(new stask::MediaType(setbasic, (vm.count("type") ? vm["type"].as() : 'O'), vm.count("type"), search_path)); std::shared_ptr hashing(new stask::Hashing(scan_dirtree, true)); - std::shared_ptr content_type(new stask::ContentType(scan_dirtree, media_type)); + std::shared_ptr content_type(new stask::ContentType(setbasic, scan_dirtree, media_type)); std::shared_ptr mime(new stask::Mime(scan_dirtree)); std::shared_ptr filerecdata(new FileRecordDataFiller(mime, hashing)); + std::shared_ptr setrecdata(new SetRecordDataFiller(media_type, content_type)); - std::cout << "Content type: " << mchlib::content_type_to_char(content_type->get_or_create()) << std::endl; + std::cout << "Content type: " << setrecdata->get_or_create().type << std::endl; const auto& hashes = filerecdata->get_or_create(); for (const auto& hash : hashes) {