|
/* ==========================================================================
File : Function.cpp
Class : CFunction
Date : 06/16/04
Purpose : "CFunction", derived from "CObject", represents a single
class function in a cpp-file.
Description : The class contains data members as well as functionality
to generate the function information to a HTML-file. The
"CFunction"-class is derived from "CObject" to be able
to put them in the "CFunctionArray" "CObArray"-member.
Usage : Allocate from the heap and add to the "CFunctionArray"
using "CFunctionArray::Add".
========================================================================*/
#include "stdafx.h"
#include "Function.h"
#include "Tokenizer/Tokenizer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void AddCode( CString& str )
{
_TCHAR delimiter = _TCHAR( '\"' );
int found = str.Find( delimiter );
BOOL left = TRUE;
CString result;
CString code;
while( found != -1 )
{
if( left )
{
code = _T( "<code>" );
left = FALSE;
}
else
{
code = _T( "</code>" );
left = TRUE;
}
CString str1 = str.Left( found );
str = str.Right( str.GetLength() - ( found + 1 ) );
result += str1 + code;
found = str.Find( delimiter );
}
result += str;
str = result;
}
////////////////////////////////////////////////////////////////////
// Public functions
//
CFunction::CFunction( )
/* ============================================================
Function : CFunction::CFunction
Description : Constructor
Access : Public
Return : void
Parameters : none
Usage : The class should be managed by a
"CFunctionArray".
============================================================*/
{
}
CFunction::~CFunction( )
/* ============================================================
Function : CFunction::~CFunction
Description : Destructor
Access : Public
Return : void
Parameters : none
Usage : The class should be managed by a
"CFunctionArray".
============================================================*/
{
}
void CFunction::Generate( CStringArray & stra ) const
/* ============================================================
Function : CFunction::Generate
Description : Generates documentation for this function
to "stra".
Access : Public
Return : void
Parameters : CStringArray & stra - Array to generate to.
Usage : Call to generate HTML for this instance.
============================================================*/
{
CString functionname;
functionname.Format( _T( "<code><b><a name='%s'></a>%s%s</b></code>" ), GetLinkName(), GetFunctionReturn(), GetFunctionName() );
CString description = GetDescription();
CString parameters = GetParameters();
CString returns = GetReturns();
CString usage = GetUsage();
if( description.IsEmpty() )
description = _T( "-" );
if( parameters.IsEmpty() )
parameters = _T( "-" );
if( returns.IsEmpty() )
returns = _T( "-" );
if( usage.IsEmpty() )
usage = _T( "-" );
if( parameters.GetLength() > 1 )
{
CTokenizer tok( parameters, _T( "\n" ) );
int max = tok.GetSize();
parameters = _T( "" );
for( int t = 0 ; t < max ; t++ )
{
CString value;
CString type;
CString desc;
tok.GetAt( t, value );
int found = value.Find( _T( "-" ) );
if( found != -1 )
{
type = value.Left( found );
desc = value.Right( value.GetLength() - ( found + 1 ) );
parameters += _T( "<code>" ) + type + _T( "</code> - " ) + desc + _T( "<br>" );
}
else
parameters += value + _T( "<br>" );
}
}
if( returns.GetLength() > 1 )
{
int found = returns.Find( _T( "-" ) );
if( found != -1 )
{
CString type;
CString desc;
type = returns.Left( found );
desc = returns.Right( returns.GetLength() - ( found + 1 ) );
returns = _T( "<code>" ) + type + _T( "</code> - " ) + desc;
}
}
CTokenizer use( usage, _T( "#" ) );
int max = use.GetSize();
if( max > 1 )
{
use.GetAt( 0, usage );
usage += _T( "<p><table width='100%'>" );
CString value;
for( int t = 1 ; t < max ; t++ )
{
use.GetAt( t, value );
int found = value.Find( _T( " " ) );
if( found != -1 )
{
CString type;
CString desc;
type = value.Left( found );
desc = value.Right( value.GetLength() - ( found +1 ) );
usage += _T( "<tr><td>" ) + type + _T( "</td><td>" ) + desc + _T( "</td></tr>" );
}
}
usage += _T( "</table>" );
}
usage += _T( "<p>" );
stra.Add( functionname );
stra.Add( _T( "<blockquote>" ) );
stra.Add( _T( "<b>Description</b><br>" ) );
stra.Add( description );
stra.Add( _T( "<br><b>Access</b><br>" ) );
stra.Add( GetAccess() );
stra.Add( _T( "<br><br><b>Parameters</b><br>" ) );
stra.Add( parameters );
stra.Add( _T( "<b>Returns</b><br>" ) );
stra.Add( returns );
stra.Add( _T( "<br><br><b>Usage</b><br>" ) );
stra.Add( usage );
stra.Add( _T( "<a class='top' href='#contents'>[back to the contents]</a> <a class='top' href='index.html'>[back to the index page]</a></p>" ) );
stra.Add( _T( "</blockquote>" ) );
}
CString CFunction::GetDescription( ) const
/* ============================================================
Function : CFunction::GetDescription
Description : Accessor. Getter for "m_description".
Access : Public
Return : CString
Parameters : none
Usage : Call to get the description field from the
function header.
============================================================*/
{
return m_description;
}
void CFunction::SetDescription( CString value )
/* ============================================================
Function : CFunction::SetDescription
Description : Accessor. Setter for "m_description"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the description field of the
function header.
============================================================*/
{
value.TrimLeft();
value.TrimRight();
value.Replace( _T( "<" ), _T( "<" ) );
value.Replace( _T( ">" ), _T( ">" ) );
AddCode( value );
m_description = value;
}
CString CFunction::GetReturns( ) const
/* ============================================================
Function : CFunction::GetReturns
Description : Accessor. Getter for "m_returns"
Access : Public
Return : CString - Return value
Parameters : none
Usage : Call to get the return value (and the
description of it) for this function.
============================================================*/
{
return m_returns;
}
void CFunction::SetReturns( CString value )
/* ============================================================
Function : CFunction::SetReturns
Description : Accessor. Setter for "m_returns"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the return value and
description of this function.
============================================================*/
{
value.TrimLeft();
value.Replace( _T( "<" ), _T( "<" ) );
value.Replace( _T( ">" ), _T( ">" ) );
AddCode( value );
m_returns = value;
}
CString CFunction::GetParameters( ) const
/* ============================================================
Function : CFunction::GetParameters
Description : Accessor. Getter for "m_parameters"
Access : Public
Return : CString - The parameter list
Parameters : none
Usage : Call to get the parameterlist for this
function.
============================================================*/
{
return m_parameters;
}
void CFunction::SetParameters( CString value )
/* ============================================================
Function : CFunction::SetParameters
Description : Accessor. Setter for "m_parameters"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the parameter list for this
function.
============================================================*/
{
value.TrimLeft();
value.Replace( _T( "<" ), _T( "<" ) );
value.Replace( _T( ">" ), _T( ">" ) );
AddCode( value );
m_parameters = value;
}
CString CFunction::GetUsage( ) const
/* ============================================================
Function : CFunction::GetUsage
Description : Accessor. Getter for "m_usage"
Access : Public
Return : CString - The usage field
Parameters : none
Usage : Call to get this field for the function
(:-))
============================================================*/
{
return m_usage;
}
void CFunction::SetUsage( CString value )
/* ============================================================
Function : CFunction::SetUsage
Description : Accessor. Setter for "m_usage"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set this field for the function.
============================================================*/
{
value.TrimLeft();
value.TrimRight();
value.Replace( _T( "<" ), _T( "<" ) );
value.Replace( _T( ">" ), _T( ">" ) );
AddCode( value );
m_usage = value;
}
CString CFunction::GetFunctionName( ) const
/* ============================================================
Function : CFunction::GetFunctionName
Description : Accessor. Getter for "m_functionName"
Access : Public
Return : CString - Function name
Parameters : none
Usage : Call to get the name of this function.
============================================================*/
{
return m_functionName;
}
void CFunction::SetFunctionName( CString value )
/* ============================================================
Function : CFunction::SetFunctionName
Description : Accessor. Setter for "m_functionName"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the name of this function.
============================================================*/
{
value.TrimLeft();
m_functionName = value;
SetLinkName( value );
}
CString CFunction::GetFunctionReturn( ) const
/* ============================================================
Function : CFunction::GetFunctionReturn
Description : Accessor. Getter for "m_functionReturn"
Access : Public
Return : CString - Return type
Parameters : none
Usage : Call to get the return type of this
function.
============================================================*/
{
return m_functionReturn;
}
void CFunction::SetFunctionReturn( CString value )
/* ============================================================
Function : CFunction::SetFunctionReturn
Description : Accessor. Setter for "m_functionReturn"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the return type for this
function.
============================================================*/
{
value.TrimLeft();
m_functionReturn = value;
}
CString CFunction::GetLinkName( ) const
/* ============================================================
Function : CFunction::GetLinkName
Description : Accessor. Getter for "m_linkName"
Access : Public
Return : CString - Mangled name
Parameters : none
Usage : Call to get the mangled name for this
function. The mangled name is the name of
the function and all the parameters sans
non-alphabetic characters. It is necessary
to create links - as several functions can
have the same name.
============================================================*/
{
return m_linkName;
}
void CFunction::SetLinkName( CString value )
/* ============================================================
Function : CFunction::SetLinkName
Description : Accessor. Setter for "m_linkName"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the link name of this function.
The link name is the name and parameters of
the functions sans non-alphabetical
characters.
============================================================*/
{
value.TrimLeft();
value.TrimRight();
value.Remove( _TCHAR( ' ' ) );
value.Remove( _TCHAR( '(' ) );
value.Remove( _TCHAR( ')' ) );
value.Remove( _TCHAR( ',' ) );
value.Remove( _TCHAR( '*' ) );
value.Remove( _TCHAR( '&' ) );
value.Remove( _TCHAR( '=' ) );
value.Remove( _TCHAR( ';' ) );
value.Remove( _TCHAR( '\"' ) );
value.Remove( _TCHAR( '\'' ) );
m_linkName = value;
}
CString CFunction::GetAccess( ) const
/* ============================================================
Function : CFunction::GetAccess
Description : Accessor. Getter for "m_access"
Access : Public
Return : CString - Access specifier
Parameters : none
Usage : Call to get the visibility of the function.
============================================================*/
{
return m_access;
}
void CFunction::SetAccess( CString value )
/* ============================================================
Function : CFunction::SetAccess
Description : Accessor. Setter for "m_access"
Access : Public
Return : void
Parameters : CString value - New value
Usage : Call to set the visibility of the function.
============================================================*/
{
value.TrimLeft();
value.TrimRight();
m_access = value;
}
|
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.