Example #1
0
/*
  Don't actually free up anything here as the space which is used
  by the node will be free'd up when the whole block is free'd.
  Returns 0 on error, non-zero on success.
*/
int wxMemStruct::Unlink ()
{
    if (! AssertList ())
        return 0;

    if (wxDebugContext::GetHead () == 0 || wxDebugContext::GetTail () == 0) {
        ErrorMsg ("Trying to remove node from empty list");
        return 0;
    }

    // Handle the part of the list before this node.
    if (m_prev == 0) {
        if (this != wxDebugContext::GetHead ()) {
            ErrorMsg ("No previous node for non-head node");
            return 0;
        }
        (void) wxDebugContext::SetHead (m_next);
    } else {
        if (! m_prev->AssertIt ()) {
            ErrorMsg ("Trashed previous pointer");
            return 0;
        }

        if (m_prev->m_next != this) {
            ErrorMsg ("List is inconsistent");
            return 0;
        }
        m_prev->m_next = m_next;
    }

    // Handle the part of the list after this node.
    if (m_next == 0) {
        if (this != wxDebugContext::GetTail ()) {
            ErrorMsg ("No next node for non-tail node");
            return 0;
        }
        (void) wxDebugContext::SetTail (m_prev);
    } else {
        if (! m_next->AssertIt ()) {
            ErrorMsg ("Trashed next pointer");
            return 0;
        }

        if (m_next->m_prev != this) {
            ErrorMsg ("List is inconsistent");
            return 0;
        }
        m_next->m_prev = m_prev;
    }

    return 1;
}
// test xml parsing result
void TestXMLPasring(char* szXMLStr, T_XML_NODE xmlArr[])
{
    T_NODE tHead = {
        NULL,
        NULL,
        NULL
    };
    
    ParseXMLStr(szXMLStr, &tHead);

    PrintList(&tHead);
    
    AssertList(&tHead, xmlArr);
    
    MyPrintf("szXMLStr(%s) test ok!-----------------\n\n", szXMLStr);
}
void TestList()
{
    T_NODE headNode = {NULL, NULL};
   
    Insert2List(&headNode, "first", "firstcontent");
    Insert2List(&headNode, "second", "secondcontent");
   
    PrintList(&headNode);
   
    T_XML_NODE xmlArr[] = {
        {"second", "secondcontent"},
        {"first", "firstcontent"},
        {NULL, NULL},
    };
    AssertList(&headNode, xmlArr);
    
    FreeList(&headNode);
}
Example #4
0
/*
  Additions are always at the tail of the list.
  Returns 0 on error, non-zero on success.
*/
int wxMemStruct::Append ()
{
    if (! AssertList ())
        return 0;

    if (wxDebugContext::GetHead () == 0) {
        if (wxDebugContext::GetTail () != 0) {
            ErrorMsg ("Null list should have a null tail pointer");
            return 0;
        }
        (void) wxDebugContext::SetHead (this);
        (void) wxDebugContext::SetTail (this);
    } else {
        wxDebugContext::GetTail ()->m_next = this;
        this->m_prev = wxDebugContext::GetTail ();
        (void) wxDebugContext::SetTail (this);
    }
    return 1;
}