gfxconversion/mifconv/inc/mifconv_argumentmanager.h
changeset 0 f453ebb75370
equal deleted inserted replaced
-1:000000000000 0:f453ebb75370
       
     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:  Mifconv argument manager class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __MIFCONVARGUMENTMANAGER_H__
       
    20 #define __MIFCONVARGUMENTMANAGER_H__
       
    21 
       
    22 #include <map>
       
    23 #include "mifconv.h"
       
    24 #include "mifconv_sourcefile.h"
       
    25 #include "mifconv_argument.h"
       
    26 
       
    27 
       
    28 /**
       
    29  * This helper class is used to specify rules that will be used when
       
    30  * mifconv is searching source icons from the predefined folders.
       
    31  * Currently it supports rules that specify what kind of files can be
       
    32  * located in the folders.
       
    33  */
       
    34 class MifConvSourceSearchRule
       
    35 {
       
    36 public:
       
    37     /**
       
    38      * Constructor
       
    39      * @param path Path to the folder, which the rule affects on.
       
    40      * @param types Allowed file types that can be located in the given 
       
    41      * <code>path</code>
       
    42      */
       
    43     MifConvSourceSearchRule(const MifConvString& path, const MifConvStringList& types);
       
    44 
       
    45     /**
       
    46      * Destructor
       
    47      */
       
    48     virtual ~MifConvSourceSearchRule();
       
    49 
       
    50     /**
       
    51      * Returns the path to the folder
       
    52      * @return Path to the folder from which the files are searched.
       
    53      */
       
    54     const MifConvString& SearchPath() const;
       
    55     MifConvString& SearchPath();
       
    56 
       
    57     /**
       
    58      * Returns a list of allowed file types (extensions). 
       
    59      * <code>MIFCONV_WILDCARD</code> can be used as a wildcard, meaning that
       
    60      * there are no restrictions for the filetype in the specific folder.
       
    61      * @return List of allowed file extensions.
       
    62      */
       
    63     const MifConvStringList& AllowedFileTypes() const;
       
    64 private:
       
    65     MifConvString iSearchPath;
       
    66     MifConvStringList iAllowedFileTypes;
       
    67 };
       
    68 
       
    69 class MifConvArgumentManager
       
    70 {
       
    71 public:
       
    72 
       
    73     /**
       
    74      * Returns a pointer to the singleton instance.
       
    75      * @return Pointer to the singleton instance.
       
    76      */
       
    77     static MifConvArgumentManager* Instance();
       
    78         
       
    79     /** 
       
    80      * Destructor
       
    81      */
       
    82 	virtual ~MifConvArgumentManager();
       
    83 
       
    84 	/** 
       
    85 	 * Initializes the argument list.
       
    86 	 * @param argList List of strings from which the arguments are parsed.
       
    87 	 */
       
    88 	void Init( const MifConvStringList& argList );
       
    89 
       
    90     /**
       
    91      * Deallocates the allocated memory.
       
    92      */
       
    93     static void Reset();
       
    94 
       
    95 	/**
       
    96 	 * Set target filename (i.e. mif-filename)
       
    97 	 * @param arg target filename
       
    98 	 */
       
    99 	void SetTargetFile( const MifConvString& arg );
       
   100 
       
   101 	/**
       
   102 	 * Returns target filename
       
   103 	 * @return target filename
       
   104 	 */
       
   105 	const MifConvString& TargetFile() const;
       
   106 
       
   107 	/**
       
   108 	 * Returns argument value
       
   109 	 * @param argName Argument name
       
   110 	 * @return Argument value
       
   111 	 */
       
   112 	const MifConvString& StringValue(const MifConvString& argName) const;
       
   113 
       
   114     /**
       
   115      * Returns argument value list
       
   116      * @param argName Argument name
       
   117      * @return List of argument values
       
   118      */
       
   119     const MifConvStringList& StringListValue(const MifConvString& argName) const;
       
   120 
       
   121 	/**
       
   122 	 * Returns value of an boolean argument. Returns false, if argument is not 
       
   123 	 * found from the boolean argument list.
       
   124 	 * @param argName Argument name
       
   125 	 * @return Argument value
       
   126 	 */
       
   127 	bool BooleanValue( const MifConvString& argName ) const;
       
   128 
       
   129 	/**
       
   130 	 * Returns source file list given in command line parameters
       
   131 	 * @return List of source files
       
   132 	 */
       
   133 	const MifConvSourceFileList& SourceFiles() const;
       
   134 
       
   135 	/**
       
   136 	 * Adds argument value to the argument map
       
   137 	 * @param argName Name of the argument
       
   138 	 * @param argValue Value of the argument
       
   139 	 */
       
   140 	void AddArgumentValue( const MifConvString& argName, const MifConvString& argValue );
       
   141 
       
   142 	/**
       
   143 	 * Add source file to the source file list
       
   144 	 * @param sourceFile Source file object to be added to the list
       
   145 	 */
       
   146 	void AddSourceFile( const MifConvSourceFile& sourceFile );
       
   147     
       
   148     /**
       
   149      * Returns value of EPOCROOT environment variable. If the EPOCROOT 
       
   150      * environment variable is defined (i.e. length > 0), directory separator
       
   151      * is added to returned string if it is missing from the EPOCROOT.
       
   152      * @return EPOCROOT environment variable value
       
   153      */
       
   154     const MifConvString& EpocRoot() const;
       
   155 
       
   156     /**
       
   157      * Converts depth value to display mode value
       
   158      * @return IconDisplayMode enumeration value 
       
   159      * @param depth IconDepth enumeration value
       
   160      */
       
   161     IconDisplayMode ConvertToDisplayMode(IconDepth depth) const;
       
   162 
       
   163     /**
       
   164      * Converts mask depth value to display mode value
       
   165      * @return IconDisplayMode enumeration value 
       
   166      * @param mask IconMaskDepth enumeration value
       
   167      */
       
   168     IconDisplayMode ConvertToMaskDisplayMode(IconMaskDepth mask) const;
       
   169 
       
   170     /**
       
   171      * Converts depth string value to depth enumeration value
       
   172      * @return IconDepth enumeration value
       
   173      * @param depthStr depth string      
       
   174      */
       
   175     IconDepth ConvertToDepth( const MifConvString& depthStr ) const;
       
   176 
       
   177     /**
       
   178      * Converts mask depth string value to mask depth enumeration value
       
   179      * @return IconMaskDepth enumeration value 
       
   180      * @param depthStr mask depth string
       
   181      */
       
   182     IconMaskDepth ConvertToMaskDepth( const MifConvString depthStr ) const;
       
   183 
       
   184 protected:
       
   185 
       
   186     /**
       
   187      * Tells whether the given string is a valid argument name
       
   188      * @return True if the given string is valid argument
       
   189      * @param argName String representing the argument name
       
   190      */
       
   191 	bool IsArgument( const MifConvString& argName ) const;
       
   192 
       
   193     /**
       
   194      * Tells whether the given argument is of string type and returns the 
       
   195      * length of the argument name. For example: If given string 
       
   196      * "/HMyHeader.mbg" this function returns 1, which is the length of the
       
   197      * argument name "H".
       
   198      * @return Length of the string if the given argument is string type, zero 
       
   199      * otherwise
       
   200      * @param argName Argument name
       
   201      */
       
   202 	size_t IsStringArgument( const MifConvString& argName ) const;
       
   203 
       
   204     /**
       
   205      * Tells whether the given argument is of string list type and returns the 
       
   206      * length of the argument name. For example: If given string 
       
   207      * "/iInputDir;TempDir" this function returns 1, which is the length of the
       
   208      * argument name "i".
       
   209      * @return Length of the string if the given argument is string list type, zero 
       
   210      * otherwise
       
   211      * @param argName Argument name
       
   212      */
       
   213 	size_t IsStringListArgument( const MifConvString& argName ) const;
       
   214 
       
   215     /**
       
   216      * Tells whether the given argument is of boolean type and returns the 
       
   217      * length of the argument name. For example: If given string "/E" this 
       
   218      * function returns 1, which is the length of the argument name "E".
       
   219      * @return Length of the argument name if the given argument is boolean 
       
   220      * type, zero otherwise
       
   221      * @param argName Argument name
       
   222      */
       
   223 	size_t IsBooleanArgument( const MifConvString& argName ) const;
       
   224 
       
   225     /**
       
   226      * Tells whether the given argument is a help argument and returns the 
       
   227      * length of the argument name. For example: If given string "--help" this
       
   228      * function returns 5, which is the length of the argument name "-help".
       
   229      * @return Length of the argument name if the given argument is a help 
       
   230      * argument, zero otherwise
       
   231      * @param argName Argument name
       
   232      */
       
   233     size_t IsHelpArgument( const MifConvString& argName ) const;
       
   234 
       
   235     /**
       
   236      * Tells whether the given argument is a valid depth value
       
   237      * @return True if the given argument is a valid depth value, false 
       
   238      * otherwise
       
   239      * @param argName Argument string
       
   240      */
       
   241 	bool IsDepthArgument( const MifConvString& argName ) const;
       
   242 
       
   243     /**
       
   244      * Tells whether the given argument is an "animated" -flag
       
   245      * @return True if the given argument is an "animated" -flag, false 
       
   246      * otherwise
       
   247      * @param argName Argument string
       
   248      */
       
   249 	bool IsAnimatedFlag( const MifConvString& argName ) const;
       
   250 
       
   251     /**
       
   252      * Finalizes the command line arguments for internal use.
       
   253      */
       
   254 	void FinalizeArguments();
       
   255 
       
   256     /**
       
   257      * Processes and fix the directory paths given in command line arguments.
       
   258      */
       
   259 	void ProcessArgumentPaths();
       
   260 
       
   261     /**
       
   262      * Resolves the actual source file types by searching them in user defined
       
   263      * or pre-defined locations.
       
   264      */
       
   265 	void ResolveSourceFileTypes();
       
   266 
       
   267     /**
       
   268      * Sets usage instructions in the given string
       
   269      * @param usageStr Usage instuctions are copied in this string object.
       
   270      */
       
   271 	void SetUsageString( MifConvString& usageStr ) const;
       
   272 
       
   273     /**
       
   274      * Gets needed environment variables.
       
   275      */
       
   276     void GetMifEnv();
       
   277 
       
   278     /**
       
   279      * Completes the given path to full directory path without the drive letter.
       
   280      * @param sourcePath Directory path to be completed to full path.
       
   281      * @param targetPath Full directory path is copied here.
       
   282      */
       
   283     void MifFullPath( const MifConvString& sourcePath, MifConvString& targetPath);
       
   284 
       
   285     /**
       
   286      * Completes the given drive and path to full absolute directory path.
       
   287      * @param sourceDrive Drive of the absolute path. If empty, epocroot 
       
   288      * environment variable is used.
       
   289      * @param sourcePath Directory path to be completed to absolute path.
       
   290      * @param targetPath Absolute directory path is copied here.
       
   291      */     
       
   292     void MifAbsolutePath( const MifConvString& sourceDrive, const MifConvString& sourcePath, MifConvString& targetPath);
       
   293 
       
   294     /**
       
   295      * Checks wheter the given file-extension is the correct one for the source 
       
   296      * file. Sets also the source filename to complete one.
       
   297      * @return true if the given source file with given extension is found and 
       
   298      * to be used.
       
   299      * @param srcFile Source file object
       
   300      * @param extension Extension of the source file
       
   301      */
       
   302     bool FindAndSetPathAndType( MifConvSourceFile& srcFile, const MifConvString& extension );
       
   303 
       
   304     /**
       
   305      * Fills up the depth and mask depth maps used to map different enumeration 
       
   306      * values internally.
       
   307      */
       
   308     void PopulateDepthAndMaskMaps();
       
   309 
       
   310     /**
       
   311      * Reads the parameter file containing commandline parameters and source 
       
   312      * icon files
       
   313      * @param paramFilename Filename for the parameter file.
       
   314      * @param paramList Parameters are inserted to this list.
       
   315      */
       
   316     void ReadParameterFile(const MifConvString& paramFilename, MifConvStringList& paramList);
       
   317 
       
   318     /**
       
   319      * Adds arguments to internal data structures
       
   320      * @param argList List containing arguments
       
   321      * @param paramsFromFile Tells if the parameters are read from the 
       
   322      * parameter file or not.
       
   323      * Applied usage rules depend sligthly on this.
       
   324      */
       
   325     void AddArguments( const MifConvStringList& argList, bool paramsFromFile = false );
       
   326 
       
   327     /**
       
   328      * Reads string argument from the list to internal data structure
       
   329      */
       
   330     MifConvString ReadStringArgument(const MifConvStringList& argList, MifConvStringList::const_iterator& i, unsigned int argNameLen);
       
   331 
       
   332     /**
       
   333      * Reads string list argument from the list to internal data structure
       
   334      */
       
   335     void ReadStringListArgument(MifConvStringList::const_iterator& i, unsigned int argNameLen, MifConvStringList& StringValueList);
       
   336 
       
   337     // Internal data structure for boolean type arguments
       
   338 	typedef std::map<MifConvString, MifConvBooleanArgument> BooleanArgMap;
       
   339     BooleanArgMap iBooleanArguments;
       
   340 
       
   341     // Internal data structure for string type arguments
       
   342 	typedef std::map<MifConvString, MifConvStringArgument> StringArgMap;
       
   343     StringArgMap iStringArguments;
       
   344 
       
   345     // Internal data structure for string list type arguments
       
   346     typedef std::map<MifConvString, MifConvStringListArgument> StringListArgMap;
       
   347     StringListArgMap iStringListArguments;
       
   348 
       
   349 	inline void THROW_USAGE_EXCEPTION() const;
       
   350     inline void THROW_ERROR( const MifConvString& errorMsg, const MifConvString& file = MifConvString(), int line = 0) const;
       
   351 	
       
   352 	MifConvSourceFileList iSourceFiles;
       
   353 	MifConvString iTargetFile;
       
   354 	MifConvString iDummyString;
       
   355     MifConvStringList iDummyStringList;
       
   356     //MifConvStringList iSearchPaths;    
       
   357     MifConvString iEpocRoot;
       
   358 
       
   359     // Internal data structure storing the rules used when finding source icons 
       
   360     // from the folders
       
   361     typedef vector<MifConvSourceSearchRule> SearchRules;
       
   362     SearchRules iSearchRules;
       
   363 
       
   364     private:
       
   365 
       
   366     /**
       
   367      * Default constructor
       
   368      */
       
   369 	MifConvArgumentManager();
       
   370     static MifConvArgumentManager* iInstance;
       
   371 
       
   372     MifConvIconDepthMap iDepthMap;
       
   373     MifConvIconMaskDepthMap iMaskDepthMap;
       
   374     MifConvIconDisplayModeMap iDisplayModeMap;
       
   375     MifConvMaskIconDisplayModeMap iMaskDisplayModeMap;
       
   376 };
       
   377 
       
   378 
       
   379 #endif