|
/* ==========================================================================
File : FunctionArray.cpp
Class : CFunctionArray
Date : 06/16/04
Purpose : "CFunctionArray" manages an array of functions from the
current cpp-file.
Description : The class contains a "CObArray" holding instances of
"CFunction". It also contains functions to access and
generate documentation.
Usage : Used by the "CDocumentationGenerator"-class. Will
delete all associated memory.
========================================================================*/
#include "stdafx.h"
#include "FunctionArray.h"
#include "Function.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////
// Public functions
//
CFunctionArray::CFunctionArray( )
/* ============================================================
Function : CFunctionArray::CFunctionArray
Description : Constructor
Access : Public
Return : void
Parameters : none
Usage :
============================================================*/
{
}
CFunctionArray::~CFunctionArray( )
/* ============================================================
Function : CFunctionArray::~CFunctionArray
Description : Destructor
Access : Public
Return : void
Parameters : none
Usage : Deletes all memory.
============================================================*/
{
RemoveAll();
}
void CFunctionArray::Add( CFunction * function )
/* ============================================================
Function : CFunctionArray::Add
Description : Adds a function to the array.
Access : Public
Return : void
Parameters : CFunction * function - Function to add.
Usage : Call to add a "CFunction" to the array. The
class takes ownership of the memory.
============================================================*/
{
m_functions.Add( function );
}
int CFunctionArray::GetSize( ) const
/* ============================================================
Function : CFunctionArray::GetSize
Description : Gets the number of functions in the array.
Access : Public
Return : int - The number of functions.
Parameters : none
Usage : Call to get the number of functions in the
array.
============================================================*/
{
int result;
result = m_functions.GetSize();
return result;
}
void CFunctionArray::RemoveAt( int index )
/* ============================================================
Function : CFunctionArray::RemoveAt
Description : Removes the function at "index".
Access : Public
Return : void
Parameters : int index - Index to remove function at.
Usage : Releases memory as well.
============================================================*/
{
CFunction* object = GetAt( index );
if( object )
{
m_functions.RemoveAt( index );
delete object;
}
}
void CFunctionArray::RemoveAll( )
/* ============================================================
Function : CFunctionArray::RemoveAll
Description : Removes all functions in the array.
Access : Public
Return : void
Parameters : none
Usage : Will also delete memory.
============================================================*/
{
while( GetSize() )
RemoveAt( 0 );
}
////////////////////////////////////////////////////////////////////
// Private functions
//
CFunction* CFunctionArray::GetAt( int index ) const
/* ============================================================
Function : CFunctionArray::GetAt
Description : Gets the function at "index"
Access : Public
Return : CFunction* - The function, or "NULL" if
out of bounds.
Parameters : int index - The index to get the
function for.
Usage : Call to get a pointer to a function.
============================================================*/
{
CFunction* result = NULL;
if( index < GetSize() )
result = static_cast< CFunction* >( m_functions.GetAt( index ) );
return result;
}
void CFunctionArray::Generate( CStringArray & stra )
/* ============================================================
Function : CFunctionArray::Generate
Description : Generates HTML-documentation for all the
functions in the array to "stra".
Access : Public
Return : void
Parameters : CStringArray & stra -
Usage : Call to generate documentation for the
functions.
============================================================*/
{
Sort();
CString name;
CString oldname;
for( int t = 0 ; t < GetSize() ; t++ )
{
name = GetAt( t )->GetFunctionName();
if( oldname.GetLength() && oldname[ 0 ] != name[ 0 ] )
{
CString delim;
stra.Add( _T( "<p>" ) );
delim.Format( _T( "<b>- %c -</b><br>" ), name[ 0 ] );
stra.Add( delim );
}
else if( oldname.IsEmpty() && name.GetLength() )
{
CString delim;
delim.Format( _T( "<b>- %c -</b><br>" ), name[ 0 ] );
stra.Add( delim );
}
CString link;
link.Format( _T( "<a href='#%s'>%s</a><br>" ), GetAt( t )->GetLinkName(), name );
stra.Add( link );
oldname = name;
}
stra.Add( _T( "<p><h3>Functions</h3><hr>" ) );
for( t = 0 ; t < GetSize() ; t++ )
{
GetAt( t )->Generate( stra );
stra.Add( _T( "<hr>" ) );
}
}
void CFunctionArray::Sort()
/* ============================================================
Function : CFunctionArray::Sort
Description : Sorts the function list - alphabetical
order on the function names.
Access : Private
Return : void
Parameters : none
Usage : Call to sort the function list.
============================================================*/
{
int max = GetSize();
CFunction* obj1 = NULL;
CFunction* obj2 = NULL;
BOOL sorting = TRUE;
while( sorting )
{
sorting = FALSE;
for( int t = 0; t < max - 1 ; t++ )
{
obj1 = GetAt( t );
obj2 = GetAt( t + 1 );
if( obj1->GetFunctionName() > obj2->GetFunctionName() )
{
m_functions.SetAt( t, obj2 );
m_functions.SetAt( t + 1, obj1 );
sorting = TRUE;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
45 years old, married, three kids.
Started with computers more than 20 years ago on a CBM-64.
Read Theoretical Philosophy at the University of Lund.
Working as a C++ consultant developer.
Science-fiction freak. Enjoy vintage punkrock.