testexecmgmt/ucc/GenericService/Common/src/CUCCIniFile.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*
       
     2 * Copyright (c) 2005-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 * CUCCIniFile.h
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <afxcoll.h>
       
    22 #include <assert.h>
       
    23 
       
    24 #include "CUCCIniFile.h"
       
    25 
       
    26 #define MAX_BUFFER_SIZE 1024
       
    27 
       
    28 CUCCIniFile::CUCCIniFile()
       
    29 {
       
    30 }
       
    31 
       
    32 CUCCIniFile::CUCCIniFile(const string& strName)
       
    33 {
       
    34 	SetIniFileName( strName );
       
    35 }
       
    36 
       
    37 CUCCIniFile::~CUCCIniFile()
       
    38 {
       
    39 }
       
    40 
       
    41 void CUCCIniFile::SetIniFileName(const string& strName)
       
    42 {
       
    43 	assert( strName.size() != 0 );
       
    44 	iIniFileName = strName;
       
    45 }
       
    46 
       
    47 bool CUCCIniFile::KeyValue(const string& strKey,const string& strSection, string& value ) const
       
    48 {
       
    49 	TCHAR result[MAX_BUFFER_SIZE];
       
    50 	int ret = GetPrivateProfileString(	(LPCTSTR)strSection.c_str(),
       
    51 										(LPCTSTR)strKey.c_str(),
       
    52 										_T(""),
       
    53 										result,
       
    54 										MAX_BUFFER_SIZE,
       
    55 										(LPCTSTR)iIniFileName.c_str());
       
    56 
       
    57 	if( ret>0 )
       
    58 	{
       
    59 		value = result;
       
    60 	}
       
    61 	return ret>0?true:false;
       
    62 }
       
    63 
       
    64 bool CUCCIniFile::KeyValue(const string& strKey, const string& strSection, int& value) const
       
    65 {
       
    66 	char* stopstring = NULL;
       
    67 	string tmpKeyValue;
       
    68 
       
    69 	bool ret = KeyValue( strKey, strSection, tmpKeyValue );
       
    70 	if( ret )
       
    71 	{
       
    72 		// Check to see if the input value is in hex
       
    73 		if( tmpKeyValue[0] == '0' && tmpKeyValue[1] == 'x' )
       
    74 		{
       
    75 			value = strtol(tmpKeyValue.c_str()+2, &stopstring, 16 );
       
    76 		}
       
    77 		else
       
    78 		{
       
    79 			value = strtol(tmpKeyValue.c_str(), &stopstring, 10 );
       
    80 		}
       
    81 	}
       
    82 	return ret;
       
    83 }
       
    84 
       
    85 vector<string> CUCCIniFile::SectionNames() const
       
    86 {
       
    87 	TCHAR result[MAX_BUFFER_SIZE];
       
    88 	long lRetValue = GetPrivateProfileSectionNames(	result,
       
    89 													MAX_BUFFER_SIZE,
       
    90 													(LPCTSTR)iIniFileName.c_str());
       
    91 
       
    92 	// Return a vector of all the section names
       
    93 	vector<string> sections;
       
    94 
       
    95 	int pos = 0;
       
    96 	while( pos <= MAX_BUFFER_SIZE )
       
    97 	{
       
    98 		string section = (char*)(result+pos);
       
    99 		if( section.size() > 0 )
       
   100 		{
       
   101 			sections.push_back( section );
       
   102 			pos +=section.size()+1;
       
   103 		}
       
   104 		else
       
   105 		{
       
   106 			break;
       
   107 		}
       
   108 	}
       
   109 
       
   110 	return sections;
       
   111 }
       
   112 
       
   113 vector<string> CUCCIniFile::SectionParameters(const string& strSection) const
       
   114 {
       
   115 	TCHAR result[MAX_BUFFER_SIZE];
       
   116 	long lRetValue = GetPrivateProfileString(	(LPCTSTR)strSection.c_str(),
       
   117 												NULL,
       
   118 												_T(""),
       
   119 												result,
       
   120 												MAX_BUFFER_SIZE,
       
   121 												(LPCTSTR)iIniFileName.c_str());
       
   122 
       
   123 	// Return a vector of parameters
       
   124 	vector<string> params;
       
   125 
       
   126 	int pos = 0;
       
   127 	while( pos <= MAX_BUFFER_SIZE )
       
   128 	{
       
   129 		string param = (char*)(result+pos);
       
   130 		if( param.size() > 0 )
       
   131 		{
       
   132 			params.push_back( param );
       
   133 			pos +=param.size()+1;
       
   134 		}
       
   135 		else
       
   136 		{
       
   137 			break;
       
   138 		}
       
   139 	}
       
   140 
       
   141 	return params;
       
   142 }