apicompatanamdw/compatanalysercmd/headeranalyser/src/AnalyserParams.cpp
changeset 0 638b9c697799
equal deleted inserted replaced
-1:000000000000 0:638b9c697799
       
     1 /*
       
     2 * Copyright (c) 2006-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 "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 "CmdGlobals.h"
       
    20 #ifdef __WIN__
       
    21 #pragma warning(disable:4786)
       
    22 #endif
       
    23 
       
    24 #include <string>
       
    25 #include <map>
       
    26 #include "HAException.h"
       
    27 #include "AnalyserParams.h"
       
    28 
       
    29 
       
    30 using namespace std;
       
    31 
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // AnalyserParams::parameterExists
       
    35 // Return true, if the parameter parameter is given
       
    36 // ----------------------------------------------------------------------------
       
    37 //
       
    38 bool AnalyserParams::parameterExists(const string& aParm)
       
    39 {
       
    40     bool ret = false;
       
    41     map<string, pair<string, bool> >::iterator mapitem = iParameters.find(aParm);
       
    42     if (mapitem != iParameters.end())
       
    43     {
       
    44         ret = true;
       
    45     }
       
    46     return ret;
       
    47 }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // AnalyserParams::givenParameter
       
    51 // Return true, if the parameter parameter is given
       
    52 // ----------------------------------------------------------------------------
       
    53 //
       
    54 bool AnalyserParams::givenParameter(const string& aParm)
       
    55 {
       
    56     bool ret = false;
       
    57     map<string, pair<string, bool> >::iterator mapitem = iParameters.find(aParm);
       
    58     if (mapitem != iParameters.end())
       
    59     {
       
    60         ret = mapitem->second.second;
       
    61     }
       
    62     return ret;
       
    63 }
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // AnalyserParams::storeParameter
       
    67 // Store given parameter to parameter map
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 void AnalyserParams::storeParameter(string aParm, string aVal, bool aFromCmdline)
       
    71 {
       
    72     pair<string, pair<string, bool> >parameter(aParm,pair<string, bool>(aVal,aFromCmdline));
       
    73     map<string, pair<string, bool> >::iterator mapitem = iParameters.find(aParm);
       
    74     bool isValidParm = mapitem == iParameters.end() ? false : true;
       
    75     if (!isValidParm)
       
    76     {
       
    77         iParameters.insert(parameter);
       
    78     }
       
    79     else
       
    80     {
       
    81         if (((*mapitem).second).second == true) 
       
    82         {
       
    83             (*mapitem).second = pair<string,bool>(aVal,true);
       
    84         }
       
    85         else 
       
    86         {
       
    87             (*mapitem).second = pair<string,bool>(aVal,aFromCmdline);
       
    88         }
       
    89     }
       
    90 }
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // AnalyserParams::getParameter
       
    94 // Store given parameter value
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 string AnalyserParams::getParameter(const string& aParm)
       
    98 {
       
    99     map<string, pair<string, bool> >::iterator mapitem = iParameters.find(aParm);
       
   100     bool isValidParm = mapitem == iParameters.end() ? false : true;
       
   101     if (!isValidParm)
       
   102     {
       
   103         string excstr = "No such parameter: ";
       
   104         excstr += aParm;
       
   105         throw HAException(excstr);
       
   106     }
       
   107     return (mapitem->second).first;
       
   108 }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // AnalyserParams::getGivenParameters
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 const map <string, string> AnalyserParams::getGivenParameters()
       
   115 {
       
   116     map<string, string> givenparams;
       
   117     map<string, pair<string, bool> >::iterator begin = iParameters.begin();
       
   118     map<string, pair<string, bool> >::iterator end = iParameters.end();
       
   119     map<string, pair<string, bool> >::iterator find;
       
   120     map<string, pair<string, bool> >::iterator endfind = iParameters.end();
       
   121     while(begin != end)
       
   122     {
       
   123         string param = (*begin).first;
       
   124         pair<string, bool> values = (*begin).second;
       
   125         string val;
       
   126         if(values.second == true)
       
   127         {
       
   128             val = values.first;
       
   129             if (param == BASELINEDIR)
       
   130             {
       
   131                 find =  iParameters.find(BASELINE);
       
   132                 if (find != iParameters.end())
       
   133                 {
       
   134                     val += DIR_SEPARATOR;
       
   135                     val += ((*find).second).first;
       
   136                 }
       
   137             }
       
   138             if (param == BASELINE)
       
   139             {
       
   140                 find =  iParameters.find(BASELINEDIR);
       
   141                 val = ((*find).second).first;
       
   142                 val += DIR_SEPARATOR;
       
   143                 val += values.first;
       
   144             }
       
   145             if (param == CURRENT)
       
   146             {
       
   147                 find =  iParameters.find(CURRENTDIR);
       
   148                 val = ((*find).second).first;
       
   149                 val += DIR_SEPARATOR;
       
   150                 val += values.first;
       
   151             }
       
   152             givenparams.insert(pair<string,string>(param,val));
       
   153         }
       
   154         ++begin;
       
   155     }
       
   156     return givenparams;
       
   157 }