Exemple #1
0
// ------------------------------------------------------------------------------------------------
void Signal::Head(Object & env, Function & func)
{
    // Don't attempt to search anything if there's no head
    if (m_Head == nullptr)
    {
        m_Head = new Slot(env, func, nullptr);
        // We're done here
        return;
    }

    const Slot slot{env, func};
    // Don't attempt to search anything if there's only one element
    if (m_Head->mNext == nullptr)
    {
        // Is it already inserted?
        if (*m_Head != slot)
        {
            m_Head = new Slot(env, func, m_Head);
        }
        // We're done here
        return;
    }

    // Grab the head node
    Slot * node = m_Head;
    // Walk down the chain and find a matching node
    for (; node != nullptr; node = node->mNext)
    {
        if (*node == slot)
        {
            break; // Found it
        }
    }
    // Have we found anything?
    if (node == nullptr)
    {
        m_Head = new Slot(env, func, m_Head); // Lead everyone
    }
    // Is it the head already?
    else if (m_Head != node)
    {
        node->AttachNext(m_Head);
        // We're the head now
        m_Head = node;
    }
}