Allow for library symbols to derived from derived symbols.

This change allows for infinite inheritance depth so internally there is
no limit to deriving library symbols from other derived symbols.  Please
note that the Flatten() method now recurses until a symbol with no parent
is found.  The user interface is not hooked up at this time.
This commit is contained in:
Wayne Stambaugh 2023-06-13 15:52:42 -04:00
parent fe1b1becef
commit 5a7f95e8da
2 changed files with 48 additions and 8 deletions

View File

@ -597,7 +597,10 @@ std::unique_ptr< LIB_SYMBOL > LIB_SYMBOL::Flatten() const
wxString::Format( "Parent of derived symbol '%s' undefined", m_name ) );
// Copy the parent.
retv = std::make_unique<LIB_SYMBOL>( *parent.get() );
if( parent->IsAlias() )
retv = parent->Flatten();
else
retv = std::make_unique<LIB_SYMBOL>( *parent.get() );
retv->m_name = m_name;
retv->SetLibId( m_libId );

View File

@ -590,17 +590,54 @@ BOOST_AUTO_TEST_CASE( Inheritance )
{
std::unique_ptr<LIB_SYMBOL> parent = std::make_unique<LIB_SYMBOL>( "parent" );
BOOST_CHECK( parent->IsRoot() );
std::unique_ptr<LIB_SYMBOL> child1 = std::make_unique<LIB_SYMBOL>( "child1", parent.get() );
BOOST_CHECK( child1->IsAlias() );
LIB_SYMBOL_SPTR parentRef = child1->GetParent().lock();
std::unique_ptr<LIB_SYMBOL> ref = std::make_unique<LIB_SYMBOL>( *parent );
std::unique_ptr<LIB_SYMBOL> child = std::make_unique<LIB_SYMBOL>( "child", parent.get() );
BOOST_CHECK( child->IsAlias() );
std::unique_ptr<LIB_SYMBOL> grandChild = std::make_unique<LIB_SYMBOL>( "grandchild",
child.get() );
BOOST_CHECK( grandChild->IsAlias() );
LIB_SYMBOL_SPTR parentRef = child->GetParent().lock();
BOOST_CHECK( parentRef );
BOOST_CHECK( parentRef == parent->SharedPtr() );
BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 3 );
BOOST_CHECK_EQUAL( child1->GetUnitCount(), 1 );
LIB_SYMBOL_SPTR childRef = grandChild->GetParent().lock();
BOOST_CHECK( childRef );
BOOST_CHECK( childRef == child->SharedPtr() );
BOOST_CHECK_EQUAL( child->SharedPtr().use_count(), 3 );
BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
parent->SetUnitCount( 4 );
BOOST_CHECK_EQUAL( child1->GetUnitCount(), 4 );
child1->SetParent();
BOOST_CHECK_EQUAL( child1->GetUnitCount(), 1 );
BOOST_CHECK_EQUAL( child->GetUnitCount(), 4 );
parent->SetUnitCount( 1 );
LIB_FIELD* field = new LIB_FIELD( MANDATORY_FIELDS, "Manufacturer" );
field->SetText( "Manufacturer" );
child->AddField( field );
ref->SetName( "child" );
field = new LIB_FIELD( MANDATORY_FIELDS, "Manufacturer" );
field->SetText( "Manufacturer" );
ref->AddField( field );
BOOST_CHECK( *ref == *child->Flatten() );
ref->SetName( "grandchild" );
field = new LIB_FIELD( MANDATORY_FIELDS + 1, "MPN" );
field->SetText( "123456" );
ref->AddField( field );
field = new LIB_FIELD( MANDATORY_FIELDS + 1, "MPN" );
field->SetText( "123456" );
grandChild->AddField( field );
BOOST_CHECK( *ref == *grandChild->Flatten() );
child->SetParent();
BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
parentRef.reset();
BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 2 );
}