Skip to content

Commit

Permalink
pass shared_ptr value by ref since its only used
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 committed May 13, 2024
1 parent c28f2d1 commit 4e4100e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions OdbDesignLib/ProductModel/PinConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Odb::Lib::ProductModel
//}

PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin)
: PinConnection(pComponent, pPin, MakeName(pComponent, pPin))
: PinConnection(pComponent, pPin, MakeName(*pComponent, *pPin))
{
}

Expand All @@ -24,10 +24,11 @@ namespace Odb::Lib::ProductModel
{
}

std::string PinConnection::MakeName(std::shared_ptr<Odb::Lib::ProductModel::Component>& pComponent, std::shared_ptr<Odb::Lib::ProductModel::Pin>& pPin)
std::string PinConnection::MakeName(const Component& component, const Pin& pin)
{
if (pComponent == nullptr || pPin == nullptr) return "Pin::MakeName() FAILED";
return pComponent->GetRefDes() + "-" + pPin->GetName();
//if (pComponent == nullptr || pPin == nullptr) return "Pin::MakeName() FAILED";
//return pComponent->GetRefDes() + "-" + pPin->GetName();
return component.GetRefDes() + "-" + pin.GetName();
}

std::shared_ptr<Pin> PinConnection::GetPin() const
Expand All @@ -40,16 +41,16 @@ namespace Odb::Lib::ProductModel
return m_pComponent;
}

std::unique_ptr<Odb::Lib::Protobuf::ProductModel::PinConnection> PinConnection::to_protobuf() const
std::unique_ptr<Protobuf::ProductModel::PinConnection> PinConnection::to_protobuf() const
{
auto pPinConnectionMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::PinConnection>();
auto pPinConnectionMsg = std::make_unique<Protobuf::ProductModel::PinConnection>();
pPinConnectionMsg->set_name(m_name);
pPinConnectionMsg->mutable_component()->CopyFrom(*m_pComponent->to_protobuf());
pPinConnectionMsg->mutable_pin()->CopyFrom(*m_pPin->to_protobuf());
return pPinConnectionMsg;
}

void PinConnection::from_protobuf(const Odb::Lib::Protobuf::ProductModel::PinConnection& message)
void PinConnection::from_protobuf(const Protobuf::ProductModel::PinConnection& message)
{
m_name = message.name();
m_pComponent = std::make_shared<Component>();
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignLib/ProductModel/PinConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Odb::Lib::ProductModel
std::shared_ptr<Pin> GetPin() const;
std::shared_ptr<Component> GetComponent() const;

std::string MakeName(std::shared_ptr<Odb::Lib::ProductModel::Component>& pComponent, std::shared_ptr<Odb::Lib::ProductModel::Pin>& pPin);
static std::string MakeName(const Component& component, const Pin& pin);

// Inherited via IProtoBuffable
std::unique_ptr<Odb::Lib::Protobuf::ProductModel::PinConnection> to_protobuf() const override;
Expand Down

0 comments on commit 4e4100e

Please sign in to comment.