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

Move mediatypes.hpp/cpp to machinery.

This was needed so that machinery wouldn't depend on common.
Also moved compatibility.h to helpers include dir.
Ideally mediatypes.hpp will be merged into mediatype.hpp, or there
will be some kind of renaming because the two names are
getting really confusing.
This commit is contained in:
King_DuckZ 2016-03-04 09:01:11 +01:00
parent 6ddf79fad9
commit 1956594c01
19 changed files with 48 additions and 53 deletions

View file

@ -19,7 +19,6 @@
#define id1B7A42F6E46547A6AB0F914E2A91399F #define id1B7A42F6E46547A6AB0F914E2A91399F
#include "dindexer-common/validationerror.hpp" #include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
namespace din { namespace din {

View file

@ -18,9 +18,9 @@
#ifndef id17F1582F16C8478E8D9795BECBF275A3 #ifndef id17F1582F16C8478E8D9795BECBF275A3
#define id17F1582F16C8478E8D9795BECBF275A3 #define id17F1582F16C8478E8D9795BECBF275A3
#include "dindexer-common/mediatypes.hpp" #include "dindexer-machinery/mediatypes.hpp"
#include "dindexer-machinery/recorddata.hpp" #include "dindexer-machinery/recorddata.hpp"
#include "dindexer-common/compatibility.h" #include "helpers/compatibility.h"
#include <vector> #include <vector>
namespace mchlib { namespace mchlib {
@ -36,8 +36,8 @@ namespace mchlib {
template <bool> class SetListingView; template <bool> class SetListingView;
ContentTypes guess_content_type ( dinlib::MediaTypes parMediaType, const SetListingView<true>& parContent, std::size_t parEntriesCount=0 ); ContentTypes guess_content_type ( MediaTypes parMediaType, const SetListingView<true>& parContent, std::size_t parEntriesCount=0 );
ContentTypes guess_content_type ( dinlib::MediaTypes parMediaType, const std::vector<FileRecordData>& parContent ); ContentTypes guess_content_type ( MediaTypes parMediaType, const std::vector<FileRecordData>& parContent );
char content_type_to_char ( ContentTypes parCType ) a_pure; char content_type_to_char ( ContentTypes parCType ) a_pure;
ContentTypes char_to_content_type ( char parCType ) a_pure; ContentTypes char_to_content_type ( char parCType ) a_pure;

View file

@ -20,11 +20,11 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include "dindexer-common/mediatypes.hpp" #include "dindexer-machinery/mediatypes.hpp"
namespace mchlib { namespace mchlib {
#if defined(WITH_MEDIA_AUTODETECT) #if defined(WITH_MEDIA_AUTODETECT)
dinlib::MediaTypes guess_media_type ( std::string&& parPath ); MediaTypes guess_media_type ( std::string&& parPath );
class UnknownMediaTypeException : std::runtime_error { class UnknownMediaTypeException : std::runtime_error {
public: public:

View file

@ -18,10 +18,10 @@
#ifndef id700AFD0F33634ACC88079BB8853A9E13 #ifndef id700AFD0F33634ACC88079BB8853A9E13
#define id700AFD0F33634ACC88079BB8853A9E13 #define id700AFD0F33634ACC88079BB8853A9E13
#include "dindexer-common/compatibility.h" #include "helpers/compatibility.h"
#include <string> #include <string>
namespace dinlib { namespace mchlib {
enum MediaTypes { enum MediaTypes {
MediaType_CDRom = 'C', MediaType_CDRom = 'C',
MediaType_Directory = 'D', MediaType_Directory = 'D',
@ -35,6 +35,6 @@ namespace dinlib {
const std::string& media_type_to_str ( MediaTypes parType ); const std::string& media_type_to_str ( MediaTypes parType );
MediaTypes char_to_media_type ( char parMType ) a_pure; MediaTypes char_to_media_type ( char parMType ) a_pure;
} //namespace dinlib } //namespace mchlib
#endif #endif

View file

@ -19,21 +19,21 @@
#define id25B0BCA6D9464754920E1BC7C5D9DB57 #define id25B0BCA6D9464754920E1BC7C5D9DB57
#include "dindexer-machinery/scantask/base.hpp" #include "dindexer-machinery/scantask/base.hpp"
#include "dindexer-common/mediatypes.hpp" #include "dindexer-machinery/mediatypes.hpp"
#include <string> #include <string>
namespace mchlib { namespace mchlib {
namespace scantask { namespace scantask {
class MediaType : Base<dinlib::MediaTypes> { class MediaType : Base<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;
private: private:
virtual void on_data_destroy ( dinlib::MediaTypes& parData ); virtual void on_data_destroy ( MediaTypes& parData );
virtual void on_data_create ( dinlib::MediaTypes& parData ); virtual void on_data_create ( MediaTypes& parData );
dinlib::MediaTypes m_default; MediaTypes m_default;
#if defined(WITH_MEDIA_AUTODETECT) #if defined(WITH_MEDIA_AUTODETECT)
std::string m_search_path; std::string m_search_path;
bool m_force; bool m_force;

View file

@ -2,7 +2,6 @@ project(${bare_name}-common CXX C)
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
commandline.cpp commandline.cpp
mediatypes.cpp
settings.cpp settings.cpp
validationerror.cpp validationerror.cpp
common_info.cpp common_info.cpp

View file

@ -19,7 +19,6 @@
#define idB6191389C4AD4EE5862CCF1591BE6CE5 #define idB6191389C4AD4EE5862CCF1591BE6CE5
#include "dindexer-common/validationerror.hpp" #include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
namespace din { namespace din {

View file

@ -19,7 +19,6 @@
#define id1B7A42F6E46547A6AB0F914E2A91399F #define id1B7A42F6E46547A6AB0F914E2A91399F
#include "dindexer-common/validationerror.hpp" #include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
namespace din { namespace din {

View file

@ -11,6 +11,7 @@ add_library(${PROJECT_NAME} SHARED
filesearcher.cpp filesearcher.cpp
discinfo.cpp discinfo.cpp
mediatype.cpp mediatype.cpp
mediatypes.cpp
machinery_info.cpp machinery_info.cpp
guess_content_type.cpp guess_content_type.cpp
set_listing.cpp set_listing.cpp
@ -28,7 +29,6 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE ${bare_name}-if PRIVATE ${bare_name}-if
PRIVATE ${MAGIC_LIBRARIES} PRIVATE ${MAGIC_LIBRARIES}
PUBLIC ${bare_name}-common
) )
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}

View file

@ -42,7 +42,7 @@ namespace mchlib {
}; };
struct EntryChecking { struct EntryChecking {
typedef bool(*CheckerFunction)(dinlib::MediaTypes, const ConstSetListingView&, const std::vector<const FileRecordData*>&); typedef bool(*CheckerFunction)(MediaTypes, const ConstSetListingView&, const std::vector<const FileRecordData*>&);
std::size_t max_total_entries; std::size_t max_total_entries;
CheckerFunction checker_func; CheckerFunction checker_func;
@ -87,8 +87,8 @@ namespace mchlib {
return std::move(retval); return std::move(retval);
} }
bool identify_video_dvd (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent, const std::vector<const FileRecordData*>& parFlatContent ) { bool identify_video_dvd (MediaTypes parMediaType, const ConstSetListingView& parContent, const std::vector<const FileRecordData*>& parFlatContent ) {
if (parMediaType != dinlib::MediaType_DVD and parMediaType != dinlib::MediaType_Directory) if (parMediaType != MediaType_DVD and parMediaType != MediaType_Directory)
return false; return false;
const auto items_count = count_listing_items(parContent); const auto items_count = count_listing_items(parContent);
@ -103,8 +103,8 @@ namespace mchlib {
return check_missing_content(parFlatContent, should_have).empty(); return check_missing_content(parFlatContent, should_have).empty();
} }
bool identify_video_cd (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent, const std::vector<const FileRecordData*>& parFlatContent) { bool identify_video_cd (MediaTypes parMediaType, const ConstSetListingView& parContent, const std::vector<const FileRecordData*>& parFlatContent) {
if (parMediaType != dinlib::MediaType_CDRom and parMediaType != dinlib::MediaType_Directory) if (parMediaType != MediaType_CDRom and parMediaType != MediaType_Directory)
return false; return false;
const auto items_count = count_listing_items(parContent); const auto items_count = count_listing_items(parContent);
@ -121,7 +121,7 @@ namespace mchlib {
} }
} //unnamed namespace } //unnamed namespace
ContentTypes guess_content_type (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent, std::size_t parEntriesCount) { ContentTypes guess_content_type (MediaTypes parMediaType, const ConstSetListingView& parContent, std::size_t parEntriesCount) {
if (boost::empty(parContent)) if (boost::empty(parContent))
return ContentType_Empty; return ContentType_Empty;
@ -145,7 +145,7 @@ namespace mchlib {
return ContentType_Generic; return ContentType_Generic;
} }
ContentTypes guess_content_type (dinlib::MediaTypes parMediaType, const std::vector<FileRecordData>& parContent) { ContentTypes guess_content_type (MediaTypes parMediaType, const std::vector<FileRecordData>& parContent) {
if (parContent.empty()) if (parContent.empty())
return ContentType_Empty; return ContentType_Empty;

View file

@ -40,23 +40,23 @@ namespace mchlib {
{ {
} }
dinlib::MediaTypes guess_media_type (std::string&& parPath) { MediaTypes guess_media_type (std::string&& parPath) {
DiscInfo info(std::move(parPath)); DiscInfo info(std::move(parPath));
const DriveTypes drive_type = info.drive_type(); const DriveTypes drive_type = info.drive_type();
if (DriveType_HardDisk == drive_type) { if (DriveType_HardDisk == drive_type) {
if (info.mountpoint() == PathName(info.original_path()).path()) if (info.mountpoint() == PathName(info.original_path()).path())
return dinlib::MediaType_HardDisk; return MediaType_HardDisk;
else else
return dinlib::MediaType_Directory; return MediaType_Directory;
} }
else if (DriveType_Optical == drive_type) { else if (DriveType_Optical == drive_type) {
switch (info.optical_type()) { switch (info.optical_type()) {
case OpticalType_DVD: case OpticalType_DVD:
return dinlib::MediaType_DVD; return MediaType_DVD;
case OpticalType_CDRom: case OpticalType_CDRom:
return dinlib::MediaType_CDRom; return MediaType_CDRom;
case OpticalType_BluRay: case OpticalType_BluRay:
return dinlib::MediaType_BluRay; return MediaType_BluRay;
default: default:
throw UnknownMediaTypeException("Set autodetect failed because this media type is unknown, please specify the set type manually"); throw UnknownMediaTypeException("Set autodetect failed because this media type is unknown, please specify the set type manually");
} }

View file

@ -15,11 +15,11 @@
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>. * along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dindexer-common/mediatypes.hpp" #include "dindexer-machinery/mediatypes.hpp"
#include <map> #include <map>
#include <stdexcept> #include <stdexcept>
namespace dinlib { namespace mchlib {
const std::string& media_type_to_str (MediaTypes parType) { const std::string& media_type_to_str (MediaTypes parType) {
static const std::map<MediaTypes, const std::string> types { static const std::map<MediaTypes, const std::string> types {
{MediaType_CDRom, "CD-Rom"}, {MediaType_CDRom, "CD-Rom"},
@ -43,4 +43,4 @@ namespace dinlib {
MediaTypes char_to_media_type (char parMType) { MediaTypes char_to_media_type (char parMType) {
return static_cast<MediaTypes>(parMType); return static_cast<MediaTypes>(parMType);
} }
} //namespace dinlib } //namespace mchlib

View file

@ -25,7 +25,7 @@
namespace mchlib { namespace mchlib {
namespace scantask { namespace scantask {
MediaType::MediaType (char parDefault, bool parForce, std::string parSearchPath) : MediaType::MediaType (char parDefault, bool parForce, std::string parSearchPath) :
m_default(dinlib::char_to_media_type(parDefault)) m_default(char_to_media_type(parDefault))
#if defined(WITH_MEDIA_AUTODETECT) #if defined(WITH_MEDIA_AUTODETECT)
, m_search_path(std::move(parSearchPath)) , m_search_path(std::move(parSearchPath))
, m_force(parForce) , m_force(parForce)
@ -37,11 +37,11 @@ namespace mchlib {
#endif #endif
} }
void MediaType::on_data_destroy (dinlib::MediaTypes& parData) { void MediaType::on_data_destroy (MediaTypes& parData) {
parData = dinlib::MediaType_Other; parData = MediaType_Other;
} }
void MediaType::on_data_create (dinlib::MediaTypes& parData) { void MediaType::on_data_create (MediaTypes& parData) {
#if defined(WITH_MEDIA_AUTODETECT) #if defined(WITH_MEDIA_AUTODETECT)
if (m_force) { if (m_force) {
parData = m_default; parData = m_default;

View file

@ -19,7 +19,6 @@
#define id1B7A42F6E46547A6AB0F914E2A91399F #define id1B7A42F6E46547A6AB0F914E2A91399F
#include "dindexer-common/validationerror.hpp" #include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
namespace din { namespace din {

View file

@ -19,7 +19,6 @@
#define id259FD7C96B5049ECB50386F25455FBB2 #define id259FD7C96B5049ECB50386F25455FBB2
#include "dindexer-common/validationerror.hpp" #include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
namespace din { namespace din {

View file

@ -27,14 +27,14 @@ namespace po = boost::program_options;
namespace din { namespace din {
namespace { namespace {
const char g_allowed_types[] = { const char g_allowed_types[] = {
static_cast<char>(dinlib::MediaType_CDRom), static_cast<char>(mchlib::MediaType_CDRom),
static_cast<char>(dinlib::MediaType_Directory), static_cast<char>(mchlib::MediaType_Directory),
static_cast<char>(dinlib::MediaType_DVD), static_cast<char>(mchlib::MediaType_DVD),
static_cast<char>(dinlib::MediaType_BluRay), static_cast<char>(mchlib::MediaType_BluRay),
static_cast<char>(dinlib::MediaType_FloppyDisk), static_cast<char>(mchlib::MediaType_FloppyDisk),
static_cast<char>(dinlib::MediaType_HardDisk), static_cast<char>(mchlib::MediaType_HardDisk),
static_cast<char>(dinlib::MediaType_IomegaZip), static_cast<char>(mchlib::MediaType_IomegaZip),
static_cast<char>(dinlib::MediaType_Other) static_cast<char>(mchlib::MediaType_Other)
}; };
} //unnamed namespace } //unnamed namespace

View file

@ -19,6 +19,7 @@
#define id1B7A42F6E46547A6AB0F914E2A91399F #define id1B7A42F6E46547A6AB0F914E2A91399F
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include "dindexer-machinery/mediatypes.hpp"
#include "dindexer-machinery/mediatype.hpp" #include "dindexer-machinery/mediatype.hpp"
namespace din { namespace din {

View file

@ -23,7 +23,7 @@
namespace { namespace {
template <std::size_t N> template <std::size_t N>
void detect_type (mchlib::FileRecordData (&parTestData)[N], mchlib::ContentTypes parExpected, dinlib::MediaTypes parMediaType) { void detect_type (mchlib::FileRecordData (&parTestData)[N], mchlib::ContentTypes parExpected, mchlib::MediaTypes parMediaType) {
using mchlib::SetListing; using mchlib::SetListing;
using mchlib::FileRecordData; using mchlib::FileRecordData;
@ -52,7 +52,7 @@ TEST(machinery, guess_content_type) {
FileRecordData("VIDEO_TS/VTS_01_0.VOB",0,0,2,false,false), FileRecordData("VIDEO_TS/VTS_01_0.VOB",0,0,2,false,false),
FileRecordData("VIDEO_TS/VIDEO_TS.VOB",0,0,2,false,false) FileRecordData("VIDEO_TS/VIDEO_TS.VOB",0,0,2,false,false)
}; };
detect_type(test_data, mchlib::ContentType_VideoDVD, dinlib::MediaType_DVD); detect_type(test_data, mchlib::ContentType_VideoDVD, mchlib::MediaType_DVD);
} }
{ {
@ -63,7 +63,7 @@ TEST(machinery, guess_content_type) {
FileRecordData("some_file.bin",0,0,1,false,false), FileRecordData("some_file.bin",0,0,1,false,false),
FileRecordData("another_dir/VTS_01_0.BUP",0,0,2,false,false) FileRecordData("another_dir/VTS_01_0.BUP",0,0,2,false,false)
}; };
detect_type(test_data, mchlib::ContentType_Generic, dinlib::MediaType_Directory); detect_type(test_data, mchlib::ContentType_Generic, mchlib::MediaType_Directory);
} }
{ {
@ -81,6 +81,6 @@ TEST(machinery, guess_content_type) {
FileRecordData("CDI",0,0,1,true,false), FileRecordData("CDI",0,0,1,true,false),
FileRecordData("KARAOKE",0,0,1,true,false) FileRecordData("KARAOKE",0,0,1,true,false)
}; };
detect_type(test_data, mchlib::ContentType_VideoCD, dinlib::MediaType_CDRom); detect_type(test_data, mchlib::ContentType_VideoCD, mchlib::MediaType_CDRom);
} }
} }