|
|
|
@ -23,6 +23,7 @@ |
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
@ -84,52 +85,25 @@ NETCLASS::~NETCLASS() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NETCLASSES::NETCLASSES() : |
|
|
|
m_Default( NETCLASS::Default ) |
|
|
|
NETCLASSES::NETCLASSES() |
|
|
|
{ |
|
|
|
m_Default = boost::make_shared<NETCLASS>( NETCLASS::Default ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NETCLASSES::~NETCLASSES() |
|
|
|
{ |
|
|
|
Clear(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NETCLASSES::Clear() |
|
|
|
{ |
|
|
|
// Although std::map<> will destroy the items that it contains, in this
|
|
|
|
// case we have NETCLASS* (pointers) and "destroying" a pointer does not
|
|
|
|
// delete the object that the pointer points to.
|
|
|
|
|
|
|
|
// this NETCLASSES is owner of its NETCLASS pointers,
|
|
|
|
// so delete NETCLASSes pointed to by them.
|
|
|
|
for( iterator i = begin(); i!=end(); ) |
|
|
|
{ |
|
|
|
// http://www.sgi.com/tech/stl/Map.html says:
|
|
|
|
// "Erasing an element from a map also does not invalidate any iterators,
|
|
|
|
// except, of course, for iterators that actually point to the element that
|
|
|
|
// is being erased."
|
|
|
|
|
|
|
|
iterator e = i++; // copy, then advance.
|
|
|
|
|
|
|
|
delete e->second; // delete the NETCLASS, which 'second' points to.
|
|
|
|
|
|
|
|
m_NetClasses.erase( e ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool NETCLASSES::Add( NETCLASS* aNetClass ) |
|
|
|
bool NETCLASSES::Add( NETCLASSPTR aNetClass ) |
|
|
|
{ |
|
|
|
const wxString& name = aNetClass->GetName(); |
|
|
|
|
|
|
|
if( name == NETCLASS::Default ) |
|
|
|
{ |
|
|
|
// invoke operator=(), which is currently generated by compiler.
|
|
|
|
m_Default = *aNetClass; |
|
|
|
|
|
|
|
delete aNetClass; // we own aNetClass, must delete it since we copied it.
|
|
|
|
m_Default = aNetClass; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
@ -139,6 +113,7 @@ bool NETCLASSES::Add( NETCLASS* aNetClass ) |
|
|
|
{ |
|
|
|
// name not found, take ownership
|
|
|
|
m_NetClasses[name] = aNetClass; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
@ -150,30 +125,30 @@ bool NETCLASSES::Add( NETCLASS* aNetClass ) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NETCLASS* NETCLASSES::Remove( const wxString& aNetName ) |
|
|
|
NETCLASSPTR NETCLASSES::Remove( const wxString& aNetName ) |
|
|
|
{ |
|
|
|
NETCLASSMAP::iterator found = m_NetClasses.find( aNetName ); |
|
|
|
|
|
|
|
if( found != m_NetClasses.end() ) |
|
|
|
{ |
|
|
|
NETCLASS* netclass = found->second; |
|
|
|
boost::shared_ptr<NETCLASS> netclass = found->second; |
|
|
|
m_NetClasses.erase( found ); |
|
|
|
return netclass; |
|
|
|
} |
|
|
|
|
|
|
|
return NULL; |
|
|
|
return NETCLASSPTR(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NETCLASS* NETCLASSES::Find( const wxString& aName ) const |
|
|
|
NETCLASSPTR NETCLASSES::Find( const wxString& aName ) const |
|
|
|
{ |
|
|
|
if( aName == NETCLASS::Default ) |
|
|
|
return (NETCLASS*) &m_Default; |
|
|
|
return m_Default; |
|
|
|
|
|
|
|
NETCLASSMAP::const_iterator found = m_NetClasses.find( aName ); |
|
|
|
|
|
|
|
if( found == m_NetClasses.end() ) |
|
|
|
return NULL; |
|
|
|
return NETCLASSPTR(); |
|
|
|
else |
|
|
|
return found->second; |
|
|
|
} |
|
|
|
@ -197,9 +172,9 @@ void BOARD::SynchronizeNetsAndNetClasses() |
|
|
|
// and therefore bogus netclass memberships will be deleted in logic below this loop.
|
|
|
|
for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz ) |
|
|
|
{ |
|
|
|
NETCLASS* netclass = clazz->second; |
|
|
|
NETCLASSPTR netclass = clazz->second; |
|
|
|
|
|
|
|
for( NETCLASS::iterator member = netclass->begin(); member != netclass->end(); ++member ) |
|
|
|
for( NETCLASS::const_iterator member = netclass->begin(); member != netclass->end(); ++member ) |
|
|
|
{ |
|
|
|
const wxString& netname = *member; |
|
|
|
|
|
|
|
@ -222,7 +197,7 @@ void BOARD::SynchronizeNetsAndNetClasses() |
|
|
|
|
|
|
|
for( NETCLASSES::iterator clazz = netClasses.begin(); clazz != netClasses.end(); ++clazz ) |
|
|
|
{ |
|
|
|
NETCLASS* netclass = clazz->second; |
|
|
|
NETCLASSPTR netclass = clazz->second; |
|
|
|
|
|
|
|
netclass->Clear(); |
|
|
|
} |
|
|
|
@ -236,7 +211,7 @@ void BOARD::SynchronizeNetsAndNetClasses() |
|
|
|
|
|
|
|
// because of the std:map<> this should be fast, and because of
|
|
|
|
// prior logic, netclass should not be NULL.
|
|
|
|
NETCLASS* netclass = netClasses.Find( classname ); |
|
|
|
NETCLASSPTR netclass = netClasses.Find( classname ); |
|
|
|
|
|
|
|
wxASSERT( netclass ); |
|
|
|
|
|
|
|
|