|         |      1 /* | 
|         |      2 * Copyright (c) 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:  Defines CATBase "utility" class. | 
|         |     15 * | 
|         |     16 */ | 
|         |     17  | 
|         |     18 #ifndef __CATBASE_H__ | 
|         |     19 #define __CATBASE_H__ | 
|         |     20  | 
|         |     21 #include "../inc/ATCommonDefines.h" | 
|         |     22  | 
|         |     23 /** | 
|         |     24 * This class implements lot of utility type of functions used all around atool project. | 
|         |     25 * All functions are static so they can be used without inheritance of this class. But still | 
|         |     26 * this is a base class of almost all others. | 
|         |     27 */ | 
|         |     28 class CATBase | 
|         |     29 { | 
|         |     30 public: | 
|         |     31 	 | 
|         |     32 	/** | 
|         |     33 	* Constructor | 
|         |     34 	*/ | 
|         |     35 	CATBase(); | 
|         |     36  | 
|         |     37 	/** | 
|         |     38 	* Destructor | 
|         |     39 	*/ | 
|         |     40 	virtual ~CATBase(void); | 
|         |     41  | 
|         |     42 public: | 
|         |     43 	 | 
|         |     44 	/** | 
|         |     45 	* FilterExtraSpaces | 
|         |     46 	* Filters/replaces multiple continuous spaces with single. Won't leave | 
|         |     47 	* spaces in start or end of string. | 
|         |     48 	* @param sString to filter. | 
|         |     49 	* @return void. | 
|         |     50 	*/ | 
|         |     51 	static void FilterExtraSpaces( string& sString ); | 
|         |     52  | 
|         |     53 	/** | 
|         |     54 	* Convert hex value in string to signed decimal. | 
|         |     55 	* @param sHex | 
|         |     56 	* @param iDec | 
|         |     57 	* @return true if successful | 
|         |     58 	*/ | 
|         |     59 	static bool hexToDec( string& sHex, int& iDec ); | 
|         |     60  | 
|         |     61 	/** | 
|         |     62 	* Convert hex value in string to unsigned decimal | 
|         |     63 	* @param sHex | 
|         |     64 	* @param iDec | 
|         |     65 	* @return true if successful | 
|         |     66 	*/ | 
|         |     67 	static bool hexToDec( string& sHex, unsigned int& iDec ); | 
|         |     68  | 
|         |     69 	/** | 
|         |     70 	* Convert hex value in string to unsigned long. | 
|         |     71 	* @param sHex | 
|         |     72 	* @param ulDec | 
|         |     73 	* @return true if successful | 
|         |     74 	*/ | 
|         |     75 	static bool hexToDec( string& sHex, unsigned long& ulDec ); | 
|         |     76  | 
|         |     77 	/** | 
|         |     78 	* Convert hex value in string to unsigned long long. | 
|         |     79 	* @param sHex | 
|         |     80 	* @param ullDec | 
|         |     81 	* @return true if successful | 
|         |     82 	*/ | 
|         |     83 	static bool hexToDec( string& sHex, unsigned long long& ullDec ); | 
|         |     84  | 
|         |     85 	/** | 
|         |     86 	* Convert hex value to integer | 
|         |     87 	* @param value | 
|         |     88 	* @return unsigned long | 
|         |     89 	*/ | 
|         |     90 	static unsigned long _httoi(const TCHAR *value); | 
|         |     91  | 
|         |     92 	/** | 
|         |     93 	* Convert integer to hex string. | 
|         |     94 	* @param i | 
|         |     95 	* @return hex string | 
|         |     96 	*/ | 
|         |     97 	static string NumberToHexString( unsigned int i ); | 
|         |     98  | 
|         |     99 	/** | 
|         |    100 	* Convert long to hex string. | 
|         |    101 	* @param i | 
|         |    102 	* @return hex string | 
|         |    103 	*/ | 
|         |    104 	static string NumberToHexString( unsigned long i ); | 
|         |    105  | 
|         |    106 	/** | 
|         |    107 	* Helper function checks is given character hex. | 
|         |    108 	* @param value value to check. | 
|         |    109 	* @return true if value is hex char. | 
|         |    110 	*/ | 
|         |    111 	static bool IsHexCharacter(const TCHAR *value); | 
|         |    112  | 
|         |    113 	/** | 
|         |    114 	* Parse string to vector of strings using | 
|         |    115 	* separator. (Tokenizer with delimeter). | 
|         |    116 	* @param sInput string to split | 
|         |    117 	* @char separator | 
|         |    118 	* return vector<string> | 
|         |    119 	*/ | 
|         |    120 	static vector<string> ParseStringToVector( const string& sInput, char separator ); | 
|         |    121  | 
|         |    122 	/** | 
|         |    123 	* Remove spaces and tabulatures from beginning and | 
|         |    124 	* end of given string. | 
|         |    125 	* @param sInput String to trim. | 
|         |    126 	*/ | 
|         |    127 	static void TrimString( string& sInput ); | 
|         |    128  | 
|         |    129 	/** | 
|         |    130 	* Searches files with given extension from path. | 
|         |    131 	* @param pPathAndExt path with extension | 
|         |    132 	* @return string filename | 
|         |    133 	*/ | 
|         |    134 	static string GetFileNameUsingExt( const char* pPathAndExt ); | 
|         |    135  | 
|         |    136 	/** | 
|         |    137 	* Changes all BackSlash characters to Slash character from string. | 
|         |    138 	* @param sInput String including backslashes. | 
|         |    139 	* @return String without backslashes. | 
|         |    140 	*/ | 
|         |    141 	static string ChangeSlashToBackSlash( string sInput ); | 
|         |    142  | 
|         |    143 	/** | 
|         |    144 	* Changes given string to uppercase | 
|         |    145 	* @param sInput | 
|         |    146 	*/ | 
|         |    147 	static void ChangeToUpper( string& sInput ); | 
|         |    148  | 
|         |    149 	/** | 
|         |    150 	* Converts any uppercase letter to lowercase. | 
|         |    151 	* | 
|         |    152 	* @param sInput Reference to string. | 
|         |    153 	*/ | 
|         |    154 	static void ChangeToLower( string& sInput ); | 
|         |    155  | 
|         |    156 	/** | 
|         |    157 	* Filter string out of unwanted characters. The list of allowed | 
|         |    158 	* characters is defined in CFILTERSTRING. | 
|         |    159 	* @param sString string to filter. | 
|         |    160 	* @return filtered string. | 
|         |    161 	*/ | 
|         |    162 	static string FilterString( const string& sString ); | 
|         |    163  | 
|         |    164 	/** | 
|         |    165 	* Removes path and extension from given filename string | 
|         |    166 	* @param sFileName | 
|         |    167 	* @param bReverseFindExt if true extension will be looked starting from end | 
|         |    168 	* @return string | 
|         |    169 	*/ | 
|         |    170 	static string RemovePathAndExt( string sFileName, bool bReverseFindExt = false ); | 
|         |    171  | 
|         |    172 	/** | 
|         |    173 	* Check if given file exists. | 
|         |    174 	* @param pFilename Pointer to file name. | 
|         |    175 	* @return False If file does not exists. | 
|         |    176 	*/ | 
|         |    177 	static bool FileExists( const char* pFilename ); | 
|         |    178  | 
|         |    179 	/** | 
|         |    180 	* Check if given file is flagged read only. | 
|         |    181 	* @param pFileName pointer to file name | 
|         |    182 	* @return true if read only flag set. | 
|         |    183 	*/ | 
|         |    184 	static bool IsFileReadOnly( const char* pFileName ); | 
|         |    185  | 
|         |    186 	/** | 
|         |    187 	* Set file read only. | 
|         |    188 	* @param pFileName Pointer to file name | 
|         |    189 	* @return true if successful. | 
|         |    190 	*/ | 
|         |    191 	static bool SetFileReadOnly( const char* pFileName ); | 
|         |    192  | 
|         |    193 	/** | 
|         |    194 	* Set file writable (remove read only flag). | 
|         |    195 	* | 
|         |    196 	* @param pFilename Pointer to file name. | 
|         |    197 	* @return true if successful. | 
|         |    198 	*/ | 
|         |    199 	static bool SetFileWritable( const char* pFileName ); | 
|         |    200  | 
|         |    201 	/** | 
|         |    202 	* Copy file to given path | 
|         |    203 	* @param sFile | 
|         |    204 	* @param sToPath | 
|         |    205 	* @return true if successful | 
|         |    206 	*/ | 
|         |    207 	static bool FileCopyToPath(const string& sFile, const string& sToPath); | 
|         |    208  | 
|         |    209 	/** | 
|         |    210 	* Move file to given path | 
|         |    211 	* @param sFile File to be moved | 
|         |    212 	* @param sToPath path where to move file | 
|         |    213 	* @return true if successful | 
|         |    214 	*/ | 
|         |    215 	static bool FileMoveToPath(const string& sFile, const string& sToPath); | 
|         |    216  | 
|         |    217 	/** | 
|         |    218 	* Delete file | 
|         |    219 	* Note! if file does not exists no error message is displayed | 
|         |    220 	* but function returns false | 
|         |    221 	* @param sFile File to be deleted | 
|         |    222 	* @param bPrint display messages or not, default true | 
|         |    223 	* @return true if successful | 
|         |    224 	*/ | 
|         |    225 	static bool FileDelete(const string& sFile, bool bPrint = true ); | 
|         |    226      | 
|         |    227 	/** | 
|         |    228 	* Delete dir | 
|         |    229 	* Note! if dir does not exists no error message is displayed | 
|         |    230 	* but function returns false. | 
|         |    231 	* This function wont delete directory if string does not contain | 
|         |    232 	* AT_TEMP... | 
|         |    233 	* @param sDir Directory to be deleted | 
|         |    234 	* @param bPrint display message or not, default true | 
|         |    235 	* @return true if successful | 
|         |    236 	*/ | 
|         |    237 	static bool DirDelete(const string& sDir, bool bPrint = true ); | 
|         |    238  | 
|         |    239 	/** | 
|         |    240 	* Create dir | 
|         |    241 	* Note! if dir cannot be created no error message is displayed | 
|         |    242 	* but function returns false. | 
|         |    243 	* @param sDir Directory to be deleted | 
|         |    244 	* @param pPrint display message or not, default true | 
|         |    245 	* @return true if successful | 
|         |    246 	*/ | 
|         |    247 	static bool DirCreate(const string& sDir, bool pPrint = true ); | 
|         |    248  | 
|         |    249 	/** | 
|         |    250 	* Create temp path string for given | 
|         |    251 	* mmpfile (full path+mmpname) | 
|         |    252 	* @param sMmpFileWithPath | 
|         |    253 	* @return string containing full path to | 
|         |    254 	* AnalyzeTool temporary directory | 
|         |    255 	*/ | 
|         |    256 	static string CreateTempPath(const string& sMmpFileWithPath); | 
|         |    257  | 
|         |    258 	/** | 
|         |    259 	* Search files with extensions from given path. | 
|         |    260 	* @param pPathAndExt path with extension definition | 
|         |    261 	* @param bPrintErrors do print errors? | 
|         |    262 	* @param sErrorLog errors | 
|         |    263 	* @return true if found. | 
|         |    264 	*/ | 
|         |    265 	static bool SearchFileWithExtension( const char* pPathAndExt, bool bPrintErrors, string& sErrorLog ); | 
|         |    266  | 
|         |    267 	/** | 
|         |    268 	* Helper function to parse filename or path from given string | 
|         |    269 	* @param bFileName if true returns filename otherwise the path | 
|         |    270 	* @param sInput string where to get path or filename | 
|         |    271 	* @return string filename or path | 
|         |    272 	*/ | 
|         |    273 	static string GetPathOrFileName( bool bFileName, string sInput ); | 
|         |    274  | 
|         |    275 	/** | 
|         |    276 	* Function returns string from begin of given string until next space, | 
|         |    277 	* characters until next space are removed from sInput string. | 
|         |    278 	* | 
|         |    279 	* @param sInput Line where data is separated with spaces. | 
|         |    280 	* @param bEraseFromInput If true characters before space will be removed. | 
|         |    281 	* @return string String until next space. | 
|         |    282 	*/ | 
|         |    283 	static string GetStringUntilNextSpace( string& sInput, bool bEraseFromInput = true ); | 
|         |    284  | 
|         |    285 	/** | 
|         |    286 	* Convert unix path to windows | 
|         |    287 	* @param sPath | 
|         |    288 	*/ | 
|         |    289 	static void ConvertUnixPathToWin( string& sPath ); | 
|         |    290  | 
|         |    291 	/** | 
|         |    292 	* Create Temporary AT Cpp file | 
|         |    293 	* @param sId unique id to add in file name | 
|         |    294 	* @param sPath where to create | 
|         |    295 	* @param sS60FileName of the logging file | 
|         |    296 	* @param iLogOption logging mode | 
|         |    297 	* @param iIsDebug build type | 
|         |    298 	* @param iAllocCallStackSize | 
|         |    299 	* @param iFreeCallStackSize | 
|         |    300 	* @return true if successful | 
|         |    301 	*/ | 
|         |    302 	static bool CreateTemporaryCpp( const string& sId | 
|         |    303 								 ,const string& sPath | 
|         |    304 								 ,const string& sS60FileName | 
|         |    305 								 ,int iLogOption | 
|         |    306 								 ,int iIsDebug | 
|         |    307 								 ,int iAllocCallStackSize | 
|         |    308 								 ,int iFreeCallStackSize ); | 
|         |    309 	/** | 
|         |    310 	* Acquire a list of files in given directory | 
|         |    311 	* @param sDirectory can end to \ or x but not to * | 
|         |    312 	* @param bListDirs if true directories will be listed as well, default false | 
|         |    313 	* @param bAddPathToFile if true given sDirectory path is added to file string, default false | 
|         |    314 	* @return vector<string> list of files in folder | 
|         |    315 	*/ | 
|         |    316 	static vector<string> DirList(const string& sDirectory, bool bListDirs = false, bool bAddPathToFile = false); | 
|         |    317  | 
|         |    318 	/** | 
|         |    319 	* Get extension from given "file" string | 
|         |    320 	* returns string after last . if any otherwise returns same | 
|         |    321 	* what was given | 
|         |    322 	* @param sString  | 
|         |    323 	* @return string string after last '.' if no '.' returns given string | 
|         |    324 	*/ | 
|         |    325 	static string GetExtension(const string& sString); | 
|         |    326  | 
|         |    327 	/** | 
|         |    328 	* Convert TCHAR pointer to string | 
|         |    329 	* @param charArray to convert | 
|         |    330 	* @return string | 
|         |    331 	*/ | 
|         |    332 	static string ConvertTCHARtoString(TCHAR* charArray); | 
|         |    333  | 
|         |    334 	/** | 
|         |    335 	* if given string contains two dots '.' this will remove | 
|         |    336 	* all characters after first '.' | 
|         |    337 	*/ | 
|         |    338 	static void RemoveAllAfterDotIfTwoDots(string& sString); | 
|         |    339  | 
|         |    340 	/** | 
|         |    341 	* checks given file is it data file | 
|         |    342 	* @param sFile | 
|         |    343 	* @return true if it is datafile | 
|         |    344 	*/ | 
|         |    345 	static bool IsDataFile( string sFile ); | 
|         |    346  | 
|         |    347 	/** | 
|         |    348 	* Parses a path string containing ".." to a valid | 
|         |    349 	* path without relations. If given string does | 
|         |    350 	* not contain relations it will not be changed | 
|         |    351 	* @param sPathString | 
|         |    352 	* @return void | 
|         |    353 	*/ | 
|         |    354 	static void ParseRelativePathString(string& sPathString); | 
|         |    355  | 
|         |    356 	/** | 
|         |    357 	* Remove relative path ".." from string | 
|         |    358 	* @param sString string to remove from | 
|         |    359 	* @param iDots index of ".." | 
|         |    360 	* @return void | 
|         |    361 	*/ | 
|         |    362 	static void RemoveRelativePath(string& sString, size_t iDots); | 
|         |    363  | 
|         |    364 	/** | 
|         |    365 	* Check if given directory exists. | 
|         |    366 	* | 
|         |    367 	* @param pDirname Pointer to directory name. | 
|         |    368 	* @return False If directory does not exists. | 
|         |    369 	*/	 | 
|         |    370 	static bool DirectoryExists( const char* pDirname ); | 
|         |    371  | 
|         |    372 	/** | 
|         |    373 	* Checks from constant array is this targettype | 
|         |    374 	* unsupported by AT | 
|         |    375 	* @param sTargetType type to check | 
|         |    376 	* @return true if it is supported by atool | 
|         |    377 	*/ | 
|         |    378 	static bool IsTargetTypeSupported(string sTargetType); | 
|         |    379  | 
|         |    380 	/** | 
|         |    381 	* Checks from constant array is this targettype | 
|         |    382 	* kernel side. | 
|         |    383 	* @param sTargetType type to check | 
|         |    384 	* @return true if it is kernel type | 
|         |    385 	*/ | 
|         |    386 	static bool IsTargetTypeKernelSide(string sTargetType); | 
|         |    387  | 
|         |    388 	/** | 
|         |    389 	* Check is given variant defined in environment.(SBS v.1) | 
|         |    390 	* @param sEpocroot | 
|         |    391 	* @param sVariantName | 
|         |    392 	* @return true if it is. | 
|         |    393 	*/ | 
|         |    394 	static bool CheckVariant( const string& sEpocroot, const string& sVariantName ); | 
|         |    395  | 
|         |    396 	/** | 
|         |    397 	* Check has the environment defined "DEFAULT" variant | 
|         |    398 	* @param sEpocRoot | 
|         |    399 	* @return true if it is | 
|         |    400 	*/ | 
|         |    401 	static  bool IsDefaultVariant( const string& sEpocRoot ); | 
|         |    402  | 
|         |    403 	/** | 
|         |    404 	* Check is all character ascii | 
|         |    405 	* @param pInput pointer to characters | 
|         |    406 	* @param iLength length of the string | 
|         |    407 	* @return true if all character are ascii | 
|         |    408 	*/ | 
|         |    409 	static bool IsAscii( const char* pInput, const unsigned int iLength ); | 
|         |    410  | 
|         |    411 	/** | 
|         |    412 	* Get current environments epocroot. | 
|         |    413 	* @param sEpocRoot value is stored in this if successful. | 
|         |    414 	* @return true if successful. | 
|         |    415 	*/ | 
|         |    416 	static bool GetEpocRoot( string& sEpocRoot ); | 
|         |    417 }; | 
|         |    418 #endif |