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)
232 if (index >= m_start_index && index < m_next_index)
234 auto it = m_pins.begin();
235 std::advance(it, index - m_start_index);
241 if (index <= m_start_index && index > m_next_index)
243 auto it = m_pins.begin();
244 std::advance(it, m_start_index - index);
249 return ERR(
"no pin exists at index " + std::to_string(index) +
" within pin group '" + m_name +
"'");
262 return ERR(
"'nullptr' provided as pin when trying to retrieve index within pin group '" + m_name +
"' with ID " + std::to_string(m_id));
265 if (pin->m_group.first !=
this)
267 return ERR(
"provided pin '" + pin->get_name() +
"' does not belong to pin group '" + m_name +
"'");
270 return OK(pin->m_group.second);
292 return m_start_index;
322 return m_pins.empty();
332 return m_pins.size();
345 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);
352 index = m_next_index++;
353 m_pins.push_back(pin);
357 if (m_start_index == m_next_index)
360 index = m_start_index;
365 index = ++m_start_index;
367 m_pins.push_front(pin);
369 pin->m_group = std::make_pair(
this, index);
384 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));
387 if (pin->m_group.first !=
this)
389 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));
392 if (m_ascending && new_index >= m_start_index && new_index < m_next_index)
394 i32 old_index = pin->m_group.second;
395 if (old_index == new_index)
403 m_pins.erase(std::next(m_pins.begin(), old_index - m_start_index));
404 auto it = std::next(m_pins.begin(), new_index - m_start_index);
405 it = m_pins.insert(it, pin);
411 std::get<1>((*it)->m_group) +=
direction;
413 std::get<1>(pin->m_group) = new_index;
415 else if (!m_ascending && new_index <= m_start_index && new_index > m_next_index)
417 i32 old_index = pin->m_group.second;
418 if (old_index == new_index)
426 m_pins.erase(std::next(m_pins.begin(), m_start_index - old_index));
427 auto it = std::next(m_pins.begin(), m_start_index - new_index);
428 it = m_pins.insert(it, pin);
434 std::get<1>((*it)->m_group) -=
direction;
436 std::get<1>(pin->m_group) = new_index;
440 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 start index ("
441 + std::to_string(m_start_index) +
") and end index(" + std::to_string(m_next_index - 1) +
") of pin group '" + m_name +
"' with ID " + std::to_string(m_id));
457 log_warning(
"pin_group",
"'nullptr' given instead of a pin when trying to remove pin from pin group '{}' with ID {}.", m_name, m_id);
461 if (pin->m_group.first !=
this)
463 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);
467 i32 index = pin->m_group.second;
468 pin->m_group = std::make_pair(
nullptr, 0);
471 auto it = std::next(m_pins.begin(), index - m_start_index);
472 it = m_pins.erase(it);
473 for (; it != m_pins.end(); it++)
475 std::get<1>((*it)->m_group)--;
481 if (m_pins.size() == 1)
488 auto it = m_pins.begin();
489 for (
int i = m_start_index; i > index; i--)
491 std::get<1>((*(it++))->m_group)--;
514 if (pin->m_group.first !=
this)
527 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_start_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
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,...)