16 Net::Net(NetlistInternalManager* internal_manager, EventHandler* event_handler,
const u32 id,
const std::string&
name)
18 assert(internal_manager !=
nullptr);
19 m_internal_manager = internal_manager;
23 m_event_handler = event_handler;
30 log_debug(
"net",
"the nets with IDs {} and {} are not equal due to an unequal ID or name.", m_id, other.
get_id());
36 log_debug(
"net",
"the nets with IDs {} and {} are not equal as one is a global input or output net and the other is not.", m_id, other.
get_id());
42 log_debug(
"net",
"the nets with IDs {} and {} are not equal due to an unequal number of sources or destinations.", m_id, other.
get_id());
46 const std::vector<Endpoint*>& sources_n2 = other.
get_sources();
47 for (
const Endpoint* ep_n1 : m_sources_raw)
49 if (std::find_if(sources_n2.begin(), sources_n2.end(), [ep_n1](
const Endpoint* ep_n2) { return *ep_n1->get_pin() == *ep_n2->get_pin() && *ep_n1->get_gate() == *ep_n2->get_gate(); })
52 log_debug(
"net",
"the nets with IDs {} and {} are not equal due to an unequal source endpoint.", m_id, other.
get_id());
58 for (
const Endpoint* ep_n1 : m_destinations_raw)
61 destinations_n2.begin(), destinations_n2.end(), [ep_n1](
const Endpoint* ep_n2) { return *ep_n1->get_pin() == *ep_n2->get_pin() && *ep_n1->get_gate() == *ep_n2->get_gate(); })
62 == destinations_n2.end())
64 log_debug(
"net",
"the nets with IDs {} and {} are not equal due to an unequal destination endpoint.", m_id, other.
get_id());
69 if (!DataContainer::operator==(other))
71 log_debug(
"net",
"the nets with IDs {} and {} are not equal due to unequal data.", m_id, other.
get_id());
85 return (uintptr_t)
this;
95 return m_internal_manager->m_netlist;
107 log_error(
"net",
"net name cannot be empty.");
124 return m_internal_manager->net_add_source(
this, gate, pin);
131 log_warning(
"net",
"could not add source to gate: nullptr given for gate");
134 if (pin_name.empty())
136 log_warning(
"net",
"could not add source to gate '{}' with ID {}: empty string provided as pin name", gate->
get_name(), gate->
get_id());
142 log_warning(
"net",
"could not add source to gate '{}' with ID {}: no pin with name '{}' exists", gate->
get_name(), gate->
get_id(), pin_name);
150 if (
auto it = std::find_if(m_sources_raw.begin(), m_sources_raw.end(), [gate, pin](
auto ep) { return ep->get_gate() == gate && *ep->get_pin() == *pin; }); it != m_sources_raw.end())
152 return m_internal_manager->net_remove_source(
this, *it);
161 log_warning(
"net",
"could not remove source from gate: nullptr given for gate");
164 if (pin_name.empty())
166 log_warning(
"net",
"could not remove source from gate '{}' with ID {}: empty string provided as pin name", gate->
get_name(), gate->
get_id());
172 log_warning(
"net",
"could not remove source from gate '{}' with ID {}: no pin with name '{}' exists", gate->
get_name(), gate->
get_id(), pin_name);
184 return m_internal_manager->net_remove_source(
this, ep);
191 log_warning(
"net",
"could not check if gate is a source: nullptr given for gate");
195 return std::find_if(m_sources_raw.begin(), m_sources_raw.end(), [gate](
const auto* ep) { return ep->get_gate() == gate; }) != m_sources_raw.end();
202 log_warning(
"net",
"could not check if gate is a source: nullptr given for gate");
208 log_warning(
"net",
"could not check if gate is a source: nullptr given for pin");
212 return std::find_if(m_sources_raw.begin(), m_sources_raw.end(), [gate, pin](
const auto* ep) { return ep->get_gate() == gate && *ep->get_pin() == *pin; }) != m_sources_raw.end();
219 log_warning(
"net",
"could not check if gate is a source: nullptr given for gate");
223 if (pin_name.empty())
225 log_warning(
"net",
"could not check if gate '{}' with ID {} is a source: empty string provided as pin name", gate->
get_name(), gate->
get_id());
243 return std::find(m_sources_raw.begin(), m_sources_raw.end(), ep) != m_sources_raw.end();
250 return (
u32)m_sources_raw.size();
254 for (
auto dst : m_sources_raw)
268 return m_sources_raw;
271 std::vector<Endpoint*> srcs;
272 for (
auto src : m_sources_raw)
285 return m_internal_manager->net_add_destination(
this, gate, pin);
292 log_warning(
"net",
"could not add destination to gate: nullptr given for gate");
295 if (pin_name.empty())
297 log_warning(
"net",
"could not add destination to gate '{}' with ID {}: empty string provided as pin name", gate->
get_name(), gate->
get_id());
303 log_warning(
"net",
"could not add destination to gate '{}' with ID {}: no pin with name '{}' exists", gate->
get_name(), gate->
get_id(), pin_name);
311 if (
auto it = std::find_if(m_destinations_raw.begin(), m_destinations_raw.end(), [gate, pin](
const auto* ep) { return ep->get_gate() == gate && *ep->get_pin() == *pin; });
312 it != m_destinations_raw.end())
314 return m_internal_manager->net_remove_destination(
this, *it);
323 log_warning(
"net",
"could not remove destination from gate: nullptr given for gate");
326 if (pin_name.empty())
328 log_warning(
"net",
"could not remove destination from gate '{}' with ID {}: empty string provided as pin name", gate->
get_name(), gate->
get_id());
334 log_warning(
"net",
"could not remove destination from gate '{}' with ID {}: no pin with name '{}' exists", gate->
get_name(), gate->
get_id(), pin_name);
346 return m_internal_manager->net_remove_destination(
this, ep);
353 log_warning(
"net",
"could not check if gate is a destination: nullptr given for gate");
357 return std::find_if(m_destinations_raw.begin(), m_destinations_raw.end(), [gate](
const auto* ep) { return ep->get_gate() == gate; }) != m_destinations_raw.end();
364 log_warning(
"net",
"could not check if gate is a destination: nullptr given for gate");
370 log_warning(
"net",
"could not check if gate is a destination: nullptr given for pin");
374 return std::find_if(m_destinations_raw.begin(), m_destinations_raw.end(), [gate, pin](
const auto* ep) { return ep->get_gate() == gate && *ep->get_pin() == *pin; }) != m_destinations_raw.end();
381 log_warning(
"net",
"could not check if gate is a destination: nullptr given for gate");
385 if (pin_name.empty())
387 log_warning(
"net",
"could not check if gate '{}' with ID {} is a destination: empty string provided as pin name", gate->
get_name(), gate->
get_id());
405 return std::find(m_destinations_raw.begin(), m_destinations_raw.end(), ep) != m_destinations_raw.end();
412 return (
u32)m_destinations_raw.size();
416 for (
auto dst : m_destinations_raw)
430 return m_destinations_raw;
433 std::vector<Endpoint*> dsts;
434 for (
auto dst : m_destinations_raw)
447 return ((m_sources.size() == 0) || (m_destinations.size() == 0));
452 return m_sources.size() == 1 && m_sources.front()->get_gate()->is_gnd_gate();
457 return m_sources.size() == 1 && m_sources.front()->get_gate()->is_vcc_gate();
bool is_source_pin() const
bool is_destination_pin() const
NETLIST_API void notify(NetlistEvent::event ev, Netlist *netlist, u32 associated_data=0xFFFFFFFF)
GateType * get_type() const
const std::string & get_name() const
GatePin * get_pin_by_name(const std::string &name) const
@ name_changed
no associated_data
u32 get_num_of_sources(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Netlist * get_netlist() const
Endpoint * add_destination(Gate *gate, const std::string &pin_name)
bool remove_source(Gate *gate, const std::string &pin_name)
void set_name(const std::string &name)
bool mark_global_input_net()
Endpoint * add_source(Gate *gate, const std::string &pin_name)
const std::string & get_name() const
bool unmark_global_output_net()
bool operator==(const Net &other) const
bool unmark_global_input_net()
bool mark_global_output_net()
bool is_a_source(const Gate *gate) const
Grouping * get_grouping() const
bool is_global_output_net() const
u32 get_num_of_destinations(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
std::vector< Endpoint * > get_destinations(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
bool operator!=(const Net &other) const
bool is_a_destination(const Gate *gate) const
bool is_global_input_net() const
bool remove_destination(Gate *gate, const std::string &pin_name)
std::vector< Endpoint * > get_sources(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
bool mark_global_input_net(Net *net)
bool mark_global_output_net(Net *net)
bool unmark_global_output_net(Net *net)
bool is_global_input_net(const Net *net) const
bool unmark_global_input_net(Net *net)
bool is_global_output_net(const Net *net) const
#define log_error(channel,...)
#define log_debug(channel,...)
#define log_warning(channel,...)
CORE_API T trim(const T &s, const char *to_remove=" \t\r\n")