Beispiel #1
0
CTreeElement<T> * CTree<T>::Add(CTreeElement<T> * Node, const T& Element, bool * Added) {
	if (Added) (* Added) = true;
	if (!Node) Node = m_Head;
	if (!Node) {
          m_Head = new CTreeElement<T>(Element);          
          return m_Head;
        }
	/* hack: try to add to parent's last element */
	if (Node->m_Parent) {
		if (m_Sorted) {
			if (Greater(Element, Node->m_Parent->m_LastChild->m_Element)) {
				return AddAfter(Node->m_Parent->m_LastChild, Element);
			} else if (m_Unique && (Equal(Node->m_Parent->m_LastChild->m_Element, Element))) {
				if (Added) (* Added) = false;
				return Node->m_Parent->m_LastChild;
			}
		}
		Node = Node->m_Parent->m_Child;
	} else Node = m_Head;
	/* classic insertion */
	while(1) {
		if (m_Unique && Equal(Node->m_Element, Element)) {
			if (Added) (* Added) = false;
			return Node;
		} else if (m_Sorted && (Greater(Node->m_Element, Element))) return AddBefore(Node, Element);
		if (Node->m_Next) Node = Node->m_Next;
		else break;
	}
	return AddAfter(Node, Element);
}
Beispiel #2
0
CTreeElement<T> * CTree<T>::AddChild(CTreeElement<T> * Node, const T& Element, bool * Added) {
	if (Added) (* Added) = true;
	if (!Node) Node = m_Head;
	if (!Node) {
          m_Head = new CTreeElement<T>(Element);          
          return m_Head;
        }
	/* hack: check the last element first */
	if (m_Sorted && Node->m_LastChild) {          
		if (Greater(Element, Node->m_LastChild->m_Element)) {
			return AddAfter(Node->m_LastChild, Element);
		} else if (m_Unique && (Equal(Node->m_LastChild->m_Element, Element))) {
			if (Added) (* Added) = false;
			return Node->m_LastChild;
		}
	}
	/* classic add to the tree */
	CTreeElement<T> * Current = Node->m_Child;
	if (!Current) return AddChildFirst(Node, Element);
	while(1) {
		if (m_Unique && Equal(Current->m_Element, Element)) {
			if (Added) (* Added) = false;
			return Current;
		} else if (m_Sorted && (Greater(Current->m_Element, Element))) {
			return AddBefore(Current, Element);
		}
		if (Current->m_Next) Current = Current->m_Next;
		else break;
	}
	return AddAfter(Current, Element);
}
Beispiel #3
0
int KGLISTITEMDATELINK::AddDepend(
								  LPKGLISTITEM pParentItem, LPKGLISTITEM pAddItem
								  )
{
	int nResult  = false;
	int nRetCode = false;

	LPKGLISTITEM pBeforeItem = NULL;
	LPKGLISTITEM pTempItem   = NULL;

	KG_PROCESS_ERROR(pAddItem);

	if (pParentItem)
	{	
		KG_PROCESS_ERROR(pHead);
		nRetCode = FindItem(pParentItem);
		KG_PROCESS_ERROR(nRetCode);

		pTempItem = pParentItem->pFirstChildItem;
		if (!pTempItem)
		{
			pParentItem->pFirstChildItem = pAddItem;
			pAddItem->pPerantItem		 = pParentItem;
			pAddItem->nTitleLever		 = pParentItem->nTitleLever + 1;
		}
		else
		{
			while (pTempItem)
			{
				pBeforeItem = pTempItem;
				pTempItem   = pTempItem->pNexSiblingItem;
			}
			AddAfter(pBeforeItem, pAddItem);
		}

	}
	else
	{
		if (!pHead)
		{
			pHead = pAddItem;
			pAddItem->pPerantItem = NULL;
			pAddItem->nTitleLever = 0;
		}
		else
		{
			pTempItem = pHead;
			while (pTempItem)
			{
				pBeforeItem = pTempItem;
				pTempItem   = pTempItem->pNexSiblingItem;
			}
			AddAfter(pBeforeItem, pAddItem);
		}
	}

	nResult = true;	 
Exit0:
	return nResult;
}
Beispiel #4
0
bool CUrlTree::AddFast(const CString& Line, CVector<CObject *>& HorizontalVector) {
    // cout << "Line: " << Line << endl;
    CVector<CString> SpaceVector;
    CString::StrToVector(Line, ' ', &SpaceVector);
    if (SpaceVector.GetSize() != 3) return false;
    int AbstractPosition = CString::StrToInt(SpaceVector[0]);
    int HorizontalPosition = CString::StrToInt(SpaceVector[1]);
    SpaceVector[2] = CUrl::UnEscape(SpaceVector[2]);    
    // cout << "Abstract/Horizontal: " << AbstractPosition << "/" << HorizontalPosition << endl;
    CObject * NewNode = NULL;
    if (!HorizontalVector.GetSize() && !HorizontalPosition) {
        /* top node */
        NewNode = (CObject *) (m_Head = new CTreeElement<CString>(SpaceVector[2]));
        HorizontalVector += NewNode;
    } else if (HorizontalPosition == ((int)HorizontalVector.GetSize() - 1)) {
        /* same level, add after element */
        NewNode = (CObject *) AddAfter((CTreeElement<CString> *) HorizontalVector[HorizontalPosition], SpaceVector[2]);
        HorizontalVector[HorizontalPosition] = NewNode;
    } else if (HorizontalPosition > ((int)HorizontalVector.GetSize() - 1)) {
        /* sub level, add child */
        NewNode = (CObject *) AddChildLast((CTreeElement<CString> *) HorizontalVector[HorizontalPosition-1], SpaceVector[2]);
        HorizontalVector += NewNode;
    } else if (HorizontalPosition < ((int)HorizontalVector.GetSize() - 1)) {
        /* previous level, remove and add */
        do {
            HorizontalVector.RemoveAt((int)HorizontalVector.GetSize() - 1);
        } while (HorizontalPosition < ((int) HorizontalVector.GetSize() - 1));
        NewNode = (CObject *) AddAfter((CTreeElement<CString> *) HorizontalVector[HorizontalPosition], SpaceVector[2]);
        HorizontalVector[HorizontalPosition] = NewNode;
    } else return false;

    // cout << "New Tree:" << endl << (* this) << endl;
    
    /* set the absolute URL index */
    if (AbstractPosition != -1) {
        m_IndexVector.SetDim(AbstractPosition + 1);        
        while ((int) m_IndexVector.GetSize() <= AbstractPosition) 
            m_IndexVector.Add((CObject *) NULL);
        m_IndexVector[AbstractPosition] = NewNode;                
        m_UrlVector.SetSize(m_IndexVector.GetSize());
    	m_UrlVector[AbstractPosition] = ResolveAt(AbstractPosition);
    } 
    
    ((CTreeElement<CString> *) NewNode)->SetData((void *) AbstractPosition);
    
    return true;
}
Beispiel #5
0
void UIHierarchy::AddAfter(UIHierarchyNode *forParent)
{
    UIHierarchyNode *checkNode = NULL;
    if (!iheritanceQueue.empty()) 
    {
        checkNode = *(iheritanceQueue.begin());
        iheritanceQueue.pop_front();
    }
    for (List<UIHierarchyNode *>::iterator it = forParent->children.begin(); it != forParent->children.end(); it++) 
    {
        if (checkNode) 
        {
            if ((*it) == checkNode)
            {
                checkNode = NULL;
                if ((*it)->isOpen) 
                {
                    AddAfter((*it));
                }
                if(addPos + (int32)scrollContainer->relativePosition.y > size.y * 2)
                {
                    return;
                }
            }
        }
        else 
        {
            if(addPos + (int32)scrollContainer->relativePosition.y + cellHeight > -size.y)
            {
                AddCellAtPos(delegate->CellForNode(this, (*it)->userNode), addPos, cellHeight, (*it));
            }
            addPos += cellHeight;
            if(addPos + (int32)scrollContainer->relativePosition.y > size.y * 2)
            {
                return;
            }
            if ((*it)->isOpen) 
            {
                AddAfter((*it));
            }
        }
    }
}
Beispiel #6
0
void UIHierarchy::AddCellsAfter(UIHierarchyNode *afterNode)
{
    iheritanceQueue.clear();
    UIHierarchyNode *nd = afterNode;
    while (nd != baseNode)
    {
        iheritanceQueue.push_front(nd);
        nd = nd->parent;
    }
    
    AddAfter(baseNode);
}
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    // Tries to make the specified block the active one.
    // If the specified block has fever objects than the active one,
    // or the active one has more than 25% free objects, the block 
    // is put on the second position.
    void MakeBlockActive(BlockHeader* block) {
        if(First() == nullptr) {
            AddFirst(block); // The First() block in the list.
        }
        else {
            unsigned int firstFree = static_cast<BlockHeader*>(First())->FreeObjects;

            if((firstFree <= (MaxObjectNumber() / 4)) && 
               (block->FreeObjects > firstFree)) {
                // Few unused objects are in the active block, 
                // and this one has more unused objects, so make it active.
                Remove(block);
                AddFirst(block);
            }
            else {
                // Add the block after the active one.
                Remove(block);
                AddAfter(First(), block);
            }
        }
    }
Beispiel #8
0
void UIHierarchy::FullRedraw()
{
    scrollContainer->RemoveAllControls();
    if(!delegate)
    {
        return;
    }
    
    needRedraw = false;
    
    addPos = 0;
    scroll->SetViewSize(size.y);
    if (needRecalc) 
    {
        RecalcHierarchy();
    }

    iheritanceQueue.clear();
    AddAfter(baseNode);
    
    scroll->SetElementSize((float32)baseNode->openedChildrenCount * cellHeight);
}
Beispiel #9
0
//------------------------------------------------------------------------------
void BigNumber::AddZeroes (int count_zeroes) {
        for (int i=0;i<count_zeroes;i++)
                AddAfter(last,0);
}