imgtools/imgcheck/src/exceptionreporter.cpp
author srilekhas <srilekhas@symbian.org>
Wed, 18 Aug 2010 11:18:38 +0100
changeset 627 cb3264f4c6e6
parent 590 360bd6b35136
permissions -rw-r--r--
Merge : re-applies missing part of fix for Bug 2901,Add export for s60ibymacros.pm

/*
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
* This class is used to receive the enum index of the original 
* message with some more variable arguments. These variable 
* arguments are split and put into the original message.
*
*/


/**
 @file
 @internalComponent
 @released
*/

#include "exceptionreporter.h"
#include "utils.h"
#include "h_utl.h"
/** 
Constructor receives the variable arguements and gets the instance 
of MessageImplementation class. Invokes GetMessage to get the 
original message. Find %d and %s inside the original message and
replace these specifiers with the received variable argument value.

@internalComponent
@released

@param aMsgIndex - an enum index to get original message from 
MessageImplementation class
@param ... - variable arguments.
*/
ExceptionReporter::ExceptionReporter(int aMsgIndex, ...) {
	iExcepImplPtr = ExceptionImplementation::Instance(0);
	iMessage = iExcepImplPtr->Message(aMsgIndex); 
	if(iMessage.length() > 0) {
		va_list argList;
		va_start(argList,aMsgIndex);
		
		int intVal;
		string strVal;
		
		unsigned int index = iMessage.find("%");
		string subStr = iMessage.substr(index + 1);//skip '%'
		while( index != string::npos ) {
			switch(iMessage.at(index + 1))  {
				case 'd':
					intVal = va_arg(argList, int);
					iMessage.erase(index, 2);//delete two characters "%d"
					iMessage.insert(index, ReaderUtil::IntToAscii(intVal, EBase10));
					break;
				case 's':
					strVal.assign(va_arg(argList, char*));		 
					iMessage.erase(index, 2); //delete two characters "%s"
					iMessage.insert(index, strVal);
					break;
			}
			index = iMessage.find("%");
		}
	}
}


/** 
Destructor. 

@internalComponent
@released
*/
ExceptionReporter::~ExceptionReporter() {
}


/**
Invokes the Log function of ExceptionImplementation, which puts the 
data into logfile directly and takes decision whether to put the same 
on standard output or not.

@internalComponent
@released
*/
void ExceptionReporter::Log(void) const {
	iExcepImplPtr->Log(iMessage);
}

/**
Invokes the Report function of ExceptionImplementation to report error or warning.

@internalComponent
@released
*/
void ExceptionReporter::Report(void) const {
	iExcepImplPtr->Report(iMessage);
}