securityanddataprivacytools/securitytools/certapp/encdec/appuidmap.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appuidmap.h"
       
    20 #include <map>
       
    21 
       
    22 struct AppMapEntry
       
    23 	{
       
    24 	std::string iDef;
       
    25 	TInt32 iLastDefFileIndex;
       
    26 	};
       
    27 typedef std::map<TUint32, AppMapEntry> AppMap;
       
    28 
       
    29 //
       
    30 // Local static vars. This avoids including map etc in the header
       
    31 //
       
    32 static AppMap sAppMap;
       
    33 
       
    34 bool AppUidMap::InsertUidDefinition(TInt32 aUid, const std::string &aDef, TInt32 aInputFileIndex,
       
    35 									TInt32 &aLastIndex, std::string &aFirstDef)
       
    36 {
       
    37 	AppMapEntry val;
       
    38 	val.iDef = aDef;
       
    39 	val.iLastDefFileIndex = aInputFileIndex;
       
    40 	AppMap::value_type e(aUid, val);
       
    41 	std::pair<AppMap::iterator,bool> result = sAppMap.insert(e);
       
    42 	if(result.second == true)
       
    43 		{
       
    44 		// Inserted new entry
       
    45 		return true;
       
    46 		}
       
    47 	// Duplicate.
       
    48 	// Save fileIndex of previous definition
       
    49 	aLastIndex = (result.first)->second.iLastDefFileIndex;
       
    50 	aFirstDef = (result.first)->second.iDef;
       
    51 	// Update location of last seen def
       
    52 	(result.first)->second.iLastDefFileIndex = aInputFileIndex;
       
    53 
       
    54 	return false;
       
    55 }
       
    56 
       
    57 
       
    58 
       
    59 
       
    60 
       
    61 
       
    62 static EnumEntry *sEnumEntries = 0;
       
    63 
       
    64 void AppUidMap::GenerateEnumEntries()
       
    65 {
       
    66 	delete [] sEnumEntries;
       
    67 	sEnumEntries = new EnumEntry[sAppMap.size()+1];
       
    68 	sEnumEntries[sAppMap.size()].iName=0; // Terminate array
       
    69 
       
    70 	AppMap::const_iterator it = sAppMap.begin();
       
    71 	for(TUint32 i=0; i < sAppMap.size(); ++i)
       
    72 		{
       
    73 		sEnumEntries[i].iName = (*it).second.iDef.c_str();
       
    74 		sEnumEntries[i].iValue = (*it).first;
       
    75 		++it;
       
    76 		}
       
    77 }
       
    78 
       
    79 
       
    80 EnumEntry *AppUidMap::EnumEntries()
       
    81 {
       
    82 BULLSEYE_OFF
       
    83 	if(sEnumEntries == 0) FatalError();
       
    84 BULLSEYE_RESTORE
       
    85 	return sEnumEntries;
       
    86 }
       
    87 
       
    88 // End of file