Commit 72813236 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Return vectors by value

parent f05e350c
......@@ -17,7 +17,7 @@ class IAlbum
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const = 0;
virtual std::vector<std::shared_ptr<IAlbumTrack>> tracks() const = 0;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackId ) = 0;
virtual bool destroy() = 0;
};
......
......@@ -18,7 +18,7 @@ class IAlbumTrack
virtual std::shared_ptr<IAlbum> album() = 0;
virtual const std::string& artist() const = 0;
virtual bool setArtist( const std::string& artist ) = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
*/
......
......@@ -38,10 +38,10 @@ class IFile
virtual std::vector<std::shared_ptr<ILabel> > labels() = 0;
virtual bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps ) = 0;
virtual bool videoTracks( std::vector<VideoTrackPtr>& tracks ) = 0;
virtual std::vector<VideoTrackPtr> videoTracks() = 0;
virtual bool addAudioTrack( const std::string& codec, unsigned int bitrate,
unsigned int sampleRate, unsigned int nbChannels ) = 0;
virtual bool audioTracks( std::vector<AudioTrackPtr>& tracks ) = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0;
/// Returns wether the file has been added as a stand alone file (true), or as
/// part of a folder (false)
virtual bool isStandAlone() = 0;
......
......@@ -13,7 +13,7 @@ class ILabel
virtual unsigned int id() const = 0;
virtual const std::string& name() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
};
#endif // ILABEL_H
......@@ -43,7 +43,7 @@ class IMediaLibrary
virtual LabelPtr createLabel( const std::string& label ) = 0;
virtual bool deleteLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
virtual bool files( std::vector<FilePtr>& res ) = 0;
virtual std::vector<FilePtr> files() = 0;
virtual AlbumPtr album( const std::string& title ) = 0;
virtual AlbumPtr createAlbum( const std::string& title ) = 0;
virtual ShowPtr show( const std::string& name ) = 0;
......
......@@ -18,7 +18,7 @@ class IMovie
virtual const std::string& imdbId() const = 0;
virtual bool setImdbId( const std::string& id ) = 0;
virtual bool destroy() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
};
#endif // IMOVIE_H
......@@ -18,7 +18,7 @@ class IShow
virtual const std::string& tvdbId() = 0;
virtual bool setTvdbId( const std::string& id ) = 0;
virtual ShowEpisodePtr addEpisode( const std::string& title, unsigned int episodeNumber ) = 0;
virtual bool episodes( std::vector<ShowEpisodePtr>& episodes ) = 0;
virtual std::vector<ShowEpisodePtr> episodes() = 0;
virtual bool destroy() = 0;
};
......
......@@ -23,7 +23,7 @@ class IShowEpisode
virtual const std::string& tvdbId() const = 0;
virtual bool setTvdbId( const std::string& tvdbId ) = 0;
virtual std::shared_ptr<IShow> show() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
*/
......
......@@ -86,11 +86,11 @@ time_t Album::lastSyncDate() const
return m_lastSyncDate;
}
bool Album::tracks( std::vector<std::shared_ptr<IAlbumTrack> >& tracks ) const
std::vector<std::shared_ptr<IAlbumTrack>> Album::tracks() const
{
static const std::string req = "SELECT * FROM " + policy::AlbumTrackTable::Name
+ " WHERE album_id = ?";
return SqliteTools::fetchAll<AlbumTrack>( m_dbConnection, req, tracks, m_id );
return SqliteTools::fetchAll<AlbumTrack, IAlbumTrack>( m_dbConnection, req, m_id );
}
AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
......@@ -100,9 +100,7 @@ AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
bool Album::destroy()
{
std::vector<AlbumTrackPtr> ts;
if ( tracks( ts ) == false )
return false;
auto ts = tracks();
//FIXME: Have a single request to fetch all files at once, instead of having one per track
for ( auto& t : ts )
{
......
......@@ -38,7 +38,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
virtual const std::string& artworkUrl() const;
virtual bool setArtworkUrl( const std::string& artworkUrl );
virtual time_t lastSyncDate() const;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const;
virtual std::vector<std::shared_ptr<IAlbumTrack> > tracks() const;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackNb );
virtual bool destroy();
......
......@@ -95,9 +95,7 @@ std::shared_ptr<IAlbum> AlbumTrack::album()
bool AlbumTrack::destroy()
{
// Manually remove Files from cache, and let foreign key handling delete them from the DB
std::vector<FilePtr> fs;
if ( files( fs ) == false )
return false;
auto fs = files();
if ( fs.size() == 0 )
std::cerr << "No files found for AlbumTrack " << m_id << std::endl;
for ( auto& f : fs )
......@@ -124,9 +122,9 @@ bool AlbumTrack::setArtist(const std::string& artist)
return true;
}
bool AlbumTrack::files(std::vector<FilePtr>& files)
std::vector<FilePtr> AlbumTrack::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE album_track_id = ? ";
return SqliteTools::fetchAll<File>( m_dbConnection, req, files, m_id );
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
......@@ -38,7 +38,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
virtual bool destroy();
virtual const std::string& artist() const;
virtual bool setArtist( const std::string& artist );
virtual bool files( std::vector<FilePtr>& files );
virtual std::vector<FilePtr> files();
static bool createTable( DBConnection dbConnection );
static AlbumTrackPtr create( DBConnection dbConnection, unsigned int albumId,
......
......@@ -72,10 +72,10 @@ class Cache
* @param res A reference to the result vector. All existing elements will
* be discarded.
*/
static bool fetchAll( DBConnection dbConnectionWeak, std::vector<std::shared_ptr<INTF> >& res )
static std::vector<std::shared_ptr<INTF>> fetchAll( DBConnection dbConnectionWeak )
{
static const std::string req = "SELECT * FROM " + TABLEPOLICY::Name;
return SqliteTools::fetchAll<IMPL, INTF>( dbConnectionWeak, req.c_str(), res );
return SqliteTools::fetchAll<IMPL, INTF>( dbConnectionWeak, req.c_str() );
}
static std::shared_ptr<IMPL> load( std::shared_ptr<sqlite3> dbConnection, sqlite3_stmt* stmt )
......
......@@ -115,12 +115,10 @@ bool File::setShowEpisode(ShowEpisodePtr showEpisode)
std::vector<std::shared_ptr<ILabel> > File::labels()
{
std::vector<std::shared_ptr<ILabel> > labels;
static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label "
"WHERE lfr.id_file = ?";
SqliteTools::fetchAll<Label>( m_dbConnection, req, labels, m_id );
return labels;
return SqliteTools::fetchAll<Label, ILabel>( m_dbConnection, req, m_id );
}
int File::playCount() const
......@@ -167,12 +165,12 @@ bool File::addVideoTrack(const std::string& codec, unsigned int width, unsigned
return SqliteTools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
bool File::videoTracks(std::vector<VideoTrackPtr>& tracks)
std::vector<VideoTrackPtr> File::videoTracks()
{
static const std::string req = "SELECT t.* FROM " + policy::VideoTrackTable::Name +
" t LEFT JOIN VideoTrackFileRelation vtfr ON vtfr.id_track = t.id_track"
" WHERE vtfr.id_file = ?";
return SqliteTools::fetchAll<VideoTrack>( m_dbConnection, req, tracks, m_id );
return SqliteTools::fetchAll<VideoTrack, IVideoTrack>( m_dbConnection, req, m_id );
}
bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
......@@ -190,12 +188,12 @@ bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
return SqliteTools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
bool File::audioTracks( std::vector<AudioTrackPtr>& tracks )
std::vector<AudioTrackPtr> File::audioTracks()
{
static const std::string req = "SELECT t.* FROM " + policy::AudioTrackTable::Name +
" t LEFT JOIN AudioTrackFileRelation atfr ON atfr.id_track = t.id_track"
" WHERE atfr.id_file = ?";
return SqliteTools::fetchAll<AudioTrack>( m_dbConnection, req, tracks, m_id );
return SqliteTools::fetchAll<AudioTrack, IAudioTrack>( m_dbConnection, req, m_id );
}
bool File::isStandAlone()
......
......@@ -60,9 +60,9 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual bool setMovie( MoviePtr movie );
virtual bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps );
virtual bool videoTracks( std::vector<VideoTrackPtr>& tracks );
virtual std::vector<VideoTrackPtr> videoTracks();
virtual bool addAudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
virtual bool audioTracks( std::vector<AudioTrackPtr>& tracks );
virtual std::vector<AudioTrackPtr> audioTracks();
virtual bool isStandAlone() override;
virtual bool isReady() const;
......
......@@ -56,7 +56,5 @@ std::vector<FilePtr> Folder::files()
{
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name +
" WHERE f.id_folder = ?";
auto res = std::vector<FilePtr>{};
SqliteTools::fetchAll<File>( m_dbConection, req, res, m_id );
return res;
return SqliteTools::fetchAll<File, IFile>( m_dbConection, req, m_id );
}
......@@ -33,12 +33,12 @@ const std::string& Label::name()
return m_name;
}
bool Label::files( std::vector<FilePtr>& files )
std::vector<FilePtr> Label::files()
{
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
return SqliteTools::fetchAll<File>( m_dbConnection, req, files, m_id );
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
LabelPtr Label::create(DBConnection dbConnection, const std::string& name )
......
......@@ -39,7 +39,7 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol
public:
virtual unsigned int id() const;
virtual const std::string& name();
virtual bool files( std::vector<FilePtr>& files );
virtual std::vector<FilePtr> files();
static LabelPtr create( DBConnection dbConnection, const std::string& name );
static bool createTable( DBConnection dbConnection );
......
......@@ -60,9 +60,9 @@ bool MediaLibrary::initialize(const std::string& dbPath)
}
bool MediaLibrary::files( std::vector<FilePtr>& res )
std::vector<FilePtr> MediaLibrary::files()
{
return File::fetchAll( m_dbConnection, res );
return File::fetchAll( m_dbConnection );
}
FilePtr MediaLibrary::file( const std::string& path )
......
......@@ -14,7 +14,7 @@ class MediaLibrary : public IMediaLibrary
~MediaLibrary();
virtual bool initialize( const std::string& dbPath );
virtual bool files( std::vector<FilePtr>& res );
virtual std::vector<FilePtr> files();
virtual FilePtr file( const std::string& path );
virtual FilePtr addFile( const std::string& path );
virtual FolderPtr addFolder( const std::string& path ) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment