Commit 4be33502 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Cache: Remove INTF template parameter

Instead, have the caller specify which type they want.
This allows us avoid using those ugly std::static_pointer_cast
parent e6960e3e
...@@ -58,7 +58,7 @@ class IMedia ...@@ -58,7 +58,7 @@ class IMedia
virtual bool removeLabel( LabelPtr label ) = 0; virtual bool removeLabel( LabelPtr label ) = 0;
virtual MoviePtr movie() = 0; virtual MoviePtr movie() = 0;
virtual const std::string& artist() const = 0; virtual const std::string& artist() const = 0;
virtual std::vector<std::shared_ptr<ILabel> > labels() = 0; virtual std::vector<LabelPtr> labels() = 0;
virtual std::vector<VideoTrackPtr> videoTracks() = 0; virtual std::vector<VideoTrackPtr> videoTracks() = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0; virtual std::vector<AudioTrackPtr> audioTracks() = 0;
// Returns the location of this file snapshot. // Returns the location of this file snapshot.
......
...@@ -151,7 +151,7 @@ std::vector<MediaPtr> Album::tracks() const ...@@ -151,7 +151,7 @@ std::vector<MediaPtr> Album::tracks() const
" LEFT JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media " " LEFT JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media "
" WHERE att.album_id = ? ORDER BY att.disc_number, att.track_number"; " WHERE att.album_id = ? ORDER BY att.disc_number, att.track_number";
m_tracks = Media::fetchAll( m_dbConnection, req, m_id ); m_tracks = Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
m_tracksCached = true; m_tracksCached = true;
return m_tracks; return m_tracks;
} }
...@@ -214,7 +214,7 @@ std::vector<ArtistPtr> Album::artists() const ...@@ -214,7 +214,7 @@ std::vector<ArtistPtr> Album::artists() const
static const std::string req = "SELECT art.* FROM " + policy::ArtistTable::Name + " art " static const std::string req = "SELECT art.* FROM " + policy::ArtistTable::Name + " art "
"LEFT JOIN AlbumArtistRelation aar ON aar.id_artist = art.id_artist " "LEFT JOIN AlbumArtistRelation aar ON aar.id_artist = art.id_artist "
"WHERE aar.id_album = ?"; "WHERE aar.id_album = ?";
return Artist::fetchAll( m_dbConnection, req, m_id ); return Artist::fetchAll<IArtist>( m_dbConnection, req, m_id );
} }
bool Album::addArtist( std::shared_ptr<Artist> artist ) bool Album::addArtist( std::shared_ptr<Artist> artist )
......
...@@ -47,10 +47,10 @@ struct AlbumTable ...@@ -47,10 +47,10 @@ struct AlbumTable
}; };
} }
class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable> class Album : public IAlbum, public Cache<Album, policy::AlbumTable>
{ {
private: using _Cache = Cache<Album, policy::AlbumTable>;
typedef Cache<Album, IAlbum, policy::AlbumTable> _Cache;
public: public:
Album( DBConnection dbConnection, sqlite::Row& row ); Album( DBConnection dbConnection, sqlite::Row& row );
Album( const std::string& title ); Album( const std::string& title );
...@@ -103,7 +103,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable> ...@@ -103,7 +103,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
mutable bool m_tracksCached; mutable bool m_tracksCached;
mutable std::mutex m_tracksLock; mutable std::mutex m_tracksLock;
friend class Cache<Album, IAlbum, policy::AlbumTable>; friend _Cache;
friend struct policy::AlbumTable; friend struct policy::AlbumTable;
}; };
......
...@@ -44,10 +44,10 @@ struct AlbumTrackTable ...@@ -44,10 +44,10 @@ struct AlbumTrackTable
}; };
} }
class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, policy::AlbumTrackTable> class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, policy::AlbumTrackTable>
{ {
private: using _Cache = Cache<AlbumTrack, policy::AlbumTrackTable>;
typedef Cache<AlbumTrack, IAlbumTrack, policy::AlbumTrackTable> _Cache;
public: public:
AlbumTrack( DBConnection dbConnection, sqlite::Row& row ); AlbumTrack( DBConnection dbConnection, sqlite::Row& row );
AlbumTrack(Media* media, unsigned int trackNumber, unsigned int albumId , unsigned int discNumber); AlbumTrack(Media* media, unsigned int trackNumber, unsigned int albumId , unsigned int discNumber);
...@@ -80,7 +80,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol ...@@ -80,7 +80,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
std::shared_ptr<Album> m_album; std::shared_ptr<Album> m_album;
friend class Cache<AlbumTrack, IAlbumTrack, policy::AlbumTrackTable>; friend _Cache;
friend struct policy::AlbumTrackTable; friend struct policy::AlbumTrackTable;
}; };
......
...@@ -80,7 +80,7 @@ std::vector<AlbumPtr> Artist::albums() const ...@@ -80,7 +80,7 @@ std::vector<AlbumPtr> Artist::albums() const
return {}; return {};
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " alb " static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " alb "
"WHERE artist_id = ? ORDER BY release_year, title"; "WHERE artist_id = ? ORDER BY release_year, title";
return Album::fetchAll( m_dbConnection, req, m_id ); return Album::fetchAll<IAlbum>( m_dbConnection, req, m_id );
} }
std::vector<MediaPtr> Artist::media() const std::vector<MediaPtr> Artist::media() const
...@@ -90,7 +90,7 @@ std::vector<MediaPtr> Artist::media() const ...@@ -90,7 +90,7 @@ std::vector<MediaPtr> Artist::media() const
static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med " static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media " "LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media "
"WHERE mar.id_artist = ?"; "WHERE mar.id_artist = ?";
return Media::fetchAll( m_dbConnection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
} }
else else
{ {
...@@ -99,7 +99,7 @@ std::vector<MediaPtr> Artist::media() const ...@@ -99,7 +99,7 @@ std::vector<MediaPtr> Artist::media() const
static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med " static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media " "LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media "
"WHERE mar.id_artist IS NULL"; "WHERE mar.id_artist IS NULL";
return Media::fetchAll( m_dbConnection, req ); return Media::fetchAll<IMedia>( m_dbConnection, req );
} }
} }
......
...@@ -40,10 +40,10 @@ struct ArtistTable ...@@ -40,10 +40,10 @@ struct ArtistTable
}; };
} }
class Artist : public IArtist, public Cache<Artist, IArtist, policy::ArtistTable> class Artist : public IArtist, public Cache<Artist, policy::ArtistTable>
{ {
private: private:
using _Cache = Cache<Artist, IArtist, policy::ArtistTable>; using _Cache = Cache<Artist, policy::ArtistTable>;
public: public:
Artist( DBConnection dbConnection, sqlite::Row& row ); Artist( DBConnection dbConnection, sqlite::Row& row );
......
...@@ -39,8 +39,10 @@ struct AudioTrackTable ...@@ -39,8 +39,10 @@ struct AudioTrackTable
}; };
} }
class AudioTrack : public IAudioTrack, public Cache<AudioTrack, IAudioTrack, policy::AudioTrackTable> class AudioTrack : public IAudioTrack, public Cache<AudioTrack, policy::AudioTrackTable>
{ {
using _Cache = Cache<AudioTrack, policy::AudioTrackTable>;
public: public:
AudioTrack( DBConnection dbConnection, sqlite::Row& row ); AudioTrack( DBConnection dbConnection, sqlite::Row& row );
AudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels, const std::string& language, const std::string& desc , unsigned int mediaId); AudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels, const std::string& language, const std::string& desc , unsigned int mediaId);
...@@ -71,7 +73,6 @@ class AudioTrack : public IAudioTrack, public Cache<AudioTrack, IAudioTrack, pol ...@@ -71,7 +73,6 @@ class AudioTrack : public IAudioTrack, public Cache<AudioTrack, IAudioTrack, pol
private: private:
typedef Cache<AudioTrack, IAudioTrack, policy::AudioTrackTable> _Cache;
friend struct policy::AudioTrackTable; friend struct policy::AudioTrackTable;
}; };
......
...@@ -104,14 +104,14 @@ std::vector<MediaPtr> Folder::files() ...@@ -104,14 +104,14 @@ std::vector<MediaPtr> Folder::files()
{ {
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + static const std::string req = "SELECT * FROM " + policy::MediaTable::Name +
" WHERE folder_id = ?"; " WHERE folder_id = ?";
return Media::fetchAll( m_dbConection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConection, req, m_id );
} }
std::vector<FolderPtr> Folder::folders() std::vector<FolderPtr> Folder::folders()
{ {
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name + static const std::string req = "SELECT * FROM " + policy::FolderTable::Name +
" WHERE id_parent = ?"; " WHERE id_parent = ?";
return fetchAll( m_dbConection, req, m_id ); return fetchAll<IFolder>( m_dbConection, req, m_id );
} }
FolderPtr Folder::parent() FolderPtr Folder::parent()
......
...@@ -52,9 +52,9 @@ struct FolderCache ...@@ -52,9 +52,9 @@ struct FolderCache
} }
class Folder : public IFolder, public Cache<Folder, IFolder, policy::FolderTable, policy::FolderCache> class Folder : public IFolder, public Cache<Folder, policy::FolderTable, policy::FolderCache>
{ {
using _Cache = Cache<Folder, IFolder, policy::FolderTable, policy::FolderCache>; using _Cache = Cache<Folder, policy::FolderTable, policy::FolderCache>;
public: public:
Folder( DBConnection dbConnection, sqlite::Row& row ); Folder( DBConnection dbConnection, sqlite::Row& row );
......
...@@ -60,7 +60,7 @@ std::vector<MediaPtr> Label::files() ...@@ -60,7 +60,7 @@ std::vector<MediaPtr> Label::files()
static const std::string req = "SELECT f.* FROM " + policy::MediaTable::Name + " f " static const std::string req = "SELECT f.* FROM " + policy::MediaTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_media = f.id_media " "LEFT JOIN LabelFileRelation lfr ON lfr.id_media = f.id_media "
"WHERE lfr.id_label = ?"; "WHERE lfr.id_label = ?";
return Media::fetchAll( m_dbConnection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
} }
LabelPtr Label::create(DBConnection dbConnection, const std::string& name ) LabelPtr Label::create(DBConnection dbConnection, const std::string& name )
......
...@@ -50,10 +50,10 @@ struct LabelCachePolicy ...@@ -50,10 +50,10 @@ struct LabelCachePolicy
} }
class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, policy::LabelCachePolicy> class Label : public ILabel, public Cache<Label, policy::LabelTable, policy::LabelCachePolicy>
{ {
private: using _Cache = Cache<Label, policy::LabelTable, policy::LabelCachePolicy>;
typedef Cache<Label, ILabel, policy::LabelTable, policy::LabelCachePolicy> _Cache;
public: public:
Label( DBConnection dbConnection, sqlite::Row& row ); Label( DBConnection dbConnection, sqlite::Row& row );
Label( const std::string& name ); Label( const std::string& name );
...@@ -70,7 +70,7 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol ...@@ -70,7 +70,7 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol
unsigned int m_id; unsigned int m_id;
std::string m_name; std::string m_name;
friend class Cache<Label, ILabel, policy::LabelTable>; friend _Cache;
friend struct policy::LabelTable; friend struct policy::LabelTable;
}; };
......
...@@ -158,12 +158,12 @@ bool Media::setShowEpisode(ShowEpisodePtr showEpisode) ...@@ -158,12 +158,12 @@ bool Media::setShowEpisode(ShowEpisodePtr showEpisode)
return true; return true;
} }
std::vector<std::shared_ptr<ILabel> > Media::labels() std::vector<LabelPtr> Media::labels()
{ {
static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l " static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label " "LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label "
"WHERE lfr.id_media = ?"; "WHERE lfr.id_media = ?";
return Label::fetchAll( m_dbConnection, req, m_id ); return Label::fetchAll<ILabel>( m_dbConnection, req, m_id );
} }
int Media::playCount() const int Media::playCount() const
...@@ -205,7 +205,7 @@ std::vector<VideoTrackPtr> Media::videoTracks() ...@@ -205,7 +205,7 @@ std::vector<VideoTrackPtr> Media::videoTracks()
{ {
static const std::string req = "SELECT * FROM " + policy::VideoTrackTable::Name + static const std::string req = "SELECT * FROM " + policy::VideoTrackTable::Name +
" WHERE media_id = ?"; " WHERE media_id = ?";
return VideoTrack::fetchAll( m_dbConnection, req, m_id ); return VideoTrack::fetchAll<IVideoTrack>( m_dbConnection, req, m_id );
} }
bool Media::addAudioTrack( const std::string& codec, unsigned int bitrate, bool Media::addAudioTrack( const std::string& codec, unsigned int bitrate,
...@@ -219,7 +219,7 @@ std::vector<AudioTrackPtr> Media::audioTracks() ...@@ -219,7 +219,7 @@ std::vector<AudioTrackPtr> Media::audioTracks()
{ {
static const std::string req = "SELECT * FROM " + policy::AudioTrackTable::Name + static const std::string req = "SELECT * FROM " + policy::AudioTrackTable::Name +
" WHERE media_id = ?"; " WHERE media_id = ?";
return AudioTrack::fetchAll( m_dbConnection, req, m_id ); return AudioTrack::fetchAll<IAudioTrack>( m_dbConnection, req, m_id );
} }
const std::string &Media::snapshot() const std::string &Media::snapshot()
......
...@@ -57,10 +57,10 @@ struct MediaCache ...@@ -57,10 +57,10 @@ struct MediaCache
}; };
} }
class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, policy::MediaCache> class Media : public IMedia, public Cache<Media, policy::MediaTable, policy::MediaCache>
{ {
private: private:
typedef Cache<Media, IMedia, policy::MediaTable, policy::MediaCache> _Cache; using _Cache = Cache<Media, policy::MediaTable, policy::MediaCache>;
public: public:
// Those should be private, however the standard states that the expression // Those should be private, however the standard states that the expression
...@@ -88,7 +88,7 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol ...@@ -88,7 +88,7 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol
bool setShowEpisode( ShowEpisodePtr showEpisode ); bool setShowEpisode( ShowEpisodePtr showEpisode );
virtual bool addLabel( LabelPtr label ) override; virtual bool addLabel( LabelPtr label ) override;
virtual bool removeLabel( LabelPtr label ) override; virtual bool removeLabel( LabelPtr label ) override;
virtual std::vector<std::shared_ptr<ILabel> > labels() override; virtual std::vector<LabelPtr> labels() override;
virtual int playCount() const override; virtual int playCount() const override;
virtual const std::string& mrl() const override; virtual const std::string& mrl() const override;
virtual MoviePtr movie() override; virtual MoviePtr movie() override;
...@@ -135,7 +135,7 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol ...@@ -135,7 +135,7 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol
ShowEpisodePtr m_showEpisode; ShowEpisodePtr m_showEpisode;
MoviePtr m_movie; MoviePtr m_movie;
friend class Cache<Media, IMedia, policy::MediaTable, policy::MediaCache>; friend _Cache;
friend struct policy::MediaTable; friend struct policy::MediaTable;
}; };
......
...@@ -173,19 +173,19 @@ void MediaLibrary::setVerbosity(LogLevel v) ...@@ -173,19 +173,19 @@ void MediaLibrary::setVerbosity(LogLevel v)
std::vector<MediaPtr> MediaLibrary::files() std::vector<MediaPtr> MediaLibrary::files()
{ {
return Media::fetchAll( m_dbConnection.get() ); return Media::fetchAll<IMedia>( m_dbConnection.get() );
} }
std::vector<MediaPtr> MediaLibrary::audioFiles() std::vector<MediaPtr> MediaLibrary::audioFiles()
{ {
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? ORDER BY title"; static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? ORDER BY title";
return Media::fetchAll( m_dbConnection.get(), req, IMedia::Type::AudioType ); return Media::fetchAll<IMedia>( m_dbConnection.get(), req, IMedia::Type::AudioType );
} }
std::vector<MediaPtr> MediaLibrary::videoFiles() std::vector<MediaPtr> MediaLibrary::videoFiles()
{ {
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? ORDER BY title"; static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? ORDER BY title";
return Media::fetchAll( m_dbConnection.get(), req, IMedia::Type::VideoType ); return Media::fetchAll<IMedia>( m_dbConnection.get(), req, IMedia::Type::VideoType );
} }
MediaPtr MediaLibrary::file( const std::string& path ) MediaPtr MediaLibrary::file( const std::string& path )
...@@ -290,7 +290,7 @@ std::vector<AlbumPtr> MediaLibrary::albums() ...@@ -290,7 +290,7 @@ std::vector<AlbumPtr> MediaLibrary::albums()
{ {
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" ORDER BY title ASC"; " ORDER BY title ASC";
return Album::fetchAll( m_dbConnection.get(), req ); return Album::fetchAll<IAlbum>( m_dbConnection.get(), req );
} }
ShowPtr MediaLibrary::show(const std::string& name) ShowPtr MediaLibrary::show(const std::string& name)
...@@ -338,7 +338,7 @@ std::vector<ArtistPtr> MediaLibrary::artists() const ...@@ -338,7 +338,7 @@ std::vector<ArtistPtr> MediaLibrary::artists() const
{ {
static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name + static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name +
" WHERE nb_albums > 0"; " WHERE nb_albums > 0";
return Artist::fetchAll( m_dbConnection.get(), req ); return Artist::fetchAll<IArtist>( m_dbConnection.get(), req );
} }
void MediaLibrary::addMetadataService(std::unique_ptr<IMetadataService> service) void MediaLibrary::addMetadataService(std::unique_ptr<IMetadataService> service)
......
...@@ -121,7 +121,7 @@ std::vector<MediaPtr> Movie::files() ...@@ -121,7 +121,7 @@ std::vector<MediaPtr> Movie::files()
{ {
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE movie_id = ?"; + " WHERE movie_id = ?";
return Media::fetchAll( m_dbConnection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
} }
bool Movie::createTable( DBConnection dbConnection ) bool Movie::createTable( DBConnection dbConnection )
......
...@@ -39,8 +39,10 @@ struct MovieTable ...@@ -39,8 +39,10 @@ struct MovieTable
}; };
} }
class Movie : public IMovie, public Cache<Movie, IMovie, policy::MovieTable> class Movie : public IMovie, public Cache<Movie, policy::MovieTable>
{ {
using _Cache = Cache<Movie, policy::MovieTable>;
public: public:
Movie( DBConnection dbConnection, sqlite::Row& row ); Movie( DBConnection dbConnection, sqlite::Row& row );
Movie( const std::string& title ); Movie( const std::string& title );
...@@ -69,7 +71,6 @@ class Movie : public IMovie, public Cache<Movie, IMovie, policy::MovieTable> ...@@ -69,7 +71,6 @@ class Movie : public IMovie, public Cache<Movie, IMovie, policy::MovieTable>
std::string m_artworkUrl; std::string m_artworkUrl;
std::string m_imdbId; std::string m_imdbId;
typedef Cache<Movie, IMovie, policy::MovieTable> _Cache;
friend struct policy::MovieTable; friend struct policy::MovieTable;
}; };
......
...@@ -142,12 +142,11 @@ void Parser::restore() ...@@ -142,12 +142,11 @@ void Parser::restore()
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE parsed = 0"; + " WHERE parsed = 0";
auto media = Media::fetchAll( m_dbConnection, req ); auto media = Media::fetchAll<Media>( m_dbConnection, req );
std::lock_guard<std::mutex> lock( m_lock ); std::lock_guard<std::mutex> lock( m_lock );
for ( auto& it : media ) for ( auto& m : media )
{ {
auto m = std::static_pointer_cast<Media>( it );
m_tasks.push( new Task( m, m_services, m_callback ) ); m_tasks.push( new Task( m, m_services, m_callback ) );
} }
} }
......
...@@ -132,7 +132,7 @@ std::vector<ShowEpisodePtr> Show::episodes() ...@@ -132,7 +132,7 @@ std::vector<ShowEpisodePtr> Show::episodes()
{ {
static const std::string req = "SELECT * FROM " + policy::ShowEpisodeTable::Name static const std::string req = "SELECT * FROM " + policy::ShowEpisodeTable::Name
+ " WHERE show_id = ?"; + " WHERE show_id = ?";
return ShowEpisode::fetchAll( m_dbConnection, req, m_id ); return ShowEpisode::fetchAll<IShowEpisode>( m_dbConnection, req, m_id );
} }
bool Show::createTable(DBConnection dbConnection) bool Show::createTable(DBConnection dbConnection)
......
...@@ -42,8 +42,10 @@ struct ShowTable ...@@ -42,8 +42,10 @@ struct ShowTable
}; };
} }
class Show : public IShow, public Cache<Show, IShow, policy::ShowTable> class Show : public IShow, public Cache<Show, policy::ShowTable>
{ {
using _Cache = Cache<Show, policy::ShowTable>;
public: public:
Show( DBConnection dbConnection, sqlite::Row& row ); Show( DBConnection dbConnection, sqlite::Row& row );
Show( const std::string& name ); Show( const std::string& name );
...@@ -75,9 +77,8 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable> ...@@ -75,9 +77,8 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
time_t m_lastSyncDate; time_t m_lastSyncDate;
std::string m_tvdbId; std::string m_tvdbId;
friend class Cache<Show, IShow, policy::ShowTable>; friend _Cache;
friend struct policy::ShowTable; friend struct policy::ShowTable;
typedef Cache<Show, IShow, policy::ShowTable> _Cache;
}; };
#endif // SHOW_H #endif // SHOW_H
...@@ -145,7 +145,7 @@ std::vector<MediaPtr> ShowEpisode::files() ...@@ -145,7 +145,7 @@ std::vector<MediaPtr> ShowEpisode::files()
{ {
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE show_episode_id = ?"; + " WHERE show_episode_id = ?";
return Media::fetchAll( m_dbConnection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
} }
bool ShowEpisode::createTable( DBConnection dbConnection ) bool ShowEpisode::createTable( DBConnection dbConnection )
......
...@@ -43,8 +43,10 @@ struct ShowEpisodeTable ...@@ -43,8 +43,10 @@ struct ShowEpisodeTable
}; };
} }
class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, IShowEpisode, policy::ShowEpisodeTable> class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, policy::ShowEpisodeTable>
{ {
using _Cache = Cache<ShowEpisode, policy::ShowEpisodeTable>;
public: public:
ShowEpisode( DBConnection dbConnection, sqlite::Row& row ); ShowEpisode( DBConnection dbConnection, sqlite::Row& row );
ShowEpisode(const std::string& name, unsigned int episodeNumber, unsigned int showId ); ShowEpisode(const std::string& name, unsigned int episodeNumber, unsigned int showId );
...@@ -80,9 +82,8 @@ class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, IShowEpisode, ...@@ -80,9 +82,8 @@ class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, IShowEpisode,
unsigned int m_showId; unsigned int m_showId;
ShowPtr m_show; ShowPtr m_show;
friend class Cache<ShowEpisode, IShowEpisode, policy::ShowEpisodeTable>; friend _Cache;
friend struct policy::ShowEpisodeTable; friend struct policy::ShowEpisodeTable;
typedef Cache<ShowEpisode, IShowEpisode, policy::ShowEpisodeTable> _Cache;
}; };
#endif // SHOWEPISODE_H #endif // SHOWEPISODE_H
...@@ -40,8 +40,10 @@ struct VideoTrackTable ...@@ -40,8 +40,10 @@ struct VideoTrackTable
}; };
} }
class VideoTrack : public IVideoTrack, public Cache<VideoTrack, IVideoTrack, policy::VideoTrackTable> class VideoTrack : public IVideoTrack, public Cache<VideoTrack, policy::VideoTrackTable>
{ {
using _Cache = Cache<VideoTrack, policy::VideoTrackTable>;
public: public:
VideoTrack( DBConnection dbConnection, sqlite::Row& row ); VideoTrack( DBConnection dbConnection, sqlite::Row& row );
VideoTrack( const std::string& codec, unsigned int width, unsigned int height, float fps, unsigned int mediaId ); VideoTrack( const std::string& codec, unsigned int width, unsigned int height, float fps, unsigned int mediaId );
...@@ -66,7 +68,6 @@ class VideoTrack : public IVideoTrack, public Cache<VideoTrack, IVideoTrack, pol ...@@ -66,7 +68,6 @@ class VideoTrack : public IVideoTrack, public Cache<VideoTrack, IVideoTrack, pol
unsigned int m_mediaId; unsigned int m_mediaId;
private: private:
typedef Cache<VideoTrack, IVideoTrack, policy::VideoTrackTable> _Cache;
friend struct policy::VideoTrackTable; friend struct policy::VideoTrackTable;
}; };
......
...@@ -68,7 +68,7 @@ class PrimaryKeyCacheKeyPolicy ...@@ -68,7 +68,7 @@ class PrimaryKeyCacheKeyPolicy
* - Inherit this class and specify the template parameter & policies accordingly * - Inherit this class and specify the template parameter & policies accordingly
* - Make this class a friend class of the class you inherit from * - Make this class a friend class of the class you inherit from
*/ */
template <typename IMPL, typename INTF, typename TABLEPOLICY, typename CACHEPOLICY = PrimaryKeyCacheKeyPolicy > template <typename IMPL, typename TABLEPOLICY, typename CACHEPOLICY = PrimaryKeyCacheKeyPolicy >
class Cache class Cache
{ {
public: public:
...@@ -96,6 +96,7 @@ class Cache ...@@ -96,6 +96,7 @@ class Cache
/* /*
* Will fetch all elements from the database & cache them. * Will fetch all elements from the database & cache them.
*/ */
template <typename INTF = IMPL>
static std::vector<std::shared_ptr<INTF>> fetchAll( DBConnection dbConnection ) static std::vector<std::shared_ptr<INTF>> fetchAll( DBConnection dbConnection )
{ {
static const std::string req = "SELECT * FROM " + TABLEPOLICY::Name; static const std::string req = "SELECT * FROM " + TABLEPOLICY::Name;
...@@ -105,7 +106,7 @@ class Cache ...@@ -105,7 +106,7 @@ class Cache
return sqlite::Tools::fetchAll<IMPL, INTF>( dbConnection, req ); return sqlite::Tools::fetchAll<IMPL, INTF>( dbConnection, req );
} }
template <typename... Args> template <typename INTF, typename... Args>
static std::vector<std::shared_ptr<INTF>> fetchAll( DBConnection dbConnection, const std::string &req, Args&&... args ) static std::vector<std::shared_ptr<INTF>> fetchAll( DBConnection dbConnection, const std::string &req, Args&&... args )
{ {
Lock lock( Mutex ); Lock lock( Mutex );
...@@ -136,7 +137,8 @@ class Cache ...@@ -136,7 +137,8 @@ class Cache
return sqlite::Tools::executeDelete( dbConnection, req, key ); return sqlite::Tools::executeDelete( dbConnection, req, key );
} }
static bool destroy( DBConnection dbConnection, const INTF* self ) template <typename T>
static bool destroy( DBConnection dbConnection, const T* self )
{ {
const auto& key = CACHEPOLICY::key( self ); const auto& key = CACHEPOLICY::key( self );
return destroy( dbConnection, key ); return destroy( dbConnection, key );
...@@ -192,11 +194,11 @@ class Cache ...@@ -192,11 +194,11 @@ class Cache
typedef std::lock_guard<std::recursive_mutex> Lock; typedef std::lock_guard<std::recursive_mutex> Lock;
}; };
template <typename IMPL, typename INTF, typename TABLEPOLICY, typename CACHEPOLICY> template <typename IMPL, typename TABLEPOLICY, typename CACHEPOLICY>
std::unordered_map<typename CACHEPOLICY::KeyType, std::shared_ptr<IMPL> > std::unordered_map<typename CACHEPOLICY::KeyType, std::shared_ptr<IMPL> >
Cache<IMPL, INTF, TABLEPOLICY, CACHEPOLICY>::Store; Cache<IMPL, TABLEPOLICY, CACHEPOLICY>::Store;
template <typename IMPL, typename INTF, typename TABLEPOLICY, typename CACHEPOLICY> template <typename IMPL, typename TABLEPOLICY, typename CACHEPOLICY>
std::recursive_mutex Cache<IMPL, INTF, TABLEPOLICY, CACHEPOLICY>::Mutex; std::recursive_mutex Cache<IMPL, TABLEPOLICY, CACHEPOLICY>::Mutex;
#endif // CACHE_H #endif // CACHE_H
...@@ -81,10 +81,9 @@ void FsDiscoverer::reload() ...@@ -81,10 +81,9 @@ void FsDiscoverer::reload()