#include <Common.hpp>
#include <List.hpp>
#include <Vector.hpp>
#include <CoreLinuxIterator.hpp>
#include <iostream>
#include <exception>
using namespace corelinux;
CORELINUX_LIST( Int , IntList );
CORELINUX_VECTOR( Real , RealVector );
int main( void );
template<class T>
void dumpIterator( Iterator<T> *aIteratorPtr );
void handleAssertion( AssertionCref aAssert );
void handleException( ExceptionCref aExcp );
int main( void )
{
try
{
Iterator<Int> *aIntIterator(NULLPTR);
IntList aIntList;
aIntList.push_back(5);
aIntList.push_back(6);
aIntList.push_back(7);
aIntIterator = new CoreLinuxIterator<IntListIterator,Int>
(
aIntList.begin(),
aIntList.end()
);
dumpIterator<Int>(aIntIterator);
delete aIntIterator;
Iterator<Real> *aRealIterator( NULLPTR );
RealVector aRealVector;
aRealVector.push_back(0.7);
aRealVector.push_back(2.8);
aRealVector.push_back(7.19823);
aRealIterator = new CoreLinuxIterator<RealVectorIterator,Real>
(
aRealVector.begin(),
aRealVector.end()
);
dumpIterator<Real>(aRealIterator);
delete aRealIterator;
}
catch( InvalidIteratorExceptionRef aInvalidIterator )
{
cerr << "Invalid iterator constructed." << endl;
handleException(aInvalidIterator);
}
catch( IteratorBoundsExceptionRef aBoundsException )
{
cerr << "Bounds exception occured during traversel." << endl;
handleException(aBoundsException);
}
catch( AssertionRef aAssert )
{
handleAssertion(aAssert);
}
catch( std::exception & e )
{
cerr << e.what() << endl;
}
catch( ... )
{
cerr << "Unknown exception." << endl;
}
return 0;
}
template<class T>
void dumpIterator( Iterator<T> *aIteratorPtr )
{
while( aIteratorPtr->isValid() )
{
cout << aIteratorPtr->getElement() << endl;
aIteratorPtr->setNext();
}
}
void handleAssertion( AssertionCref aAssert )
{
cerr << aAssert.getFile() << ":" << aAssert.getLine() << ":" <<
"Assertion: ";
if( aAssert.getType() == Assertion::NEVERGETHERE )
{
cerr << "NEVER_GET_HERE";
}
else
{
if( aAssert.getType() == Assertion::REQUIRE )
{
cerr << "REQUIRE";
}
else if( aAssert.getType() == Assertion::ENSURE )
{
cerr << "ENSURE";
}
else if( aAssert.getType() == Assertion::CHECK )
{
cerr << "CHECK";
}
else
{
cerr << "ASSERT";
}
cerr << "( " << aAssert.getWhy() << " )";
}
cerr << endl;
}
void handleException( ExceptionCref aExcp )
{
cerr << aExcp.getFile() << ":" << aExcp.getLine() << ":" <<
"Exception: " << aExcp.getWhy() << endl;
}