OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
Net.cpp
Go to the documentation of this file.
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
12{
13 Net::Net(const std::string& name, unsigned int index)
14 : m_name(name)
15 , m_index(index)
16 {
17 }
18
20 {
21 m_pinConnections.clear();
22 }
23
24 std::string Net::GetName() const
25 {
26 return m_name;
27 }
28
30 {
31 return m_pinConnections;
32 }
33
35 {
36 return m_pinConnections;
37 }
38
39 unsigned int Net::GetIndex() const
40 {
41 return m_index;
42 }
43
44 bool Net::AddPinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, unsigned int subnetNumber)
45 {
46 m_pinConnections.push_back(std::make_shared<PinConnection>(pComponent, pPin, subnetNumber));
47 return true;
48 }
49
50 std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Net> Odb::Lib::ProductModel::Net::to_protobuf() const
51 {
52 auto pNetMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Net>();
53 pNetMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
54 pNetMsg->set_index(m_index);
55 for (auto& pPinConnection : m_pinConnections)
56 {
57 pNetMsg->add_pinconnections()->CopyFrom(*pPinConnection->to_protobuf());
58 }
59 return pNetMsg;
60 }
61
62 void Odb::Lib::ProductModel::Net::from_protobuf(const Odb::Lib::Protobuf::ProductModel::Net& message)
63 {
64 m_name = message.name();
65 m_index = message.index();
66 for (auto& pinConnectionMsg : message.pinconnections())
67 {
68 auto pPinConnection = std::make_shared<PinConnection>(nullptr, nullptr, "");
69 pPinConnection->from_protobuf(pinConnectionMsg);
70 m_pinConnections.push_back(pPinConnection);
71 }
72 }
73}
bool AddPinConnection(std::shared_ptr< Component > pComponent, std::shared_ptr< Pin > pPin, unsigned int subnetNumber=0)
Definition Net.cpp:44
unsigned int GetIndex() const
Definition Net.cpp:39
void from_protobuf(const Odb::Lib::Protobuf::ProductModel::Net &message) override
Definition Net.cpp:62
std::unique_ptr< Odb::Lib::Protobuf::ProductModel::Net > to_protobuf() const override
Definition Net.cpp:50
Net(const std::string &name, unsigned int index)
Definition Net.cpp:13
std::string GetName() const
Definition Net.cpp:24
PinConnection::Vector & GetPinConnections()
Definition Net.cpp:29
std::vector< std::shared_ptr< PinConnection > > Vector
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.