OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
PinConnection.cpp
Go to the documentation of this file.
1#include "PinConnection.h"
2#include <memory>
3#include "Pin.h"
4#include "Component.h"
5#include <string>
6#include "pinconnection.pb.h"
7#include "../Text/Utf8Sanitizer.h"
8
9
11{
12 //PinConnection::~PinConnection()
13 //{
14 //}
15
16 PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, unsigned int subnetNumber)
17 : PinConnection(pComponent, pPin, MakeName(*pComponent, *pPin), subnetNumber)
18 {
19 }
20
21 PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, const std::string& name, unsigned int subnetNumber)
22 : m_name(name)
23 , m_pComponent(pComponent)
24 , m_pPin(pPin)
25 , m_subnetNumber(subnetNumber)
26 {
27 }
28
29 std::string PinConnection::MakeName(const Component& component, const Pin& pin)
30 {
31 //if (pComponent == nullptr || pPin == nullptr) return "Pin::MakeName() FAILED";
32 //return pComponent->GetRefDes() + "-" + pPin->GetName();
33 return component.GetRefDes() + "-" + pin.GetName();
34 }
35
36 std::shared_ptr<Pin> PinConnection::GetPin() const
37 {
38 return m_pPin;
39 }
40
41 std::shared_ptr<Component> PinConnection::GetComponent() const
42 {
43 return m_pComponent;
44 }
45
46 unsigned int PinConnection::GetSubnetNumber() const
47 {
48 return m_subnetNumber;
49 }
50
51 std::unique_ptr<Protobuf::ProductModel::PinConnection> PinConnection::to_protobuf() const
52 {
53 auto pPinConnectionMsg = std::make_unique<Protobuf::ProductModel::PinConnection>();
54 pPinConnectionMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
55 pPinConnectionMsg->mutable_component()->CopyFrom(*m_pComponent->to_protobuf());
56 pPinConnectionMsg->mutable_pin()->CopyFrom(*m_pPin->to_protobuf());
57 return pPinConnectionMsg;
58 }
59
60 void PinConnection::from_protobuf(const Protobuf::ProductModel::PinConnection& message)
61 {
62 m_name = message.name();
63 m_pComponent = std::make_shared<Component>();
64 m_pComponent->from_protobuf(message.component());
65 m_pPin = std::make_shared<Pin>("", -1);
66 m_pPin->from_protobuf(message.pin());
67 }
68
69} // namespace Odb::Lib::ProductModel
std::string GetRefDes() const
Definition Component.cpp:39
std::shared_ptr< Pin > GetPin() const
static std::string MakeName(const Component &component, const Pin &pin)
std::shared_ptr< Component > GetComponent() const
std::unique_ptr< Odb::Lib::Protobuf::ProductModel::PinConnection > to_protobuf() const override
void from_protobuf(const Odb::Lib::Protobuf::ProductModel::PinConnection &message) override
PinConnection(std::shared_ptr< Component > pComponent, std::shared_ptr< Pin > pPin, unsigned int subnetNumber=0)
std::string GetName() const
Definition Pin.cpp:15
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.