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

parser: Item: Rework access to subitems

This allows a reference to be returned (without wrapping all subitems in
a unique_ptr or a reference_wrapper, or a manually heap allocated Item*)
parent 68b91cb0
...@@ -91,7 +91,7 @@ int MetadataParser::toInt( parser::Task::Item& item, parser::Task::Item::Metadat ...@@ -91,7 +91,7 @@ int MetadataParser::toInt( parser::Task::Item& item, parser::Task::Item::Metadat
parser::Task::Status MetadataParser::run( parser::Task::Item& item ) parser::Task::Status MetadataParser::run( parser::Task::Item& item )
{ {
bool alreadyInParser = false; bool alreadyInParser = false;
int nbSubitem = item.subItems().size(); int nbSubitem = item.nbSubItems();
// Assume that file containing subitem(s) is a Playlist // Assume that file containing subitem(s) is a Playlist
if ( nbSubitem > 0 ) if ( nbSubitem > 0 )
{ {
...@@ -275,9 +275,8 @@ bool MetadataParser::addPlaylistMedias( parser::Task::Item& item ) const ...@@ -275,9 +275,8 @@ bool MetadataParser::addPlaylistMedias( parser::Task::Item& item ) const
// be recreated if need be, and appropriate entries in PlaylistMediaRelation // be recreated if need be, and appropriate entries in PlaylistMediaRelation
// table will be recreated to link things together. // table will be recreated to link things together.
auto subitems = item.subItems(); for ( auto i = 0u; i < item.nbSubItems(); ++i ) // FIXME: Interrupt loop if paused
for ( const auto& subItem : subitems ) // FIXME: Interrupt loop if paused addPlaylistElement( item, playlistPtr, item.subItem( i ) );
addPlaylistElement( item, playlistPtr, subItem );
return true; return true;
} }
......
...@@ -188,9 +188,14 @@ void Task::Item::setMrl( std::string mrl ) ...@@ -188,9 +188,14 @@ void Task::Item::setMrl( std::string mrl )
m_mrl = std::move( mrl ); m_mrl = std::move( mrl );
} }
const std::vector<Task::Item>& Task::Item::subItems() const size_t Task::Item::nbSubItems() const
{ {
return m_subItems; return m_subItems.size();
}
const Task::Item& Task::Item::subItem( unsigned int index ) const
{
return m_subItems[index];
} }
Task::Item& Task::Item::createSubItem( std::string mrl, unsigned int playlistIndex ) Task::Item& Task::Item::createSubItem( std::string mrl, unsigned int playlistIndex )
......
...@@ -182,7 +182,8 @@ public: ...@@ -182,7 +182,8 @@ public:
const std::string& mrl() const; const std::string& mrl() const;
void setMrl( std::string mrl ); void setMrl( std::string mrl );
const std::vector<Item>& subItems() const; size_t nbSubItems() const;
const Item& subItem( unsigned int index ) const;
Item& createSubItem( std::string mrl, unsigned int playlistIndex ); Item& createSubItem( std::string mrl, unsigned int playlistIndex );
int64_t duration() const; int64_t duration() const;
......
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