36 #include <unordered_map>
88 std::vector<T*> other_pins = other.
get_pins();
89 if (m_pins.size() != other_pins.size())
94 auto this_it = m_pins.begin();
95 auto other_it = other_pins.begin();
96 while (this_it != m_pins.end() && other_it != other_pins.end())
98 if (**this_it++ != **other_it++)
125 return (uintptr_t)
this;
205 std::vector<T*>
get_pins(
const std::function<
bool(T*)>& filter =
nullptr)
const
209 return std::vector<T*>(m_pins.begin(), m_pins.end());
214 for (
T* pin : m_pins)
233 if (
index >= m_lowest_index &&
index <= m_highest_index)
235 auto it = m_pins.begin();
238 std::advance(it,
index - m_lowest_index);
242 std::advance(it, m_highest_index -
index);
247 return ERR(
"no pin exists at index " + std::to_string(
index) +
" within pin group '" + m_name +
"'");
260 return ERR(
"'nullptr' provided as pin when trying to retrieve index within pin group '" + m_name +
"' with ID " + std::to_string(m_id));
263 if (pin->m_group.first !=
this)
265 return ERR(
"provided pin '" + pin->get_name() +
"' does not belong to pin group '" + m_name +
"'");
268 return OK(pin->m_group.second);
298 return m_lowest_index;
308 return m_highest_index;
320 return m_ascending ? m_lowest_index : m_highest_index;
350 return m_pins.empty();
360 return m_pins.size();
377 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);
381 i32 index = m_pins.empty() ? m_highest_index : ++m_highest_index;
385 m_pins.push_back(pin);
389 m_pins.push_front(pin);
391 pin->m_group = std::make_pair(
this,
index);
407 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));
410 if (pin->m_group.first !=
this)
412 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));
415 if (new_index >= m_lowest_index && new_index <= m_highest_index)
419 i32 old_index = pin->m_group.second;
420 if (old_index == new_index)
428 m_pins.erase(std::next(m_pins.begin(), old_index - m_lowest_index));
429 auto it = std::next(m_pins.begin(), new_index - m_lowest_index);
430 it = m_pins.insert(it, pin);
436 std::get<1>((*it)->m_group) +=
direction;
438 std::get<1>(pin->m_group) = new_index;
442 i32 old_index = pin->m_group.second;
443 if (old_index == new_index)
451 m_pins.erase(std::next(m_pins.begin(), m_highest_index - old_index));
452 auto it = std::next(m_pins.begin(), m_highest_index - new_index);
453 it = m_pins.insert(it, pin);
459 std::get<1>((*it)->m_group) -=
direction;
461 std::get<1>(pin->m_group) = new_index;
466 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 ("
467 + 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));
485 log_warning(
"pin_group",
"'nullptr' given instead of a pin when trying to remove pin from pin group '{}' with ID {}.", m_name, m_id);
489 if (pin->m_group.first !=
this)
491 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);
496 pin->m_group = std::make_pair(
nullptr, 0);
502 auto it = std::next(m_pins.begin(),
index - m_lowest_index);
503 it = m_pins.erase(it);
504 for (; it != m_pins.end(); it++)
506 std::get<1>((*it)->m_group)--;
511 auto it = m_pins.begin();
512 for (
int i = m_highest_index; i >
index; i--)
514 std::get<1>((*(it++))->m_group)--;
519 m_highest_index = m_pins.empty() ? m_lowest_index : --m_highest_index;
537 if (pin->m_group.first !=
this)
550 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,...)