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

Add a file getter in IMediaLibrary

parent 4c1ffc35
......@@ -12,6 +12,7 @@ class IMediaLibrary
virtual ~IMediaLibrary() {}
virtual bool initialize( const std::string& dbPath ) = 0;
virtual IFile* addFile( const std::string& path ) = 0;
virtual IFile* file( const std::string& path ) = 0;
virtual const std::vector<IFile*>& files() = 0;
};
......
......@@ -42,6 +42,27 @@ const std::vector<IFile*>& MediaLibrary::files()
return *m_files;
}
IFile*MediaLibrary::file( const std::string& path )
{
if ( m_files == NULL )
{
// FIXME: This is probably ineficient.
// Consider loading the file itself from the DB & eventually store it in a tmp
// vector? Or implement caching globally for each class
files();
}
std::vector<IFile*>::iterator it = m_files->begin();
std::vector<IFile*>::iterator ite = m_files->end();
while ( it != ite )
{
if ( (*it)->mrl() == path )
return *it;
++it;
}
return NULL;
}
IFile* MediaLibrary::addFile( const std::string& path )
{
File* f = new File( path );
......
......@@ -11,6 +11,7 @@ class MediaLibrary : public IMediaLibrary
MediaLibrary();
virtual bool initialize( const std::string& dbPath );
virtual const std::vector<IFile*>& files();
virtual IFile* file( const std::string& path );
virtual IFile* addFile( const std::string& path );
private:
......
......@@ -46,6 +46,13 @@ TEST_F( MLTest, InsertFile )
delete f;
}
TEST_F( MLTest, FetchFile )
{
IFile* f = ml->addFile( "/dev/null" );
IFile* f2 = ml->file( "/dev/null" );
ASSERT_EQ( f->mrl(), f2->mrl() );
}
TEST_F( MLTest, AddLabel )
{
IFile* f = ml->addFile( "/dev/null" );
......
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