示例#1
0
//----------------------------------------------------------------------------
bool Object::DetachControl (Controller* pkControl)
{
    if ( pkControl && m_spkControl )
    {
        if ( pkControl == m_spkControl )
        {
            // controller at front of list, remove it
            pkControl->SetObject(NULL);
            ControllerPtr spkSave = pkControl;  // prevent delete
            m_spkControl = pkControl->GetNext();
            pkControl->SetNext(NULL);

            // TO DO. If the reference count for pkControl is 1, when the
            // function returns, spkSave's destructor will delete pkControl.
            // Warn the application about this?
            return true;
        }

        // search for controller
        Controller* pkPrevious = WmlSmartPointerCast(Controller,m_spkControl);
        Controller* pkCurrent = pkPrevious->GetNext();
        while ( pkCurrent && pkCurrent != pkControl )
        {
            pkPrevious = pkCurrent;
            pkCurrent = pkCurrent->GetNext();
        }
        if ( pkCurrent )
        {
            // found the controller, remove it
            pkControl->SetObject(NULL);
            ControllerPtr spkSave = pkControl;  // prevent delete
            pkPrevious->SetNext(pkControl->GetNext());
            pkControl->SetNext(NULL);

            // TO DO. If the reference count for pkControl is 1, when the
            // function returns, spkSave's destructor will delete pkControl.
            // Warn the application about this?
            return true;
        }
    }
    return false;
}
示例#2
0
//----------------------------------------------------------------------------
StringTree* Object::SaveStrings ()
{
    int iCQuantity = ( m_spkControl ? 1 : 0 );
    StringTree* pkTree = new StringTree(4,0,iCQuantity,0);

    // strings
    pkTree->SetString(0,MakeString(&ms_kRTTI,GetName()));
    pkTree->SetString(1,MakeString("this =",this));
    pkTree->SetString(2,MakeString("ID   =",m_uiID));
    pkTree->SetString(3,MakeString("refs =",m_uiReferences));

    // children
    if ( m_spkControl )
    {
        Controller* pkControl = WmlSmartPointerCast(Controller,m_spkControl);
        iCQuantity = 0;
        while ( pkControl )
        {
            iCQuantity++;
            pkControl = pkControl->GetNext();
        }

        StringTree* pkCTree = new StringTree(1,0,iCQuantity,0);
        pkTree->SetChild(0,pkCTree);
        pkCTree->SetString(0,MakeString("controllers"));
        int iSlot = 0;
        pkControl = WmlSmartPointerCast(Controller,m_spkControl);
        while ( pkControl )
        {
            pkCTree->SetChild(iSlot++,pkControl->SaveStrings());
            pkControl = pkControl->GetNext();
        }
    }

    return pkTree;
}