Line data Source code
1 : #include "Net.h"
2 : #include <memory>
3 : #include "Component.h"
4 : #include "Pin.h"
5 : #include "net.pb.h"
6 : #include <string>
7 : #include "PinConnection.h"
8 : #include "../Text/Utf8Sanitizer.h"
9 :
10 :
11 : namespace Odb::Lib::ProductModel
12 : {
13 41810 : Net::Net(const std::string& name, unsigned int index)
14 41810 : : m_name(name)
15 41810 : , m_index(index)
16 : {
17 41810 : }
18 :
19 41810 : Net::~Net()
20 : {
21 41810 : m_pinConnections.clear();
22 41810 : }
23 :
24 94556 : std::string Net::GetName() const
25 : {
26 94556 : return m_name;
27 : }
28 :
29 56502 : PinConnection::Vector& Net::GetPinConnections()
30 : {
31 56502 : return m_pinConnections;
32 : }
33 :
34 0 : const PinConnection::Vector& Net::GetPinConnections() const
35 : {
36 0 : return m_pinConnections;
37 : }
38 :
39 345614 : unsigned int Net::GetIndex() const
40 : {
41 345614 : return m_index;
42 : }
43 :
44 157214 : bool Net::AddPinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, unsigned int subnetNumber)
45 : {
46 157214 : m_pinConnections.push_back(std::make_shared<PinConnection>(pComponent, pPin, subnetNumber));
47 157214 : return true;
48 : }
49 :
50 14300 : std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Net> Odb::Lib::ProductModel::Net::to_protobuf() const
51 : {
52 14300 : auto pNetMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Net>();
53 28600 : pNetMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
54 14300 : pNetMsg->set_index(m_index);
55 74686 : for (auto& pPinConnection : m_pinConnections)
56 : {
57 60386 : pNetMsg->add_pinconnections()->CopyFrom(*pPinConnection->to_protobuf());
58 : }
59 14300 : return pNetMsg;
60 0 : }
61 :
62 3930 : void Odb::Lib::ProductModel::Net::from_protobuf(const Odb::Lib::Protobuf::ProductModel::Net& message)
63 : {
64 3930 : m_name = message.name();
65 3930 : m_index = message.index();
66 20068 : for (auto& pinConnectionMsg : message.pinconnections())
67 : {
68 16138 : auto pPinConnection = std::make_shared<PinConnection>(nullptr, nullptr, "");
69 16138 : pPinConnection->from_protobuf(pinConnectionMsg);
70 16138 : m_pinConnections.push_back(pPinConnection);
71 16138 : }
72 3930 : }
73 : }
|