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