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