Пример #1
0
testlist::Child testlist::Parent::popBackChild() const  {
    Child result = getLastChild();
    if(result.isValid())
    {
        result.removeParentHandler();
        Child prev = result.getPrevParentChild();
        result.setPrevParentChild(Child());
        result.setNextParentChild(Child());
        setLastChild(prev);
        if(!prev.isValid())
            setFirstChild(Child());
        else
            prev.setNextParentChild(Child());
        setNumChilds(getNumChilds() - 1);
        result.setParent(Parent());
    }
    return result;
}
Пример #2
0
Bool testlist::Parent::insertAfterChild(const Child & child, const Child & prev) const  {
    if(!child.isExists() ||
        !prev.isExists() ||
        prev.getParent() != *this ||
        child.getParent().isValid())
        return false;
    Child next = prev.getNextParentChild();
    prev.setNextParentChild(child);
    child.setPrevParentChild(prev);
    child.setNextParentChild(next);
    if(next.isValid())
        next.setPrevParentChild(child);
    else
        setLastChild(child);
    child.setParent(*this);
    setNumChilds(getNumChilds() + 1);
    child.setupParentHandler();
    return true;
}
Пример #3
0
Bool testlist::Parent::insertBeforeChild(const Child & child, const Child & next) const  {
    if(!child.isExists() ||
        !next.isExists() ||
        next.getParent() != *this ||
        child.getParent().isValid())
        return false;
    Child prev = next.getPrevParentChild();
    next.setPrevParentChild(child);
    child.setNextParentChild(next);
    child.setPrevParentChild(prev);
    if(prev.isValid())
        prev.setNextParentChild(child);
    else
        setFirstChild(child);
    child.setParent(*this);
    setNumChilds(getNumChilds() + 1);
    child.setupParentHandler();
    return true;
}
Пример #4
0
Bool testlist::Parent::pushBackChild(const Child & child) const  {
    if(!child.isExists() || child.getParent().isValid())
        return false;
    Child last_child = getLastChild();
    child.setPrevParentChild(last_child);
    if(last_child.isValid())
        last_child.setNextParentChild(child);
    else
        setFirstChild(child);
    child.setNextParentChild(Child());
    setLastChild(child);
    setNumChilds(getNumChilds() + 1);
    child.setParent(*this);
    child.setupParentHandler();
    return true;
}
Пример #5
0
testlist::Child testlist::Parent::popFrontChild() const  {
    Child result = getFirstChild();
    if(result.isValid())
    {
        result.removeParentHandler();
        Child next = result.getNextParentChild();
        result.setNextParentChild(Child());
        result.setPrevParentChild(Child());
        setFirstChild(next);
        if(!next.isValid())
            setLastChild(Child());
        else
            next.setPrevParentChild(Child());
        setNumChilds(getNumChilds() - 1);
        result.setParent(Parent());
    }
    return result;
}
Пример #6
0
Bool testlist::Parent::removeChild(const Child & child) const  {
    if( !child.isExists() || child.getParent() != *this)
        return false;
    child.removeParentHandler();
    Child next = child.getNextParentChild(), prev = child.getPrevParentChild();
    if(next.isValid())
        next.setPrevParentChild(prev);
    else if (getLastChild() == child)
        setLastChild(prev);
    else
        return false;
    if(prev.isValid())
        prev.setNextParentChild(next);
    else if (getFirstChild() == child)
        setFirstChild(next);
    else
        return false;
    child.setNextParentChild(Child());
    child.setPrevParentChild(Child());
    child.setParent(Parent());
    setNumChilds(getNumChilds() - 1);
    return true;
}