apicompatanamdw/compatanalysercmd/headeranalyser/src/BBCFileUtils.h
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 #ifndef __BBC_FILE_UTILS_H__
       
    20 #define __BBC_FILE_UTILS_H__
       
    21 #include "CmdGlobals.h"
       
    22 #ifdef __WIN__
       
    23 #pragma warning(disable:4786)
       
    24 #endif
       
    25 #include <vector>
       
    26 #include <string>
       
    27 #include <map>
       
    28 #include <list>
       
    29 
       
    30 using namespace std;
       
    31 
       
    32 /**
       
    33 * Class includes file handling methods
       
    34 */ 
       
    35 class BBCFileUtils
       
    36 {
       
    37 public:
       
    38     /**
       
    39     * Contructor
       
    40     * @param  basedir 
       
    41     */ 
       
    42     BBCFileUtils(string basedir);
       
    43 
       
    44     /**
       
    45     * Destructor
       
    46     */ 
       
    47     ~BBCFileUtils();
       
    48 
       
    49 public:
       
    50     /**
       
    51     * Gets all the filenames matching the given wildcard in a directory
       
    52     * @param wildcard Search pattern for the files.
       
    53     * @param aRelPath Search location.
       
    54     * @return List of the filenames (pairs).
       
    55     */ 
       
    56     list<pair<string, string> > getFilesInDir(string wildcard, string aRelPath);
       
    57 
       
    58     /**
       
    59     * Gets all the filenames matching a file set in a directory
       
    60     * @param fileset List of filenames to be searched.
       
    61     * @param aRelPath Search location.
       
    62     * @param aFoundfiles list of files found
       
    63     * @return List of the filenames (pairs).
       
    64     */ 
       
    65     list<pair<string, string> > getFilesInDir(list<pair<string, string> >& fileset, string aRelPath, list<pair<string, string> >& aFoundfiles);
       
    66 
       
    67     /**
       
    68     * Calculates a quick but relatively unique fingerprint for a string.
       
    69     * Used in tempfile name generation. Collisions may occur, but it's 
       
    70     * not highly probable.
       
    71     * @param str filename + version
       
    72     * @return hash value
       
    73     */ 
       
    74     static unsigned int quickHash(string str);
       
    75 
       
    76     /**
       
    77     * Extract Filenames
       
    78     * Converts a ';' (semicolon) separated filename list to a string list.
       
    79     *
       
    80     * @param aFilenameList list of file names to search for
       
    81     * @return list pair of files
       
    82     */ 
       
    83     static list<pair<string, string> > extractFilenames(string aFilenameList);
       
    84 
       
    85     /**
       
    86     * Gets subdirectories in a directory
       
    87     * @param aRelPath Relative path to the directory from where the subdirectories are searched.
       
    88     * @param aExcludes Subdirectories to be excluded from the results
       
    89     * @return List of subdirectories found.
       
    90     */ 
       
    91     list<pair<string, string> > getDirsInDir(string aRelPath, list<pair<string, string> >& aExcludes);
       
    92 
       
    93     /**
       
    94     * Trims the given filename string (changes ';' to ' ' [whitespace])
       
    95     * and prefixes each filename entry with the base directory name 
       
    96     * (if required)
       
    97     * @param aFilenameList String containing the filenames separated with ';'.
       
    98     * @return String containing the trimmed filenames
       
    99     */ 
       
   100     string trimFilenames(string aFilenameList);
       
   101 
       
   102     /**
       
   103     * Checks if the given filename is valid.
       
   104     * @param aFilename Name of the file to be checked.
       
   105     * @return true, if the given string is a valid filename
       
   106     */ 
       
   107     static bool isValidFilename(const string& aFilename);
       
   108 
       
   109     /**
       
   110     * Check if the given path is a valid directory.
       
   111     * @param aPath Path to be checked
       
   112     * @return true, if the given string is a valid directory path
       
   113     */ 
       
   114     static bool isValidDirectory(const string& aPath);
       
   115 
       
   116     /**
       
   117     * Set temporary directory
       
   118     * @param aTempDir Temp directory name
       
   119     */ 
       
   120     void setTemp(const string& aTempDir);
       
   121 
       
   122     /**
       
   123     * Get full path name
       
   124     * @param aPath Path to be parsed
       
   125     * @return Full path name
       
   126     * @exception throws an exception if the path cannot be solved.
       
   127     */ 
       
   128     static string getFullPath(const string& aPath);
       
   129 
       
   130     /**
       
   131     * Strips off the file extension
       
   132     * @param aFileName Whole name of the file
       
   133     * @return Filename without the extension
       
   134     */ 
       
   135     static string  StripFilenameExtension(string aFileName);
       
   136 
       
   137     /**
       
   138     * Strips off the path
       
   139     * @param aAbsFilename Filename containing the path
       
   140     * @return Path from the given filename
       
   141     */ 
       
   142     static string StripPath(const string& aAbsFilename);
       
   143 
       
   144     // -- Support for multiple header directories -- Return type changed to list
       
   145     static list<pair<string, bool> > MergeDirs(const string& rootDir, const string& subDir);
       
   146 
       
   147     static bool FileExists(const string& fileName);
       
   148 
       
   149     /**
       
   150     * Function to read the compilation error output from a file and append to a string.
       
   151     * @param filename Filename containing the error output
       
   152     * @return string having error output
       
   153     */     
       
   154 	static string getCompilationError(string filename);
       
   155 	
       
   156 	static string& TrimRight(string& s);
       
   157     static string& TrimLeft(string& s);
       
   158     static string& TrimAll(string& s);
       
   159 
       
   160 private:
       
   161 #ifdef __UNIX__
       
   162     /**
       
   163     * Finds and return absolute path of the given relative path
       
   164     * @param aRelPath path to check
       
   165     * @param aAbsPath returnned absolute path
       
   166     * @return true if absolute path is found
       
   167     */ 
       
   168     static bool absolutePath(const string& aRelPath, string& aAbsPath);
       
   169 #endif
       
   170 
       
   171 private:
       
   172     //! count of files
       
   173     int             iFileCount;
       
   174     //! Vector of base/current files
       
   175     vector<string>  iFiles;
       
   176     //! the whole path + wildcard given
       
   177     string          iWildcard;
       
   178     //! base directory
       
   179     string          iBaseDir;
       
   180     //! temporary directory
       
   181     string          iTempDir;
       
   182     //! Dump file (not used)
       
   183     string          iDumpfile;
       
   184 
       
   185     static map<string, bool> fileExistsCache;
       
   186 };
       
   187 
       
   188 #endif