36 #include <unordered_map>
85 std::vector<T*> other_pins = other.
get_pins();
86 if (m_pins.size() != other_pins.size())
91 auto this_it = m_pins.begin();
92 auto other_it = other_pins.begin();
93 while (this_it != m_pins.end() && other_it != other_pins.end())
95 if (**this_it++ != **other_it++)
122 return (uintptr_t)
this;
202 std::vector<T*>
get_pins(
const std::function<
bool(T*)>& filter =
nullptr)
const
206 return std::vector<T*>(m_pins.begin(), m_pins.end());
211 for (
T* pin : m_pins)
230 if (index >= m_lowest_index && index <= m_highest_index)
232 auto it = m_pins.begin();
235 std::advance(it, index - m_lowest_index);
239 std::advance(it, m_highest_index - index);
244 return ERR(
"no pin exists at index " + std::to_string(index) +
" within pin group '" + m_name +
"'");
257 return ERR(
"'nullptr' provided as pin when trying to retrieve index within pin group '" + m_name +
"' with ID " + std::to_string(m_id));
260 if (pin->m_group.first !=
this)
262 return ERR(
"provided pin '" + pin->get_name() +
"' does not belong to pin group '" + m_name +
"'");
265 return OK(pin->m_group.second);
295 return m_lowest_index;
305 return m_highest_index;
317 return m_ascending ? m_lowest_index : m_highest_index;
347 return m_pins.empty();
357 return m_pins.size();
374 log_warning(
"pin_group",
"'nullptr' given instead of a pin when trying to assign a pin to pin group '{}' with ID {}", m_name, m_id);
378 i32 index = m_pins.empty() ? m_highest_index : ++m_highest_index;
382 m_pins.push_back(pin);
386 m_pins.push_front(pin);
388 pin->m_group = std::make_pair(
this, index);
404 return ERR(
"'nullptr' given instead of a pin when trying to move pin within pin group '" + m_name +
"' with ID " + std::to_string(m_id));
407 if (pin->m_group.first !=
this)
409 return ERR(
"pin '" + pin->get_name() +
"' with ID " + std::to_string(pin->get_id()) +
" does not belong to pin group '" + m_name +
"' with ID " + std::to_string(m_id));
412 if (new_index >= m_lowest_index && new_index <= m_highest_index)
416 i32 old_index = pin->m_group.second;
417 if (old_index == new_index)
425 m_pins.erase(std::next(m_pins.begin(), old_index - m_lowest_index));
426 auto it = std::next(m_pins.begin(), new_index - m_lowest_index);
427 it = m_pins.insert(it, pin);
433 std::get<1>((*it)->m_group) +=
direction;
435 std::get<1>(pin->m_group) = new_index;
439 i32 old_index = pin->m_group.second;
440 if (old_index == new_index)
448 m_pins.erase(std::next(m_pins.begin(), m_highest_index - old_index));
449 auto it = std::next(m_pins.begin(), m_highest_index - new_index);
450 it = m_pins.insert(it, pin);
456 std::get<1>((*it)->m_group) -=
direction;
458 std::get<1>(pin->m_group) = new_index;
463 return ERR(
"new index (" + std::to_string(new_index) +
") for pin '" + pin->get_name() +
"' with ID " + std::to_string(pin->get_id()) +
" is not between lowest index ("
464 + std::to_string(m_lowest_index) +
") and highest index (" + std::to_string(m_highest_index - 1) +
") of pin group '" + m_name +
"' with ID " + std::to_string(m_id));
482 log_warning(
"pin_group",
"'nullptr' given instead of a pin when trying to remove pin from pin group '{}' with ID {}.", m_name, m_id);
486 if (pin->m_group.first !=
this)
488 log_warning(
"pin_group",
"pin '{}' with ID {} does not belong to pin group '{}' with ID {}.", pin->get_name(), pin->get_id(), m_name, m_id);
492 i32 index = pin->m_group.second;
493 pin->m_group = std::make_pair(
nullptr, 0);
499 auto it = std::next(m_pins.begin(), index - m_lowest_index);
500 it = m_pins.erase(it);
501 for (; it != m_pins.end(); it++)
503 std::get<1>((*it)->m_group)--;
508 auto it = m_pins.begin();
509 for (
int i = m_highest_index; i > index; i--)
511 std::get<1>((*(it++))->m_group)--;
516 m_highest_index = m_pins.empty() ? m_lowest_index : --m_highest_index;
534 if (pin->m_group.first !=
this)
547 std::list<T*> m_pins;
Result< i32 > get_index(const T *pin) const
std::vector< T * > get_pins(const std::function< bool(T *)> &filter=nullptr) const
Result< std::monostate > move_pin(T *pin, i32 new_index)
void set_direction(PinDirection direction)
bool contains_pin(T *pin)
i32 get_highest_index() const
i32 get_start_index() const
i32 get_lowest_index() const
bool operator==(const PinGroup< T > &other) const
const std::string & get_name() const
void set_ordered(bool ordered=true)
void set_name(const std::string &name)
Result< T * > get_pin_at_index(i32 index) const
bool is_ascending() const
PinDirection get_direction() const
bool is_descending() const
PinGroup(const u32 id, const std::string &name, PinDirection direction, PinType type, bool ascending=true, u32 start_index=0, bool ordered=false)
void set_type(PinType type)
bool operator!=(const PinGroup< T > &other) const
#define log_warning(channel,...)