use unique_ptr to document ownership (PNS::ROUTER)

This commit is contained in:
decimad 2016-08-29 19:48:16 +02:00 committed by Maciej Suminski
parent 6c749e0ba8
commit 2faca77adf
2 changed files with 28 additions and 40 deletions

View File

@ -70,18 +70,14 @@ ROUTER::ROUTER()
m_state = IDLE; m_state = IDLE;
m_world = NULL;
m_placer = NULL;
m_dragger = NULL;
m_mode = PNS_MODE_ROUTE_SINGLE; m_mode = PNS_MODE_ROUTE_SINGLE;
// Initialize all other variables: // Initialize all other variables:
m_lastNode = NULL; m_lastNode = nullptr;
m_shove = NULL;
m_iterLimit = 0; m_iterLimit = 0;
m_showInterSteps = false; m_showInterSteps = false;
m_snapshotIter = 0; m_snapshotIter = 0;
m_view = NULL; m_view = nullptr;
m_snappingEnabled = false; m_snappingEnabled = false;
m_violation = false; m_violation = false;
} }
@ -96,15 +92,15 @@ ROUTER* ROUTER::GetInstance()
ROUTER::~ROUTER() ROUTER::~ROUTER()
{ {
ClearWorld(); ClearWorld();
theRouter = NULL; theRouter = nullptr;
} }
void ROUTER::SyncWorld( ) void ROUTER::SyncWorld( )
{ {
ClearWorld(); ClearWorld();
m_world = new NODE; m_world = std::unique_ptr< NODE >( new NODE );
m_iface->SyncWorld( m_world ); m_iface->SyncWorld( m_world.get() );
} }
@ -113,15 +109,10 @@ void ROUTER::ClearWorld()
if( m_world ) if( m_world )
{ {
m_world->KillChildren(); m_world->KillChildren();
delete m_world; m_world.reset();
} }
if( m_placer ) m_placer.reset();
delete m_placer;
m_world = NULL;
m_placer = NULL;
} }
@ -146,15 +137,15 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM* aStartItem )
if( !aStartItem || aStartItem->OfKind( ITEM::SOLID_T ) ) if( !aStartItem || aStartItem->OfKind( ITEM::SOLID_T ) )
return false; return false;
m_dragger = new DRAGGER( this ); m_dragger.reset( new DRAGGER( this ) );
m_dragger->SetWorld( m_world ); m_dragger->SetWorld( m_world.get() );
m_dragger->SetDebugDecorator ( m_iface->GetDebugDecorator () ); m_dragger->SetDebugDecorator ( m_iface->GetDebugDecorator () );
if( m_dragger->Start ( aP, aStartItem ) ) if( m_dragger->Start ( aP, aStartItem ) )
m_state = DRAG_SEGMENT; m_state = DRAG_SEGMENT;
else else
{ {
delete m_dragger; m_dragger.reset();
m_state = IDLE; m_state = IDLE;
return false; return false;
} }
@ -167,19 +158,19 @@ bool ROUTER::StartRouting( const VECTOR2I& aP, ITEM* aStartItem, int aLayer )
switch( m_mode ) switch( m_mode )
{ {
case PNS_MODE_ROUTE_SINGLE: case PNS_MODE_ROUTE_SINGLE:
m_placer = new LINE_PLACER( this ); m_placer.reset( new LINE_PLACER( this ) );
break; break;
case PNS_MODE_ROUTE_DIFF_PAIR: case PNS_MODE_ROUTE_DIFF_PAIR:
m_placer = new DIFF_PAIR_PLACER( this ); m_placer.reset( new DIFF_PAIR_PLACER( this ) );
break; break;
case PNS_MODE_TUNE_SINGLE: case PNS_MODE_TUNE_SINGLE:
m_placer = new MEANDER_PLACER( this ); m_placer.reset( new MEANDER_PLACER( this ) );
break; break;
case PNS_MODE_TUNE_DIFF_PAIR: case PNS_MODE_TUNE_DIFF_PAIR:
m_placer = new DP_MEANDER_PLACER( this ); m_placer.reset( new DP_MEANDER_PLACER( this ) );
break; break;
case PNS_MODE_TUNE_DIFF_PAIR_SKEW: case PNS_MODE_TUNE_DIFF_PAIR_SKEW:
m_placer = new MEANDER_SKEW_PLACER( this ); m_placer.reset( new MEANDER_SKEW_PLACER( this ) );
break; break;
default: default:
@ -387,14 +378,8 @@ void ROUTER::StopRouting()
if( !RoutingInProgress() ) if( !RoutingInProgress() )
return; return;
if( m_placer ) m_placer.reset();
delete m_placer; m_dragger.reset();
if( m_dragger )
delete m_dragger;
m_placer = NULL;
m_dragger = NULL;
m_iface->EraseView(); m_iface->EraseView();
@ -455,7 +440,7 @@ int ROUTER::GetCurrentLayer() const
void ROUTER::DumpLog() void ROUTER::DumpLog()
{ {
LOGGER* logger = NULL; LOGGER* logger = nullptr;
switch( m_state ) switch( m_state )
{ {

View File

@ -24,6 +24,7 @@
#include <list> #include <list>
#include <memory>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/unordered_set.hpp> #include <boost/unordered_set.hpp>
@ -132,7 +133,7 @@ public:
NODE* GetWorld() const NODE* GetWorld() const
{ {
return m_world; return m_world.get();
} }
void FlipPosture(); void FlipPosture();
@ -214,7 +215,7 @@ public:
void SetFailureReason ( const wxString& aReason ) { m_failureReason = aReason; } void SetFailureReason ( const wxString& aReason ) { m_failureReason = aReason; }
const wxString& FailureReason() const { return m_failureReason; } const wxString& FailureReason() const { return m_failureReason; }
PLACEMENT_ALGO* Placer() { return m_placer; } PLACEMENT_ALGO* Placer() { return m_placer.get(); }
ROUTER_IFACE* GetInterface() const ROUTER_IFACE* GetInterface() const
{ {
@ -250,11 +251,13 @@ private:
VECTOR2I m_currentEnd; VECTOR2I m_currentEnd;
RouterState m_state; RouterState m_state;
NODE* m_world; std::unique_ptr< NODE > m_world;
NODE* m_lastNode; NODE* m_lastNode;
PLACEMENT_ALGO * m_placer;
DRAGGER* m_dragger; std::unique_ptr< PLACEMENT_ALGO > m_placer;
SHOVE* m_shove; std::unique_ptr< DRAGGER > m_dragger;
std::unique_ptr< SHOVE > m_shove;
ROUTER_IFACE* m_iface; ROUTER_IFACE* m_iface;
int m_iterLimit; int m_iterLimit;