Replaced Sequence* with boost::shared_ptr<Sequence>

This commit is contained in:
Joel Holdsworth 2008-12-05 20:17:56 +00:00
parent e3e639a2db
commit da3d14da72
9 changed files with 33 additions and 25 deletions

View file

@ -32,6 +32,7 @@
#include <nobug.h>
#include <vector>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
extern "C" {
#include <gavl/gavltime.h>

View file

@ -25,6 +25,9 @@
#include "project.hpp"
#include "sequence.hpp"
using namespace std;
using namespace boost;
namespace gui {
namespace model {
@ -37,11 +40,10 @@ Project::Project()
Project::~Project()
{
BOOST_FOREACH( Sequence* const sequence, sequences )
delete sequence;
}
const std::list<Sequence*>&
const std::list< shared_ptr<Sequence> >&
Project::get_sequences()
{
return sequences;
@ -50,7 +52,7 @@ Project::get_sequences()
void
Project::add_new_sequence(Glib::ustring name)
{
Sequence* const sequence = new Sequence();
shared_ptr<Sequence> sequence(new Sequence());
sequence->set_name(name);
sequences.push_back(sequence);
sequenceListChangedSignal.emit();

View file

@ -39,7 +39,7 @@ public:
~Project();
const std::list<Sequence*>& get_sequences();
const std::list< boost::shared_ptr<Sequence> >& get_sequences();
void add_new_sequence(Glib::ustring name);
@ -48,7 +48,7 @@ public:
private:
std::list<Sequence*> sequences;
std::list< boost::shared_ptr<Sequence> > sequences;
sigc::signal<void> sequenceListChangedSignal;
};

View file

@ -34,6 +34,7 @@ extern "C" {
using namespace Gtk;
using namespace sigc;
using namespace std;
using namespace boost;
using namespace gui::widgets;
using namespace gui::model;
@ -114,7 +115,7 @@ TimelinePanel::TimelinePanel(model::Project *const owner_project) :
TimelinePanel::~TimelinePanel()
{
// Free allocated widgets
pair<model::Sequence*, TimelineWidget*> pair;
pair<const model::Sequence*, TimelineWidget*> pair;
BOOST_FOREACH( pair, notebook_pages )
delete pair.second;
}
@ -220,13 +221,15 @@ TimelinePanel::on_sequence_list_changed()
void
TimelinePanel::update_notebook()
{
std::map<Sequence*, TimelineWidget*> old_pages(notebook_pages);
std::map<const model::Sequence*, TimelineWidget*>
old_pages(notebook_pages);
notebook_pages.clear();
BOOST_FOREACH( Sequence* const sequence, project->get_sequences() )
BOOST_FOREACH( boost::shared_ptr< model::Sequence > sequence,
project->get_sequences() )
{
std::map<Sequence*, TimelineWidget*>::iterator iterator =
old_pages.find(sequence);
std::map<const model::Sequence*, TimelineWidget*>::iterator
iterator = old_pages.find(sequence.get());
if(iterator != old_pages.end())
{
// This sequence has not been changed
@ -238,14 +241,14 @@ TimelinePanel::update_notebook()
{
// This is a new sequence, add it in
TimelineWidget * const widget = new TimelineWidget(sequence);
notebook_pages[sequence] = widget;
notebook_pages[sequence.get()] = widget;
notebook.append_page(*widget, sequence->get_name());
notebook.set_tab_reorderable(*widget);
}
}
// Free widgets which have been removed
pair<model::Sequence*, TimelineWidget*> pair;
pair<const model::Sequence*, TimelineWidget*> pair;
BOOST_FOREACH( pair, old_pages )
delete pair.second;

View file

@ -106,7 +106,8 @@ private:
// Body Widgets
Gtk::Notebook notebook;
std::map<model::Sequence*, TimelineWidget*> notebook_pages;
std::map< const model::Sequence*, TimelineWidget*>
notebook_pages;
// Toolbar Widgets

View file

@ -37,7 +37,8 @@ const int TimelineWidget::HeaderWidth = 150;
const double TimelineWidget::ZoomIncrement = 1.25;
const int64_t TimelineWidget::MaxScale = 30000000;
TimelineWidget::TimelineWidget(model::Sequence* const source_sequence) :
TimelineWidget::TimelineWidget(
boost::shared_ptr<model::Sequence> source_sequence) :
Table(2, 2),
sequence(source_sequence),
viewWindow(this, 0, 1),
@ -53,7 +54,7 @@ TimelineWidget::TimelineWidget(model::Sequence* const source_sequence) :
horizontalScroll(horizontalAdjustment),
verticalScroll(verticalAdjustment)
{
REQUIRE(sequence != NULL);
REQUIRE(sequence);
body = new TimelineBody(this);
ENSURE(body != NULL);
@ -276,7 +277,7 @@ TimelineWidget::on_view_window_changed()
void
TimelineWidget::update_tracks()
{
REQUIRE(sequence != NULL);
REQUIRE(sequence);
// Create timeline tracks from all the model tracks
create_timeline_tracks();
@ -297,7 +298,7 @@ TimelineWidget::update_tracks()
void
TimelineWidget::create_timeline_tracks()
{
REQUIRE(sequence != NULL);
REQUIRE(sequence);
BOOST_FOREACH(model::Track* child, sequence->get_tracks())
create_timeline_tracks_from_branch(child);
@ -345,7 +346,7 @@ TimelineWidget::create_timeline_track_from_model_track(
timeline::Track*
TimelineWidget::lookup_timeline_track(model::Track *model_track)
{
ASSERT(sequence != NULL);
REQUIRE(sequence);
std::map<model::Track*, timeline::Track*>::const_iterator iterator =
trackMap.find(model_track);
if(iterator == trackMap.end())

View file

@ -57,7 +57,7 @@ public:
/**
* Constructor
*/
TimelineWidget(model::Sequence *source_sequence);
TimelineWidget(boost::shared_ptr<model::Sequence> source_sequence);
/**
* Destructor
@ -211,7 +211,7 @@ private:
protected:
// Model Data
model::Sequence* const sequence;
const boost::shared_ptr<model::Sequence> sequence;
std::map<model::Track*, timeline::Track*> trackMap;
// View State

View file

@ -268,7 +268,7 @@ TimelineBody::draw_tracks(Cairo::RefPtr<Cairo::Context> cr)
{
REQUIRE(cr);
REQUIRE(timelineWidget != NULL);
REQUIRE(timelineWidget->sequence != NULL);
REQUIRE(timelineWidget->sequence);
// Prepare
const Allocation allocation = get_allocation();
@ -424,7 +424,7 @@ timeline::Track*
TimelineBody::track_from_point(const int y) const
{
REQUIRE(timelineWidget != NULL);
REQUIRE(timelineWidget->sequence != NULL);
REQUIRE(timelineWidget->sequence);
int offset = -get_vertical_offset();

View file

@ -492,7 +492,7 @@ const std::list<model::Track*>&
TimelineHeaderContainer::get_tracks() const
{
REQUIRE(timelineWidget != NULL);
REQUIRE(timelineWidget->sequence != NULL);
REQUIRE(timelineWidget->sequence);
return timelineWidget->sequence->get_tracks();
}