Click here to Skip to main content
15,896,207 members
Articles / Programming Languages / C++

ToDoList Add-on

Rate me:
Please Sign up or sign in to vote.
4.69/5 (6 votes)
20 Apr 2002CPOL3 min read 242.4K   2.9K   57  
A Visual Studio add-in to help navigate to TODO:, TASK: etc comments, as well as showing STL containers in debug mode such as std::string, std::list etc
/********************************************************************\
	created:		2001/03/04
	created:		4:3:2001   14:33
	filename: 	Parser\prsMulti.cpp
	file path:	.\Parser
	file base:	prsMulti
	file ext:		cpp
	author:			Alex Kucherenko
	
	purpose:	
\********************************************************************/

#include "stdafx.h"

// Disable some warnings while using STL
#pragma warning (disable : 4800 4290 4786 4503 4100 4511 )

#include "prsExceptions.h"
#include "prsBase.h"
#include "prsSingle.h"
#include "prsMulti.h"

#include "prsMultiLine.h"

//////////////////////////////////////////////////////////////////////////
// Constructor of our Multy parser class without params ( default constructor )

CToDoMultiParse::CToDoMultiParse( ) : 
  CToDoBaseParser(), 
  m_lCounter(0)
{

}

//////////////////////////////////////////////////////////////////////////
// Constructor which set FileName to class

CToDoMultiParse::CToDoMultiParse( const string &FileName ) : 
  CToDoBaseParser( FileName ),
  m_lCounter(0)
{

}

//////////////////////////////////////////////////////////////////////////
// constructor which set File name and Array of search words

CToDoMultiParse::CToDoMultiParse( const string &FileName, const TStrArray &Search ) :
  CToDoBaseParser( FileName ),
  m_lCounter(0)
{
  m_strSearch = Search;
}

//////////////////////////////////////////////////////////////////////////
// Function return ToDoSingleParse object which according to integer number
// in array of search words

CToDoSingleParse CToDoMultiParse::GetResults( const UINT Search ) throw( CToDoNoElements )
{
  if( m_mapSearch.empty() ) 
    throw CToDoNoElements();

  if( ( Search < 0 ) || ( Search > m_mapSearch.size()-1 ) ) 
    throw CToDoNoElements();
  
  return GetResults( m_strSearch[Search] );
}

//////////////////////////////////////////////////////////////////////////
// Function return ToDoSingleParse object which according to keyword in 
// array of search words

CToDoSingleParse CToDoMultiParse::GetResults( const string &Search ) throw( CToDoNoElements )
{
  if( m_mapSearch.empty() ) 
    throw CToDoNoElements();
  
  TMultiIter k = m_mapSearch.find( Search );
  
  if( k == m_mapSearch.end() ) 
    throw CToDoNoElements();
  
  return k->second;
}

//////////////////////////////////////////////////////////////////////////
// Function create Class in which merged two SingleParser classes

CToDoSingleParse CToDoMultiParse::CreateMultiLine( const string &tmp1, const string &tmp2 ) throw( CToDoNoElements )
{
  // DONE: Function get two integer values which according to array
  // of search words and make merge of two ToDoSingleParser objects.
  // Operator+ must be override in SingleParser class for this function.
  // Function will store hisresults in first object.
  TMultiSearch::iterator k, l;
  
  k = m_mapSearch.find( tmp1 );

  if( k == m_mapSearch.end() ) 
    throw CToDoNoElements( );

  l = m_mapSearch.find( tmp2 );
  
  if( l == m_mapSearch.end() ) 
    throw CToDoNoElements( );

  CToDoSingleParse tmpRet;

  tmpRet = k->second + l->second;

  return tmpRet;
}

//////////////////////////////////////////////////////////////////////////
// Function create Class in which merged two SingleParser classes

CToDoSingleParse CToDoMultiParse::CreateMultiLine( const UINT tmp1, const UINT tmp2 )
{
  // DONE: Function get two string values which according to array
  // of search words and make merge of two ToDoSingleParser objects.
  // Operator+ must be override in SingleParser class for this function.
  // Function will store hisresults in first object.
  
  if( m_mapSearch.size() != m_strSearch.size() )
    throw CToDoNoElements( );

  if( tmp1 > m_mapSearch.size() || tmp2 > m_mapSearch.size() ) 
    throw CToDoNoElements( );

  return CreateMultiLine( m_strSearch[tmp1], m_strSearch[tmp2] );
}

//////////////////////////////////////////////////////////////////////////
// Iterator function which point map to first element

TMultiIter *	CToDoMultiParse::First( ) throw( CToDoNoElements )
{
  if( m_mapSearch.empty() ) 
    throw CToDoNoElements( );
  
  m_mapIter = m_mapSearch.begin();

  #ifdef _DEBUG
    string tmpName = m_mapIter->first;
  #endif // _DEBUG
  
  return &m_mapIter;
}

//////////////////////////////////////////////////////////////////////////
// Iterator function which point map pointer to next element

TMultiIter *	CToDoMultiParse::Next ( ) throw( CToDoNoElements, CToDoLastRiched )
{
  if( m_mapSearch.empty() ) 
    throw CToDoNoElements( );
  
  if( m_mapIter == m_mapSearch.end() )  
    throw CToDoLastRiched( );
  
  m_mapIter++;

  #ifdef _DEBUG
    if( m_mapIter != m_mapSearch.end() )
      string tmpName = m_mapIter->first;
  #endif // _DEBUG

  return &m_mapIter;
}

//////////////////////////////////////////////////////////////////////////
// Function move pointer of map to prev element

TMultiIter *	CToDoMultiParse::Prev ( ) throw( CToDoNoElements, CToDoFirstRiched )
{
  if( m_mapSearch.empty() ) 
    throw CToDoNoElements( );

  if( m_mapIter == m_mapSearch.begin() ) 
    throw CToDoFirstRiched( );
  
  m_mapIter--;

  #ifdef _DEBUG
    if( m_mapIter != m_mapSearch.end() )  
      string tmpName = m_mapIter->first;
  #endif // _DEBUG
  
  return &m_mapIter;
}

//////////////////////////////////////////////////////////////////////////
// Function point map to the end of map. 
// WARNING: Such element doesn't have any data!

TMultiIter *	CToDoMultiParse::Last ( ) throw( CToDoNoElements )
{
  if( m_mapSearch.empty() ) 
    throw CToDoNoElements( );
  
  m_mapIter = m_mapSearch.end();
  
  return &m_mapIter;
}

//////////////////////////////////////////////////////////////////////////
// Engine of our class which make amian work

long CToDoMultiParse::ParseEngine( void ) throw( CToDoFileWork )
{
  FILE *tmpFile = fopen( CToDoBaseParser::GetFileName().c_str(), "rt" );
  
  if( tmpFile == NULL ) 
    throw CToDoFileWork();
  
  long    lCounter = 0;
  char    MainStr[ TODO_STRING_RESERVE ];
  char    FindedStr[ TODO_STRING_RESERVE ];
  
  // Create array of categories
  TLineMapper *tmpLines = new TLineMapper[ m_strSearch.size() ];
  
  do 
  {
    char *tmp = fgets( MainStr, sizeof( MainStr ), tmpFile );
    if( tmp == NULL ) break;
    
    lCounter++;
    int count = 0;
    
    for( TStrArrayIter k = m_strSearch.begin(); k != m_strSearch.end(); k++, count++ )
    {
      tmp = strstr( MainStr, k->c_str() );
      
      if( tmp != NULL )
      {
        strcpy( FindedStr, tmp + ( *k ).length() );
        
        tmpLines[count].insert( TLineMapper::value_type( lCounter, string( FindedStr ) ) );
        ++m_lCounter;
        
        FindedStr[0] = 0x0;
      }
    }
    
  } while( !feof( tmpFile ) );
  
  // Store all categories 
  for( UINT i=0; i < m_strSearch.size(); i++ )
  {
    CToDoSingleParse tmpParse( CToDoBaseParser::GetFileName(), m_strSearch[i] );
    
    tmpParse.m_lCounter = tmpLines[i].size();
    
    if( tmpParse.m_lCounter > 0 )
      tmpParse.m_mapLines = tmpLines[i];
    
    if( strcmp( m_strSearch[i].c_str(), "// " ) == 0 )
    {
      CToDoMultiComment tmpComment( CToDoBaseParser::GetFileName() );

      tmpComment.StartParsing();

      tmpParse.Merge( tmpComment );
    }

    m_mapSearch.insert( TMultiSearch::value_type( m_strSearch[i], tmpParse ) );
  }
  
  fclose( tmpFile );
  
  delete []tmpLines;
  return m_lCounter;
}

//:> End of file

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO ArtfulBits Inc.
Ukraine Ukraine
Name:Kucherenko Oleksandr

Born:September 20, 1979

Platforms: Win32, Linux; - well known and MS-DOS; Win16; OS/2 - old time not touched;

Hardware: IBM PC

Programming Languages: Assembler (for Intel 80386); Borland C/C++; Borland Pascal; Object Pascal; Borland C++Builder; Delphi; Perl; Java; Visual C++; Visual J++; UML; XML/XSL; C#; VB.NET; T-SQL; PL/SQL; and etc.

Development Environments: MS Visual Studio 2001-2008; MS Visual C++; Borland Delphi; Borland C++Builder; C/C++ any; Rational Rose; GDPro; Together and etc.

Libraries: STL, ATL, WTL, MFC, NuMega Driver Works, VCL; .NET 1.0, 1.1, 2.0, 3.5; and etc.

Technologies: Client/Server; COM; DirectX; DirectX Media; BDE; HTML/DHTML; ActiveX; Java Servlets; DCOM; COM+; ADO; CORBA; .NET; Windows Forms; GDI/GDI+; and etc.

Application Skills: Databases - design and maintain, support, programming; GUI Design; System Programming, Security; Business Software Development. Win/Web Services development and etc.

Comments and Discussions