2008-12-10 19:04:02 +01:00
|
|
|
/*
|
2008-12-13 17:58:41 +01:00
|
|
|
parent-track-.cpp - Implementation of the ParentTrack class
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
2008-12-13 17:58:41 +01:00
|
|
|
#include "parent-track.hpp"
|
2008-12-30 22:50:18 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2008-12-10 19:04:02 +01:00
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
using std::shared_ptr;
|
2009-01-24 13:50:49 +01:00
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
namespace gui {
|
|
|
|
|
namespace model {
|
|
|
|
|
|
2008-12-13 17:58:41 +01:00
|
|
|
ParentTrack::ParentTrack()
|
|
|
|
|
{
|
|
|
|
|
}
|
2008-12-10 19:04:02 +01:00
|
|
|
|
2011-10-22 02:49:30 +02:00
|
|
|
const std::list<shared_ptr<Track> >&
|
2008-12-13 17:58:41 +01:00
|
|
|
ParentTrack::get_child_tracks() const
|
2008-12-10 19:04:02 +01:00
|
|
|
{
|
2009-01-24 13:18:12 +01:00
|
|
|
return tracks.get_list();
|
2008-12-10 19:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-22 02:49:30 +02:00
|
|
|
lumiera::observable_list<shared_ptr<Track> >&
|
2008-12-13 17:58:41 +01:00
|
|
|
ParentTrack::get_child_track_list()
|
2008-12-10 19:04:02 +01:00
|
|
|
{
|
2008-12-13 17:58:41 +01:00
|
|
|
return tracks;
|
2008-12-10 19:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-20 22:39:33 +01:00
|
|
|
bool
|
|
|
|
|
ParentTrack::can_host_children() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-30 22:50:18 +01:00
|
|
|
bool
|
2009-01-24 13:59:56 +01:00
|
|
|
ParentTrack::remove_descendant_track(
|
2011-10-22 02:49:30 +02:00
|
|
|
const shared_ptr<Track> track)
|
2008-12-30 22:50:18 +01:00
|
|
|
{
|
|
|
|
|
REQUIRE(track);
|
|
|
|
|
|
2011-10-22 02:49:30 +02:00
|
|
|
shared_ptr<ParentTrack> parent =
|
2009-01-24 13:59:56 +01:00
|
|
|
find_descendant_track_parent(track);
|
|
|
|
|
if(parent)
|
2008-12-30 22:50:18 +01:00
|
|
|
{
|
2009-01-24 13:59:56 +01:00
|
|
|
parent->tracks.remove(track);
|
|
|
|
|
return true;
|
2008-12-30 22:50:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-22 02:49:30 +02:00
|
|
|
shared_ptr<ParentTrack>
|
|
|
|
|
ParentTrack::find_descendant_track_parent(shared_ptr<Track> child)
|
2009-01-24 13:50:49 +01:00
|
|
|
{
|
2011-10-22 02:49:30 +02:00
|
|
|
using namespace boost;
|
2011-10-21 16:14:32 +02:00
|
|
|
|
2009-01-24 13:50:49 +01:00
|
|
|
REQUIRE(child != NULL);
|
2014-04-03 22:42:48 +02:00
|
|
|
BOOST_FOREACH(std::shared_ptr<Track> track, tracks)
|
2009-01-24 13:50:49 +01:00
|
|
|
{
|
|
|
|
|
if(track == child)
|
|
|
|
|
return shared_from_this();
|
2011-10-21 09:56:10 +02:00
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
std::shared_ptr<ParentTrack> result =
|
2009-01-24 13:50:49 +01:00
|
|
|
track->find_descendant_track_parent(child);
|
|
|
|
|
if(result)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
return std::shared_ptr<ParentTrack>();
|
2011-10-21 09:56:10 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-10 19:04:02 +01:00
|
|
|
} // namespace model
|
|
|
|
|
} // namespace gui
|