1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

New ContentType task.

Fix the problems I encountered while trying to use the new task.
This commit is contained in:
King_DuckZ 2016-03-08 19:54:04 +01:00
parent b357bfb2cc
commit c068f93bac
7 changed files with 99 additions and 5 deletions

View file

@ -0,0 +1,48 @@
/* 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 id148DBED10A0B45238E810683656BA7D5
#define id148DBED10A0B45238E810683656BA7D5
#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;
namespace scantask {
class ContentType : public Base<mchlib::ContentTypes> {
public:
using DirTreeTaskPtr = std::shared_ptr<Base<std::vector<FileRecordData>>>;
using MediaTypeTaskPtr = std::shared_ptr<Base<mchlib::MediaTypes>>;
ContentType ( DirTreeTaskPtr parDirTree, MediaTypeTaskPtr parMediaType );
private:
virtual void on_data_destroy ( mchlib::ContentTypes& parData ) override;
virtual void on_data_create ( mchlib::ContentTypes& parData ) override;
DirTreeTaskPtr m_dir_tree;
MediaTypeTaskPtr m_media_type;
};
} //namespace scantask
} //namespace mchlib
#endif

View file

@ -24,7 +24,7 @@
namespace mchlib { namespace mchlib {
namespace scantask { namespace scantask {
class MediaType : Base<MediaTypes> { class MediaType : public Base<mchlib::MediaTypes> {
public: public:
MediaType ( char parDefault, bool parForce, std::string parSearchPath ); MediaType ( char parDefault, bool parForce, std::string parSearchPath );
virtual ~MediaType ( void ) noexcept = default; virtual ~MediaType ( void ) noexcept = default;

View file

@ -19,6 +19,7 @@ add_library(${PROJECT_NAME} SHARED
scantask/dirtree.cpp scantask/dirtree.cpp
scantask/mediatype.cpp scantask/mediatype.cpp
scantask/hashing.cpp scantask/hashing.cpp
scantask/contenttype.cpp
) )
#target_include_directories(${PROJECT_NAME} #target_include_directories(${PROJECT_NAME}

View file

@ -155,7 +155,7 @@ namespace mchlib {
assert(std::equal(parContent.begin(), parContent.end(), SetListing(std::vector<FileRecordData>(parContent)).sorted_list().begin())); assert(std::equal(parContent.begin(), parContent.end(), SetListing(std::vector<FileRecordData>(parContent)).sorted_list().begin()));
//TODO: assert that the first item in the list is the shortest string //TODO: assert that the first item in the list is the shortest string
std::shared_ptr<PathName> pathname(new PathName(parContent.front().abs_path)); std::shared_ptr<PathName> pathname(new PathName(""));
ConstSetListingView view(parContent.begin(), parContent.end(), pathname->atom_count(), pathname); ConstSetListingView view(parContent.begin(), parContent.end(), pathname->atom_count(), pathname);
assert(parContent.size() >= 1); assert(parContent.size() >= 1);
return guess_content_type(parMediaType, view, parContent.size() - 1); return guess_content_type(parMediaType, view, parContent.size() - 1);

View 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/contenttype.hpp"
#include <cassert>
namespace mchlib {
namespace scantask {
ContentType::ContentType (DirTreeTaskPtr parDirTree, MediaTypeTaskPtr parMediaType) :
m_dir_tree(parDirTree),
m_media_type(parMediaType)
{
assert(m_dir_tree);
assert(m_media_type);
}
void ContentType::on_data_destroy (mchlib::ContentTypes& parData) {
parData = ContentType_Unknown;
}
void ContentType::on_data_create (mchlib::ContentTypes& parData) {
auto media_type = m_media_type->get_or_create();
const auto& tree = m_dir_tree->get_or_create();
parData = mchlib::guess_content_type(media_type, tree);
}
} //namespace scantask
} //namespace mchlib

View file

@ -99,7 +99,7 @@ namespace mchlib {
{ {
assert(parBasePath); assert(parBasePath);
assert(m_base_path or m_current == m_end); assert(m_base_path or m_current == m_end);
assert(m_current == m_end or m_base_path->atom_count() == PathName(m_current->path).atom_count()); assert(m_current == m_end or m_base_path->atom_count() == PathName(m_current->path).atom_count() + parLevelOffset);
assert(m_current == m_end or m_base_path->atom_count() == m_current->level + m_level_offset); assert(m_current == m_end or m_base_path->atom_count() == m_current->level + m_level_offset);
//Look for the point where the children of this entry start //Look for the point where the children of this entry start

View file

@ -29,6 +29,7 @@
#include "dindexer-machinery/scantask/dirtree.hpp" #include "dindexer-machinery/scantask/dirtree.hpp"
#include "dindexer-machinery/scantask/mediatype.hpp" #include "dindexer-machinery/scantask/mediatype.hpp"
#include "dindexer-machinery/scantask/hashing.hpp" #include "dindexer-machinery/scantask/hashing.hpp"
#include "dindexer-machinery/scantask/contenttype.hpp"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <ciso646> #include <ciso646>
@ -78,12 +79,15 @@ int main (int parArgc, char* parArgv[]) {
const std::string search_path(vm["search-path"].as<std::string>()); const std::string search_path(vm["search-path"].as<std::string>());
std::shared_ptr<mchlib::scantask::DirTree> scan_dirtree(new mchlib::scantask::DirTree(search_path)); std::shared_ptr<mchlib::scantask::DirTree> scan_dirtree(new mchlib::scantask::DirTree(search_path));
std::shared_ptr<mchlib::scantask::MediaType> media_type(new mchlib::scantask::MediaType((vm.count("type") ? vm["type"].as<char>() : 'O'), not vm.count("type"), search_path)); std::shared_ptr<mchlib::scantask::MediaType> media_type(new mchlib::scantask::MediaType((vm.count("type") ? vm["type"].as<char>() : 'O'), vm.count("type"), search_path));
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::cout << "Content type: " << mchlib::content_type_to_char(content_type->get_or_create()) << std::endl;
const auto& hashes = hashing->get_or_create(); const auto& hashes = hashing->get_or_create();
for (const auto& hash : hashes) { for (const auto& hash : hashes) {
std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << std::endl; std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << "\n";
} }
return 0; return 0;