// Created: 27/12/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
size_t spInterFileContext::GetFileNo( const string& fname )
{
- size_t i;
- for ( i = 0; i != mFiles.size(); ++i )
- if ( fname == mFiles[i] )
+ for ( size_t i = 0; i != mFiles.size(); ++i )
+ {
+ if ( fname == mFiles[i] )
return i;
+ }
wxFAIL_MSG("File not found in array in function spInterFileContext::GetFileNo()");
- return 0;
+
+ return 0;
}
size_t spInterFileContext::GetFileNoOfContext( spContext& ctx )
{
- spContext* pCtx = ctx.GetEnclosingContext( SP_CTX_FILE );
+ spContext* pCtx = ctx.GetEnclosingContext( SP_CTX_FILE );
- // DBG:: outer-file context should be present
- wxASSERT( pCtx && pCtx->GetType() == SP_CTX_FILE );
+ // DBG:: outer-file context should be present
+ wxASSERT( pCtx && pCtx->GetType() == SP_CTX_FILE );
- return GetFileNo( ((spFile*)pCtx)->mFileName );
+ return GetFileNo( ((spFile*)pCtx)->mFileName );
}
/*** public interface ***/
void spInterFileContext::AddFile( const string& fname, const string& content )
{
- mFiles.push_back( fname );
- mContents.push_back( content );
+ mFiles.push_back( fname );
+ mContents.push_back( content );
}
void spInterFileContext::RemoveContext( spContext& ctx )
{
- wxASSERT( ctx.PositionIsKnown() ); // DBG:: should be checked by-user code
+ wxASSERT( ctx.PositionIsKnown() ); // DBG:: should be checked by-user code
- size_t fNo = GetFileNoOfContext( ctx );
+ size_t fNo = GetFileNoOfContext( ctx );
- mDeletionMarks.push_back( spBookmark( ctx.mSrcOffset, ctx.mContextLength, fNo ) );
+ mDeletionMarks.push_back( spBookmark( ctx.mSrcOffset, ctx.mContextLength, fNo ) );
}
void spInterFileContext::InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark )
{
- for( size_t i = 0; i != lst.size(); ++i )
-
- if ( lst[i].mFrom > mark.mFrom )
- {
- lst.insert( &lst[i], mark );
- return;
- }
+ for( size_t i = 0; i != lst.size(); ++i )
- lst.push_back( mark );
-}
+ if ( lst[i].mFrom > mark.mFrom )
+ {
+ lst.insert( &lst[i], mark );
+ return;
+ }
+
+ lst.push_back( mark );
+}
void spInterFileContext::DoAppendSourceFragment( string& source,
- string& result,
- size_t pos, size_t len )
+ string& result,
+ size_t pos, size_t len )
{
- mFiltered.erase( mFiltered.begin(), mFiltered.end() );
+ mFiltered.erase( mFiltered.begin(), mFiltered.end() );
- size_t i;
+ size_t i;
+
+ for( i = 0; i != mDeletionMarks.size(); ++i )
+ {
+ spBookmark& mark = mDeletionMarks[i];
- for( i = 0; i != mDeletionMarks.size(); ++i )
- {
- spBookmark& mark = mDeletionMarks[i];
+ if ( mark.mFileNo == mCurFileNo &&
+ mark.mFrom >= pos && mark.mFrom < pos + len )
- if ( mark.mFileNo == mCurFileNo &&
- mark.mFrom >= pos && mark.mFrom < pos + len )
-
- InsertBookmarkSorted( mFiltered, mark );
- }
+ InsertBookmarkSorted( mFiltered, mark );
+ }
- size_t cur = pos;
-
- for( i = 0; i != mFiltered.size(); ++ i )
- {
- spBookmark& mark = mFiltered[i];
+ size_t cur = pos;
- result.append( source, cur, ( (size_t)mark.mFrom - cur ) );
+ for( i = 0; i != mFiltered.size(); ++ i )
+ {
+ spBookmark& mark = mFiltered[i];
- cur = size_t( mark.mFrom + mark.mLen );
+ result.append( source, cur, ( (size_t)mark.mFrom - cur ) );
- if ( cur >= pos + len ) // check if we've overstepped the current source-fragment
- {
-// wxASSERT(0); // DBG:: with current imp. this should not happen
- wxFAIL_MSG("Overstepped the current source fragment in function\nspInterFileContext::DoAppendSourceFragment()");
- cur = pos + len; break;
- }
- }
+ cur = size_t( mark.mFrom + mark.mLen );
- result.append( source, cur, ( pos + len ) - cur );
+ if ( cur >= pos + len ) // check if we've overstepped the current source-fragment
+ {
+// wxASSERT(0); // DBG:: with current imp. this should not happen
+ wxFAIL_MSG("Overstepped the current source fragment in function\nspInterFileContext::DoAppendSourceFragment()");
+ cur = pos + len; break;
+ }
+ }
+
+ result.append( source, cur, ( pos + len ) - cur );
}
void spInterFileContext::GenerateContextBody( spContext& ctx,
- string& source,
- string& result,
- size_t& lastSavedPos,
- size_t& lastKnownPos )
+ string& source,
+ string& result,
+ size_t& lastSavedPos,
+ size_t& lastKnownPos )
{
- if ( ctx.PositionIsKnown() )
-
- lastKnownPos = ctx.mSrcOffset;
+ if ( ctx.PositionIsKnown() )
+ lastKnownPos = ctx.mSrcOffset;
- if ( ctx.IsVirtualContext() )
- {
- // add fragment accumulated before this context
+ if ( ctx.IsVirtualContext() )
+ {
+ // add fragment accumulated before this context
- DoAppendSourceFragment( source, result,
- size_t(lastSavedPos),
- size_t(lastKnownPos - lastSavedPos) );
+ DoAppendSourceFragment( source, result,
+ size_t(lastSavedPos),
+ size_t(lastKnownPos - lastSavedPos) );
- // add context body
+ // add context body
- result += ctx.GetVirtualContextBody();
+ result += ctx.GetVirtualContextBody();
- lastSavedPos = lastKnownPos;
+ lastSavedPos = lastKnownPos;
- if ( ctx.PositionIsKnown() )
- {
- if ( ctx.VitualContextHasChildren() )
- {
- lastKnownPos = ctx.mSrcOffset + ctx.mHeaderLength;
+ if ( ctx.PositionIsKnown() )
+ {
+ if ( ctx.VitualContextHasChildren() )
+ {
+ lastKnownPos = ctx.mSrcOffset + ctx.mHeaderLength;
- lastSavedPos = lastKnownPos;
- }
- else
- {
- lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
+ lastSavedPos = lastKnownPos;
+ }
+ else
+ {
+ lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
- lastSavedPos = lastKnownPos;
+ lastSavedPos = lastKnownPos;
- return; // have not children
- }
- }
- }
+ return; // have not children
+ }
+ }
+ }
- MMemberListT& lst = ctx.GetMembers();
+ MMemberListT& lst = ctx.GetMembers();
- for( size_t i = 0; i != lst.size(); ++i )
-
- GenerateContextBody( *lst[i], source, result, lastSavedPos, lastKnownPos );
-
- if ( ctx.IsVirtualContext() )
- {
- if ( ctx.VitualContextHasChildren() &&
+ for( size_t i = 0; i != lst.size(); ++i )
+ {
+ GenerateContextBody( *lst[i], source, result, lastSavedPos, lastKnownPos );
+ }
- ctx.GetFooterOfVirtualContextBody() != "" )
- {
- // append the reminder space after children of the context
+ if ( ctx.IsVirtualContext() )
+ {
+ if ( ctx.VitualContextHasChildren() && !ctx.GetFooterOfVirtualContextBody().empty() )
+ {
+ // append the reminder space after children of the context
- DoAppendSourceFragment( result, source,
- size_t(lastSavedPos),
- size_t(lastKnownPos - lastSavedPos) );
+ DoAppendSourceFragment( result, source,
+ size_t(lastSavedPos),
+ size_t(lastKnownPos - lastSavedPos) );
- // add footer
- result += ctx.GetFooterOfVirtualContextBody();
+ // add footer
+ result += ctx.GetFooterOfVirtualContextBody();
- lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
+ lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
- lastSavedPos = lastKnownPos;
- }
- }
+ lastSavedPos = lastKnownPos;
+ }
+ }
- if ( ctx.PositionIsKnown() )
+ if ( ctx.PositionIsKnown() )
- lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
+ lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
}
void spInterFileContext::GenrateContents()
{
- MMemberListT& lst = GetMembers();
+ MMemberListT& lst = GetMembers();
- for( size_t f = 0; f != lst.size(); ++f )
- {
- string& fname = ((spFile*)lst[f])->mFileName;
+ for( size_t f = 0; f != lst.size(); ++f )
+ {
+ string& fname = ((spFile*)lst[f])->mFileName;
- size_t fileNo = GetFileNo( fname );
+ size_t fileNo = GetFileNo( fname );
- string& source = mContents[ fileNo ];
+ string& source = mContents[ fileNo ];
- string result;
+ string result;
- size_t lastKnownPos = 0, // the begining of the file is always "known"
- lastSavedPos = 0;
+ size_t lastKnownPos = 0, // the begining of the file is always "known"
+ lastSavedPos = 0;
- mCurFileNo = fileNo;
+ mCurFileNo = fileNo;
- GenerateContextBody( *lst[f], source, result, lastSavedPos, lastKnownPos );
+ GenerateContextBody( *lst[f], source, result, lastSavedPos, lastKnownPos );
- // the end of file is always known
+ // the end of file is always known
- lastKnownPos = mContents[ fileNo ].length();
+ lastKnownPos = mContents[ fileNo ].length();
- // append the reminder
+ // append the reminder
- DoAppendSourceFragment( source, result,
- size_t(lastSavedPos),
- size_t(lastKnownPos - lastSavedPos) );
+ DoAppendSourceFragment( source, result,
+ size_t(lastSavedPos),
+ size_t(lastKnownPos - lastSavedPos) );
- // replace original contnet with newly generated one
+ // replace original contnet with newly generated one
- mContents[ fileNo ] = result;
- }
+ mContents[ fileNo ] = result;
+ }
}
void spInterFileContext::ParseContents( SourceParserPlugin* pPlugin )
{
- mDeletionMarks.erase( mDeletionMarks.begin(), mDeletionMarks.end() );
+ mDeletionMarks.erase( mDeletionMarks.begin(), mDeletionMarks.end() );
- RemoveChildren(); // clean up top-level context
+ RemoveChildren(); // clean up top-level context
- mParser.SetPlugin( pPlugin );
+ mParser.SetPlugin( pPlugin );
- for( size_t i = 0; i != mFiles.size(); ++i )
- {
- char* s = (char*)(mContents[i].c_str());
+ for( size_t i = 0; i != mFiles.size(); ++i )
+ {
+ char* s = (char*)(mContents[i].c_str());
- spFile* pFCtx = mParser.Parse( s, s + mContents[i].length() );
+ spFile* pFCtx = mParser.Parse( s, s + mContents[i].length() );
- pFCtx->mFileName = mFiles[i];
+ pFCtx->mFileName = mFiles[i];
- AddMember( pFCtx );
- }
+ AddMember( pFCtx );
+ }
}
void spInterFileContext::WriteToFiles()
{
- for( size_t i = 0; i != mFiles.size(); ++i )
- {
- FILE* fp = fopen( mFiles[i].c_str(), "w+t" );
+ for( size_t i = 0; i != mFiles.size(); ++i )
+ {
+ FILE* fp = fopen( mFiles[i].c_str(), "w+t" );
- if ( fp != NULL )
- {
- fwrite( mContents[i].c_str(), sizeof(char), mContents[i].length(), fp );
+ if ( fp != NULL )
+ {
+ fwrite( mContents[i].c_str(), sizeof(char), mContents[i].length(), fp );
- fclose( fp );
- }
- }
+ fclose( fp );
+ }
+ }
}
-string spInterFileContext::GetBody( spContext* pCtx )
+wxString spInterFileContext::GetBody( spContext* pCtx )
{
- wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code
+ wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code
- string& source = mContents[ GetFileNoOfContext( *pCtx ) ];
+ wxString& source = mContents[ GetFileNoOfContext( *pCtx ) ];
- return string( source.c_str() + pCtx->mSrcOffset, pCtx->mContextLength );
+ return wxString( source.c_str() + pCtx->mSrcOffset, pCtx->mContextLength );
}
-string spInterFileContext::GetHeader( spContext* pCtx )
+wxString spInterFileContext::GetHeader( spContext* pCtx )
{
- wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code
+ wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code
- wxASSERT( pCtx->mHeaderLength != -1 ); // DBG:: -/-
+ wxASSERT( pCtx->mHeaderLength != -1 ); // DBG:: -/-
- string& source = mContents[ GetFileNoOfContext( *pCtx ) ];
+ wxString& source = mContents[ GetFileNoOfContext( *pCtx ) ];
- return string( source.c_str() + pCtx->mSrcOffset, pCtx->mHeaderLength );
+ return wxString( source.c_str() + pCtx->mSrcOffset, pCtx->mHeaderLength );
}
// Created: 27/12/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __IFCONTEXT_G__
class spBookmark
{
public:
- size_t mFrom;
- size_t mLen;
- size_t mFileNo;
+ size_t mFrom;
+ size_t mLen;
+ size_t mFileNo;
- inline spBookmark() {}
+ inline spBookmark() {}
- inline spBookmark( int from, int len, int fileNo )
- : mFrom( from ), mLen( len ), mFileNo( fileNo )
- {}
+ inline spBookmark( int from, int len, int fileNo )
+ : mFrom( from ), mLen( len ), mFileNo( fileNo )
+ {}
};
#if defined( wxUSE_TEMPLATE_STL )
- typedef vector<spBookmark) BookmarkListT
+ typedef vector<spBookmark) BookmarkListT
#else
- typedef WXSTL_VECTOR_SHALLOW_COPY(spBookmark) BookmarkListT;
+ typedef WXSTL_VECTOR_SHALLOW_COPY(spBookmark) BookmarkListT;
#endif
{
protected:
- BookmarkListT mDeletionMarks;
+ BookmarkListT mDeletionMarks;
- BookmarkListT mFiltered;
+ BookmarkListT mFiltered;
- size_t mCurFileNo;
+ size_t mCurFileNo;
- CJSourceParser mParser;
+ CJSourceParser mParser;
protected:
- size_t GetFileNoOfContext( spContext& ctx );
- size_t GetFileNo( const string& fname );
+ size_t GetFileNoOfContext( spContext& ctx );
+ size_t GetFileNo( const string& fname );
- void InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark );
+ void InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark );
- void DoAppendSourceFragment( string& source,
- string& result,
- size_t pos, size_t len );
+ void DoAppendSourceFragment( string& source,
+ string& result,
+ size_t pos, size_t len );
- void GenerateContextBody( spContext& ctx,
- string& source,
- string& result,
- size_t& lastSavedPos,
- size_t& lastKnownPos );
+ void GenerateContextBody( spContext& ctx,
+ string& source,
+ string& result,
+ size_t& lastSavedPos,
+ size_t& lastKnownPos );
public:
- StrListT mFiles;
- StrListT mContents;
+ StrListT mFiles;
+ StrListT mContents;
public:
- spInterFileContext();
- ~spInterFileContext();
+ spInterFileContext();
+ ~spInterFileContext();
- void AddFile( const string& fname, const string& content );
+ void AddFile( const string& fname, const string& content );
- void RemoveContext( spContext& ctx );
+ void RemoveContext( spContext& ctx );
- void GenrateContents();
+ void GenrateContents();
- void ParseContents( SourceParserPlugin* pPlugin = NULL );
+ void ParseContents( SourceParserPlugin* pPlugin = NULL );
- void WriteToFiles();
+ void WriteToFiles();
- // overriden method of the base class (finds out the source fragment)
+ // overriden method of the base class (finds out the source fragment)
- virtual string GetBody( spContext* pCtx = NULL );
+ virtual wxString GetBody( spContext* pCtx = NULL );
- virtual string GetHeader( spContext* pCtx = NULL );
+ virtual wxString GetHeader( spContext* pCtx = NULL );
};