Click here to Skip to main content
15,894,176 members
Articles / Programming Languages / C++

Morefast Doc-Comments Maker

Rate me:
Please Sign up or sign in to vote.
4.50/5 (9 votes)
5 Dec 20022 min read 46.9K   1.1K   21  
This Add-In Is About Easy File/Function Commenting ...
// CommentFileReader.cpp: implementation of the CCommentFileReader class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CPPCWiz.h"
#include "CommentFileReader.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCommentFileReader::CCommentFileReader()
{
	m_strCommentFilePath = "";
	m_strCommentFilePath	 = "Commtempl.txt";

	m_strFileCommentStart = "[FILE COMMENT]";
	m_strFileCommentEnd = "[~FILE COMMENT]";
	m_strFuncCommentStart = "[FUNCTION COMMENT]";
	m_strFuncCommentEnd = "[~FUNCTION COMMENT]";
	m_strCLogCommentStart = "[CHANGELOG COMMENT]";
	m_strCLogCommentEnd = "[~CHANGELOG COMMENT]";
}

CCommentFileReader::~CCommentFileReader()
{

}
// ____________________________________________________________________________
//
// Class:       CCommentFileReader
//
// Method:      ReadAndParseFile
//
// Purpose:     Read Given File. Parse it and fill all data structure in class
//              like m_strFileComment,m_strFuncComment etc..
//
// Arguments:   fileName : FileName As String to parse file
//
// Returns:     VOID
//
// ____________________________________________________________________________
VOID CCommentFileReader::ReadAndParseFile(CString fileName)
{
	CString strFileName = m_strCommentFileFullPath + "\\" ;
	strFileName = strFileName + fileName;
	ReadFile( strFileName );
	ParseFile( );
}



//////////////////////////////////////////////////////////////////////////
//[9/4/2002 : MANISH] : Private Functions... 


VOID CCommentFileReader::ReadFile(CString fileName)
{
	ASSERT(fileName!="");

	/*
	 *	Check Status Of File - Wheather it is readable or not.
	 */
	CFileStatus OStatus;
	BOOL bCanRead = CFile::GetStatus(fileName,OStatus);

	if( bCanRead )
	{
		/*
		 *	Read Whole File To CString Object ( strFileContent )
		 */
		
		m_strCommentFilePath = CString(OStatus.m_szFullName);
		CFile OFileToRead(fileName,CFile::modeRead);
		
		INT iFileLength = OFileToRead.GetLength();

		OFileToRead.ReadHuge(m_strFileData.GetBuffer(iFileLength),iFileLength);
		m_strFileData.ReleaseBuffer(iFileLength);
		OFileToRead.Close();
		
	}
}

VOID CCommentFileReader::ParseFile()
{
	m_strFileComment = ParseCommentTemplate(m_strFileCommentStart,m_strFileCommentEnd);
	//AfxMessageBox(m_strFileComment);
	m_strFuncComment = ParseCommentTemplate(m_strFuncCommentStart,m_strFuncCommentEnd);
	//AfxMessageBox(m_strFuncComment);
	m_strCLogComment = ParseCommentTemplate(m_strCLogCommentStart,m_strCLogCommentEnd);

}

CString CCommentFileReader::ParseCommentTemplate(CString startString, CString endString)
{
	INT iCommentStart = m_strFileData.Find(startString,0);
	INT iCommentEnd = iCommentStart+1;

	CString retStrComment;

	if( iCommentStart >= 0 )
	{
		iCommentStart = iCommentStart + startString.GetLength();
		
		iCommentEnd = m_strFileData.Find(endString,iCommentStart);

		if( iCommentEnd > iCommentStart)
		{
			retStrComment = m_strFileData.Mid(iCommentStart, (iCommentEnd - iCommentStart) );
		}
		else
		{
			retStrComment = "NOT FOUND IN FILE";
		}
	}
	return retStrComment;
}

CString CCommentFileReader::GetFileComment()
{
	return m_strFileComment;
}

VOID CCommentFileReader::ReparseFile()
{
	ReadAndParseFile(m_strCommentFilePath);
}

CString CCommentFileReader::GetCommentFilePath()
{
	return (m_strCommentFilePath);
}

CString CCommentFileReader::GetFuncComment()
{
	return m_strFuncComment;
}

CString CCommentFileReader::GetCLogComment()
{
	return m_strCLogComment;
}

VOID CCommentFileReader::SetPath(CString path)
{
	m_strCommentFileFullPath = path ;
	//m_strCommentFileFullPath = m_strCommentFileFullPath + m_strCommentFilePath ;
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder IntelliPro Solutions Pvt. Ltd.
India India
A 8 or something in .NET, living in Ahmedabad, India owned IntelliPro Solutions Pvt. Ltd..

Currently working on .NET technologies, MVC and Silverlight.

My little blog is for helping community with the solution for problems or helping them to understand new technology. You can reach to my blog at http://maniish.wordpress.com.

To contact me, post comment here or email me at manish AT iprospl.com
This is a Organisation (No members)


Comments and Discussions