Wrapped TimelineBody::track in a scoped_ptr

This commit is contained in:
Joel Holdsworth 2009-01-02 16:47:29 +00:00
parent cd94bf9765
commit 1d376e4292
3 changed files with 8 additions and 13 deletions

View file

@ -35,6 +35,7 @@
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include "lib/util.hpp" #include "lib/util.hpp"
extern "C" { extern "C" {

View file

@ -58,42 +58,36 @@ TimelineBody::TimelineBody(TimelineWidget &timeline_widget) :
TimelineBody::~TimelineBody() TimelineBody::~TimelineBody()
{ {
REQUIRE(tool != NULL); WARN_IF(!tool, gui, "An invalid tool pointer is unexpected here");
if(tool != NULL)
delete tool;
} }
ToolType ToolType
TimelineBody::get_tool() const TimelineBody::get_tool() const
{ {
REQUIRE(tool != NULL); REQUIRE(tool);
if(tool != NULL) return tool->get_type();
return tool->get_type();
return gui::widgets::timeline::None;
} }
void void
TimelineBody::set_tool(timeline::ToolType tool_type) TimelineBody::set_tool(timeline::ToolType tool_type)
{ {
// Tidy up old tool // Tidy up old tool
if(tool != NULL) if(tool)
{ {
// Do we need to change tools? // Do we need to change tools?
if(tool->get_type() == tool_type) if(tool->get_type() == tool_type)
return; return;
delete tool;
} }
// Create the new tool // Create the new tool
switch(tool_type) switch(tool_type)
{ {
case timeline::Arrow: case timeline::Arrow:
tool = new ArrowTool(*this); tool.reset(new ArrowTool(*this));
break; break;
case timeline::IBeam: case timeline::IBeam:
tool = new IBeamTool(*this); tool.reset(new IBeamTool(*this));
break; break;
default: default:

View file

@ -160,7 +160,7 @@ private:
Shift Shift
}; };
timeline::Tool *tool; boost::scoped_ptr<timeline::Tool> tool;
double mouseDownX, mouseDownY; double mouseDownX, mouseDownY;
// Scroll State // Scroll State