⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srcparser.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     22/09/98
// RCS-ID:      $Id: srcparser.cpp,v 1.18 2006/07/18 16:23:52 MW Exp $
// Copyright:   (c) Aleskandars Gluchovas
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include <stdio.h>

#include "srcparser.h"

/***** Implementation for class spVisitor *****/

void spVisitor::VisitAll( spContext& atContext,
                          bool sortContent
                        )
{
    mSiblingSkipped = false;
    mChildSkipped   = false;
    mContextMask    = SP_CTX_ANY; // FIXME:: should be an arg.

    if ( sortContent && !atContext.IsSorted() )

        atContext.SortMembers();

    mpCurCxt = &atContext; // FIXME:: this is dirty, restoring it each time

    if ( atContext.GetContextType() & mContextMask )

        atContext.AcceptVisitor( *this );

    MMemberListT& members = atContext.GetMembers();

    for( size_t i = 0; i != members.size(); ++i )
    {
        if ( mSiblingSkipped )

            return;

        if ( !mChildSkipped )
        {
            size_t prevSz = members.size();

            // visit members of the context recursivelly
            VisitAll( *members[i], sortContent );

            if ( members.size() != prevSz )

                --i; // current member was removed!

            mChildSkipped = 0;
        }
    }
}

void spVisitor::RemoveCurrentContext()
{
    if ( mpCurCxt->GetParent() )

        mpCurCxt->GetParent()->RemoveChild( mpCurCxt );
}

void spVisitor::SkipSiblings()
{
    mSiblingSkipped = true;
}

void spVisitor::SkipChildren()
{
    mChildSkipped = true;
}

void spVisitor::SetFilter( int contextMask )
{
    mContextMask = contextMask;
}

/***** Implementation for class spComment *****/

bool spComment::IsMultiline()  const
{
    return mIsMultiline;
}

bool spComment::StartsParagraph() const
{
    return mStartsPar;
}

wxString& spComment::GetText()
{
    return m_Text;
}

wxString spComment::GetText() const
{
    return m_Text;
}

/***** Implementation for class spContext *****/

spContext::spContext()

    : m_pParent        ( NULL ),
      mpFirstOccurence( NULL ),
      mAlreadySorted  ( false ),

      mSrcLineNo    (-1),
      mSrcOffset    (-1),
      mContextLength(-1),
      mLastScrLineNo(-1),

      mHeaderLength (-1),
      mFooterLength (-1),

      mFirstCharPos (-1),
      mLastCharPos  (-1),

      mVisibility( SP_VIS_PRIVATE ),

      mIsVirtualContext         ( false ),
      mVirtualContextHasChildren( false ),

      mpUserData( NULL )
{}

void spContext::RemoveChildren()
{
    for( size_t i = 0; i != mMembers.size(); ++i )

        delete mMembers[i];

    mMembers.erase( mMembers.begin(), mMembers.end() );
}

spContext::~spContext()
{
    RemoveChildren();

    for( size_t i = 0; i != mComments.size(); ++i )

        delete mComments[i];
}

bool spContext::IsSorted()
{
    return mAlreadySorted;
}

void spContext::GetContextList( MMemberListT& lst, int contextMask )
{
    for( size_t i = 0; i != mMembers.size(); ++i )
    {
        spContext& member = *mMembers[i];

        if ( member.GetContextType() & contextMask )

            lst.push_back( &member );

        // collect required contexts recursively
        member.GetContextList( lst, contextMask );
    }
}

bool spContext::HasComments()
{
    return ( mComments.size() != 0 );
}

void spContext::RemoveChild( spContext* pChild )
{
    for( size_t i = 0; i != mMembers.size(); ++i )

        if ( mMembers[i] == pChild )
        {
            mMembers.erase( &mMembers[i] );

            delete pChild;
            return;
        }

    // the given child should exist on the parent's list
    wxASSERT( 0 );
}

spContext* spContext::GetEnclosingContext( int mask )
{
    spContext* cur = this->GetParent();

    while ( cur && !(cur->GetContextType() & mask) )

        cur = cur->GetParent();

    return cur;
}

bool spContext::PositionIsKnown()
{
    return ( mSrcOffset != (-1) && mContextLength != (-1) );
}

bool spContext::IsVirtualContext()
{
    return mIsVirtualContext;
}

bool spContext::VitualContextHasChildren()
{
    return mVirtualContextHasChildren;
}

wxString spContext::GetVirtualContextBody()
{
    wxASSERT( mIsVirtualContext );

    return mVirtualContextBody;
}

wxString spContext::GetFooterOfVirtualContextBody()
{
    wxASSERT( mIsVirtualContext );

    return mVittualContextFooter;
}


void spContext::SetVirtualContextBody( const wxString& body,
                                       bool            hasChildren,
                                       const wxString& footer )
{
    mVirtualContextHasChildren = hasChildren;

    mVirtualContextBody   = body;
    mVittualContextFooter = footer;

    // atuomaticllay becomes virtual context

    mIsVirtualContext   = true;
}

wxString spContext::GetBody( spContext* pCtx )
{
    if ( ( pCtx == NULL || pCtx == this ) && mIsVirtualContext )
        return mVirtualContextBody;

    if ( GetParent() )
        return GetParent()->GetBody( ( pCtx != NULL ) ? pCtx : this );
    else
        return wxEmptyString; // source-fragment cannot be found
}

wxString spContext::GetHeader( spContext* pCtx )
{
    if ( GetParent() )
        return GetParent()->GetHeader( ( pCtx != NULL ) ? pCtx : this );
    else
        return wxEmptyString; // source-fragment cannot be found
}

bool spContext::IsFirstOccurence()
{
    return ( mpFirstOccurence != 0 );
}

spContext* spContext::GetFirstOccurence()
{
    // this object should not itself be
    // the first occurence of the context
    wxASSERT( mpFirstOccurence != 0 );

    return mpFirstOccurence;
}

void spContext::AddMember( spContext* pMember )
{
    mMembers.push_back( pMember );

    pMember->m_pParent = this;
}

void spContext::AddComment( spComment* pComment )
{
    mComments.push_back( pComment );
}

MMemberListT& spContext::GetMembers()
{
    return mMembers;
}

spContext* spContext::FindContext( const wxString& identifier,
                                   int   contextType,
                                   bool  searchSubMembers
                                 )
{
    for( size_t i = 0; i != mMembers.size(); ++i )
    {
        spContext& member = *mMembers[i];

        if ( member.GetName() == identifier &&
             ( contextType & member.GetContextType() )
           )

           return &member;

        if ( searchSubMembers )
        {
            spContext* result =
                member.FindContext( identifier, contextType, 1 );

            if ( result ) return result;
        }
    }

    return 0;
}

void spContext::RemoveThisContext()
{
    if ( m_pParent )
        m_pParent->RemoveChild( this );
    else
        // context should have a parent
        wxFAIL_MSG("Context should have a parent");
}

spContext* spContext::GetOutterContext()
{
    return m_pParent;
}

bool spContext::HasOutterContext()
{
    return ( m_pParent != 0 );
}

bool spContext::IsInFile()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -