OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
Net.cpp
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
11namespace Odb::Lib::ProductModel
12{
13 Net::Net(const std::string& name, unsigned int index)
14 : m_name(name)
15 , m_index(index)
16 {
17 }
18
19 Net::~Net()
20 {
21 m_pinConnections.clear();
22 }
23
24 std::string Net::GetName() const
25 {
26 return m_name;
27 }
28
29 PinConnection::Vector& Net::GetPinConnections()
30 {
31 return m_pinConnections;
32 }
33
34 unsigned int Net::GetIndex() const
35 {
36 return m_index;
37 }
38
39 bool Net::AddPinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin)
40 {
41 m_pinConnections.push_back(std::make_shared<PinConnection>(pComponent, pPin));
42 return true;
43 }
44
45 std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Net> Odb::Lib::ProductModel::Net::to_protobuf() const
46 {
47 auto pNetMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Net>();
48 pNetMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
49 pNetMsg->set_index(m_index);
50 for (auto& pPinConnection : m_pinConnections)
51 {
52 pNetMsg->add_pinconnections()->CopyFrom(*pPinConnection->to_protobuf());
53 }
54 return pNetMsg;
55 }
56
57 void Odb::Lib::ProductModel::Net::from_protobuf(const Odb::Lib::Protobuf::ProductModel::Net& message)
58 {
59 m_name = message.name();
60 m_index = message.index();
61 for (auto& pinConnectionMsg : message.pinconnections())
62 {
63 auto pPinConnection = std::make_shared<PinConnection>(nullptr, nullptr, "");
64 pPinConnection->from_protobuf(pinConnectionMsg);
65 m_pinConnections.push_back(pPinConnection);
66 }
67 }
68}