securityanddataprivacytools/securitytools/certapp/encdec/appuidmap.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 17:00:08 +0300
branchRCL_3
changeset 95 641f389e9157
parent 8 35751d3474b7
permissions -rw-r--r--
Revision: 201035 Kit: 201035

/*
* Copyright (c) 2008-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: 
*
*/


#include "appuidmap.h"
#include <map>

struct AppMapEntry
	{
	std::string iDef;
	TInt32 iLastDefFileIndex;
	};
typedef std::map<TUint32, AppMapEntry> AppMap;

//
// Local static vars. This avoids including map etc in the header
//
static AppMap sAppMap;

bool AppUidMap::InsertUidDefinition(TInt32 aUid, const std::string &aDef, TInt32 aInputFileIndex,
									TInt32 &aLastIndex, std::string &aFirstDef)
{
	AppMapEntry val;
	val.iDef = aDef;
	val.iLastDefFileIndex = aInputFileIndex;
	AppMap::value_type e(aUid, val);
	std::pair<AppMap::iterator,bool> result = sAppMap.insert(e);
	if(result.second == true)
		{
		// Inserted new entry
		return true;
		}
	// Duplicate.
	// Save fileIndex of previous definition
	aLastIndex = (result.first)->second.iLastDefFileIndex;
	aFirstDef = (result.first)->second.iDef;
	// Update location of last seen def
	(result.first)->second.iLastDefFileIndex = aInputFileIndex;

	return false;
}






static EnumEntry *sEnumEntries = 0;

void AppUidMap::GenerateEnumEntries()
{
	delete [] sEnumEntries;
	sEnumEntries = new EnumEntry[sAppMap.size()+1];
	sEnumEntries[sAppMap.size()].iName=0; // Terminate array

	AppMap::const_iterator it = sAppMap.begin();
	for(TUint32 i=0; i < sAppMap.size(); ++i)
		{
		sEnumEntries[i].iName = (*it).second.iDef.c_str();
		sEnumEntries[i].iValue = (*it).first;
		++it;
		}
}


EnumEntry *AppUidMap::EnumEntries()
{
BULLSEYE_OFF
	if(sEnumEntries == 0) FatalError();
BULLSEYE_RESTORE
	return sEnumEntries;
}

// End of file