|
/********************************************************************\
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.