mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Turn around Set's tasks so that they provide a SetRecordDataFull.
This commit is contained in:
parent
fd5be6216a
commit
fe7e9c4af9
10 changed files with 138 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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 <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace mchlib {
|
||||
struct FileRecordData;
|
||||
struct SetRecordDataFull;
|
||||
|
||||
namespace scantask {
|
||||
class ContentType : public Base<mchlib::ContentTypes> {
|
||||
class ContentType : public LeanBase<SetRecordDataFull> {
|
||||
public:
|
||||
using DirTreeTaskPtr = std::shared_ptr<Base<std::vector<FileRecordData>>>;
|
||||
using MediaTypeTaskPtr = std::shared_ptr<Base<mchlib::MediaTypes>>;
|
||||
using MediaTypeTaskPtr = std::shared_ptr<LeanBase<SetRecordDataFull>>;
|
||||
using SetTaskType = std::shared_ptr<LeanBase<SetRecordDataFull>>;
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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 <string>
|
||||
#include <memory>
|
||||
|
||||
namespace mchlib {
|
||||
struct SetRecordDataFull;
|
||||
|
||||
namespace scantask {
|
||||
class MediaType : public Base<mchlib::MediaTypes> {
|
||||
class MediaType : public LeanBase<SetRecordDataFull> {
|
||||
public:
|
||||
MediaType ( char parDefault, bool parForce, std::string parSearchPath );
|
||||
using SetTaskType = std::shared_ptr<LeanBase<SetRecordDataFull>>;
|
||||
|
||||
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;
|
||||
|
|
42
include/dindexer-machinery/scantask/setbasic.hpp
Normal file
42
include/dindexer-machinery/scantask/setbasic.hpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idB323CEFC89C2468CA0A341C312C6C2C0
|
||||
#define idB323CEFC89C2468CA0A341C312C6C2C0
|
||||
|
||||
#include "dindexer-machinery/scantask/base.hpp"
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace mchlib {
|
||||
namespace scantask {
|
||||
class SetBasic : public Base<SetRecordDataFull> {
|
||||
typedef Base<SetRecordDataFull> 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
|
|
@ -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}
|
||||
|
|
|
@ -43,4 +43,8 @@ namespace mchlib {
|
|||
MediaTypes char_to_media_type (char parMType) {
|
||||
return static_cast<MediaTypes>(parMType);
|
||||
}
|
||||
|
||||
char media_type_to_char (MediaTypes parMType) {
|
||||
return static_cast<char>(parMType);
|
||||
}
|
||||
} //namespace mchlib
|
||||
|
|
|
@ -16,26 +16,31 @@
|
|||
*/
|
||||
|
||||
#include "dindexer-machinery/scantask/contenttype.hpp"
|
||||
#include "dindexer-machinery/guess_content_type.hpp"
|
||||
#include <cassert>
|
||||
|
||||
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
|
||||
|
|
|
@ -20,38 +20,42 @@
|
|||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
# include "dindexer-machinery/mediatype.hpp"
|
||||
#endif
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include <utility>
|
||||
|
||||
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<void>(parForce);
|
||||
static_cast<void>(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
|
||||
|
|
41
src/machinery/scantask/setbasic.cpp
Normal file
41
src/machinery/scantask/setbasic.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dindexer-machinery/scantask/setbasic.hpp"
|
||||
#include <utility>
|
||||
|
||||
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<SetRecordData&>(parData).name.clear();
|
||||
parData.name.clear();
|
||||
}
|
||||
|
||||
void SetBasic::on_data_create (SetRecordDataFull& parData) {
|
||||
parData.name = m_set_name;
|
||||
static_cast<SetRecordData&>(parData).name = parData.name;
|
||||
}
|
||||
} //namespace scantask
|
||||
} //namespace mchlib
|
|
@ -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 <iostream>
|
||||
#include <iomanip>
|
||||
#include <ciso646>
|
||||
|
@ -56,6 +57,7 @@ int main (int parArgc, char* parArgv[]) {
|
|||
using std::placeholders::_2;
|
||||
using boost::program_options::variables_map;
|
||||
using FileRecordDataFiller = stask::GeneralFiller<stask::DirTree::PathList>;
|
||||
using SetRecordDataFiller = stask::GeneralFiller<mchlib::SetRecordDataFull>;
|
||||
|
||||
variables_map vm;
|
||||
try {
|
||||
|
@ -83,14 +85,16 @@ int main (int parArgc, char* parArgv[]) {
|
|||
}
|
||||
|
||||
const std::string search_path(vm["search-path"].as<std::string>());
|
||||
std::shared_ptr<stask::SetBasic> setbasic(new stask::SetBasic(std::string(vm["setname"].as<std::string>())));
|
||||
std::shared_ptr<stask::DirTree> scan_dirtree(new stask::DirTree(search_path));
|
||||
std::shared_ptr<stask::MediaType> media_type(new stask::MediaType((vm.count("type") ? vm["type"].as<char>() : 'O'), vm.count("type"), search_path));
|
||||
std::shared_ptr<stask::MediaType> media_type(new stask::MediaType(setbasic, (vm.count("type") ? vm["type"].as<char>() : 'O'), vm.count("type"), search_path));
|
||||
std::shared_ptr<stask::Hashing> hashing(new stask::Hashing(scan_dirtree, true));
|
||||
std::shared_ptr<stask::ContentType> content_type(new stask::ContentType(scan_dirtree, media_type));
|
||||
std::shared_ptr<stask::ContentType> content_type(new stask::ContentType(setbasic, scan_dirtree, media_type));
|
||||
std::shared_ptr<stask::Mime> mime(new stask::Mime(scan_dirtree));
|
||||
std::shared_ptr<FileRecordDataFiller> filerecdata(new FileRecordDataFiller(mime, hashing));
|
||||
std::shared_ptr<SetRecordDataFiller> 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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue