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