From 30eaf90c6aed98db194a2eb2b4b1b4014afcde6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Sat, 17 May 2014 17:12:24 +0300 Subject: [PATCH] Rework File/Label API to make it more natural --- include/IFile.h | 9 +++-- include/ILabel.h | 6 +-- include/IMediaLibrary.h | 3 ++ src/File.cpp | 90 ++++++++++++++++++++++------------------- src/File.h | 7 ++-- src/Label.cpp | 43 +------------------- src/Label.h | 4 +- src/MediaLibrary.cpp | 10 +++++ src/MediaLibrary.h | 2 +- test/Tests.cpp | 24 ++++++++--- 10 files changed, 92 insertions(+), 106 deletions(-) diff --git a/include/IFile.h b/include/IFile.h index 2e4e5de09..a8d1ef5c0 100644 --- a/include/IFile.h +++ b/include/IFile.h @@ -3,10 +3,11 @@ #include #include + +#include "IMediaLibrary.h" #include "ITrackInformation.h" class IAlbumTrack; -class ILabel; class IShowEpisode; class ITrackInformation; @@ -21,9 +22,9 @@ class IFile virtual std::shared_ptr showEpisode() = 0; virtual int playCount() = 0; virtual const std::string& mrl() = 0; - virtual std::shared_ptr addLabel( const std::string& label ) = 0; - virtual bool removeLabel( const std::shared_ptr& label ) = 0; - virtual const std::vector>& labels() = 0; + virtual bool addLabel( LabelPtr label ) = 0; + virtual bool removeLabel( LabelPtr label ) = 0; + virtual std::vector > labels() = 0; }; #endif // IFILE_H diff --git a/include/ILabel.h b/include/ILabel.h index 0f27bb5cf..93f9b3575 100644 --- a/include/ILabel.h +++ b/include/ILabel.h @@ -4,7 +4,7 @@ #include #include -class IFile; +#include "IMediaLibrary.h" class ILabel { @@ -13,9 +13,7 @@ class ILabel virtual unsigned int id() const = 0; virtual const std::string& name() = 0; - virtual std::vector>& files() = 0; - virtual bool link( IFile* file ) = 0; - virtual bool unlink( IFile* file ) const = 0; + virtual std::vector& files() = 0; }; #endif // ILABEL_H diff --git a/include/IMediaLibrary.h b/include/IMediaLibrary.h index 0e26e39dd..c3a7d4a26 100644 --- a/include/IMediaLibrary.h +++ b/include/IMediaLibrary.h @@ -6,8 +6,10 @@ #include class IFile; +class ILabel; typedef std::shared_ptr FilePtr; +typedef std::shared_ptr LabelPtr; class IMediaLibrary { @@ -16,6 +18,7 @@ class IMediaLibrary virtual bool initialize( const std::string& dbPath ) = 0; virtual FilePtr addFile( const std::string& path ) = 0; virtual FilePtr file( const std::string& path ) = 0; + virtual LabelPtr createLabel( const std::string& label ) = 0; virtual bool files( std::vector& res ) = 0; }; diff --git a/src/File.cpp b/src/File.cpp index 3c598b348..1d1f12437 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -14,7 +14,6 @@ const std::string policy::FileTable::CacheColumn = "mrl"; File::File( sqlite3* dbConnection, sqlite3_stmt* stmt ) : m_dbConnection( dbConnection ) - , m_labels( nullptr ) { m_id = sqlite3_column_int( stmt, 0 ); m_type = (Type)sqlite3_column_int( stmt, 1 ); @@ -34,7 +33,6 @@ File::File( const std::string& mrl ) , m_playCount( 0 ) , m_showEpisodeId( 0 ) , m_mrl( mrl ) - , m_labels( nullptr ) { } @@ -87,17 +85,14 @@ std::shared_ptr File::showEpisode() return m_showEpisode; } -const std::vector>& File::labels() +std::vector > File::labels() { - if ( m_labels == nullptr ) - { - m_labels = new std::vector>; - const char* req = "SELECT l.* FROM Label l " - "LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label " - "WHERE lfr.id_file = ?"; - SqliteTools::fetchAll