bintools/rcomp/inc/localise.h
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2007-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 the License "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 __LOCALISE_H__
       
    20 #define __LOCALISE_H__
       
    21 
       
    22 #ifdef __VC32__ 
       
    23 #pragma warning( push, 1 )	// MS STL libraries do not compile cleanly, temporarily set warning level to 1
       
    24 #pragma warning( disable : 4710 )	// function not inlined.
       
    25 #pragma warning( disable : 4530 )	// function not inlined.
       
    26 #endif
       
    27 #include <vector>
       
    28 #include <map>
       
    29 #include <new>
       
    30 
       
    31 #pragma warning( disable : 4710 )	// function not inlined.
       
    32 
       
    33 #include "ASTRING.H"
       
    34 
       
    35 typedef std::vector<String> CommentTagStore;
       
    36 
       
    37 enum OutputStates {	EStartOfLine, EGeneral, EFindLineNo, EInLineNo, 
       
    38 					EFindFileName, EInFileName, EFindDigit, EAfterDigit };
       
    39 
       
    40 enum States { EStartOfComment, EAfterFirstWordOfTag, ENewLineAtStart, EInTag, ENewLineInTag };
       
    41 
       
    42 enum Requirements { ERequired, EOptional, EOptionalWithDefault, EForbidden };
       
    43 
       
    44 enum ProcessOptionalStates { ELookingForCommand, ELookingForEqualSignOrRlsItem, ELookingForDefault,
       
    45 								ELookingForRlsItem, EShouldBeFinished };
       
    46 
       
    47 enum NumberOfRlsTypes { ENumberOfRlsTypes = 7 }; 
       
    48 // ENumberOfRlsTypes is used as the dimension of the array iRlsTypes declared in GlobalLocalisationData.
       
    49 // These values are filled in in the constructor for that class.
       
    50 
       
    51 class RlsItemRequirements
       
    52 	{
       
    53 public:
       
    54 	RlsItemRequirements(String aRlsName, int aRequirement=EForbidden);
       
    55 	RlsItemRequirements(const RlsItemRequirements & aRlsItemRequirements);
       
    56 	~RlsItemRequirements();
       
    57 private:
       
    58 	String iRlsName;
       
    59 	int iRequirement;
       
    60 	};
       
    61 
       
    62 class CommandRequirementsHolder
       
    63 	{
       
    64 public:
       
    65 	CommandRequirementsHolder(String aCommandName);
       
    66 	CommandRequirementsHolder(const CommandRequirementsHolder & aCommandRequirmentsHolder);
       
    67 	~CommandRequirementsHolder();
       
    68 private:
       
    69 	String iCommandName;
       
    70 	std::vector<RlsItemRequirements> iRlsRequirements;
       
    71 	};
       
    72 
       
    73 
       
    74 class TagParameterData
       
    75 	{
       
    76 public:
       
    77 	TagParameterData(String aTagParameter);
       
    78 	TagParameterData(const TagParameterData & aTagParameterData);
       
    79 	~TagParameterData();
       
    80 	void SetTagParameter(String aTagParameter);
       
    81 	String GetTagParameter();
       
    82 private:
       
    83 	String iTagParameter;
       
    84 	};
       
    85 
       
    86 class CommentRequirement // requirements for an rls item
       
    87 	{
       
    88 public:
       
    89 	CommentRequirement(int aRequirementStatus, String aDefaultParameter="");
       
    90 	CommentRequirement(const CommentRequirement & aCommentRequirement);
       
    91 	~CommentRequirement();
       
    92 	int GetRequirementStatus();
       
    93 	String GetDefault();
       
    94 private:
       
    95 	int iRequirementStatus;
       
    96 	String iDefaultParameter;
       
    97 	};
       
    98 
       
    99 class CommentRequirementPair // for a particular tag holds the requirements for an rls item
       
   100 	{
       
   101 public:
       
   102 	CommentRequirementPair(String aRlsItem, int aStatus, String aDefault="");
       
   103 	CommentRequirementPair(const CommentRequirementPair & aCommentRequirementPair);
       
   104 	~CommentRequirementPair();
       
   105 	String CheckIfOptionalAndHasDefault(String aRlsTypeName, String aCommandName);
       
   106 	int GetRequirementStatus();
       
   107 	String GetRlsItem();
       
   108 	void SetRlsItem(String aRlsItem);
       
   109 private:
       
   110 	String iRlsItem;
       
   111 	CommentRequirement iCommentRequirementData;
       
   112 	};
       
   113 
       
   114 class CommentTag // the declared data which goes with a particular command tag
       
   115 	{
       
   116 public:
       
   117 	CommentTag(String aParameterType="", bool aTagDeclared=false);
       
   118 	CommentTag(const CommentTag & aCommentTag);
       
   119 	~CommentTag();
       
   120 	bool IsTagDeclared();
       
   121 	bool IsTagLegalForRlsType(String aRlsTypeName);
       
   122 	bool IsParameterAlreadyDeclared(String aTagParameter);
       
   123 	int GetRequirementStatus(String aRlsItem);
       
   124 	String CheckIfOptionalAndHasDefault(String aRlsTypeName, String aCommandName);
       
   125 	String GetParameterType();
       
   126 	String GetPermissibleParameter(int aIndex);
       
   127 	int GetNumberOfPermissibleParameters();
       
   128 	void SetDeclared();
       
   129 	void SetParameterType(String aParameterType);
       
   130 	void AddTagParameterData(String aPermissibleParameter);
       
   131 	void AddRequirements(String aRlsItem, int aRequired, String aDefault);
       
   132 private:
       
   133 	bool iTagDeclared;
       
   134 	String iParameterType;
       
   135 	std::vector<TagParameterData> iPermissibleParameters;
       
   136 	std::vector<CommentRequirementPair> iRequirements;
       
   137 	};
       
   138 
       
   139 class CommentTagPair // a mapping between command tag names and the data which goes with them
       
   140 	{
       
   141 public:
       
   142 	CommentTagPair(String aCommandName, String aParameterType="", bool aTagDeclared=false);
       
   143 	CommentTagPair(const CommentTagPair & aCommentTagPair);
       
   144 	~CommentTagPair();
       
   145 	bool TagDeclared();
       
   146 	bool IsTagLegalForRlsType(String aRlsTypeName);
       
   147 	bool IsParameterAlreadyDeclared(String aTagParameter);
       
   148 	int GetRequirementStatus(String aRlsItem);
       
   149 	String CheckIfOptionalAndHasDefault(String aRlsTypeName);
       
   150 	String GetCommandName();
       
   151 	String GetParameterType();
       
   152 	String GetPermissibleParameter(int aIndex);
       
   153 	int GetNumberOfPermissibleParameters();
       
   154 	void SetCommandName(String aCommandName);
       
   155 	void SetTagDeclared();
       
   156 	void AddPermissibleParameter(String aPermissibleParameter);
       
   157 	void AddRlsItem(String aRlsItem, int aRequired, String aDefault);
       
   158 	
       
   159 private:
       
   160 	String iCommandName;
       
   161 	CommentTag iTagVariables;
       
   162 	};
       
   163 
       
   164 
       
   165 	
       
   166 class LocalisationLine // an individual line from a localisation comment
       
   167 	{
       
   168 public:
       
   169 	LocalisationLine(String iFileName="", int iLineNumber=-1);
       
   170 	LocalisationLine(const LocalisationLine & aClass);
       
   171 	~LocalisationLine();
       
   172 	void Reset(String iFileName, int iLineNumber);
       
   173 	String GetFileName();
       
   174 	int GetFirstLine();
       
   175 	int GetLastLine();
       
   176 	void SetFirstLine(int aFirstLine);
       
   177 	void SetFileName(String aFileName);
       
   178 	void SetLastLine(int aLastLine);
       
   179 	unsigned int GetNumberOfTokens();
       
   180 	String GetElement(unsigned int aIndex);
       
   181 	void AddElement(String aElement);
       
   182 	void SetAnalysed(bool aParity);
       
   183 	void Empty();
       
   184 	bool IsLineAnalysed();
       
   185 private:
       
   186 	bool iAnalysed;
       
   187 	int iFirstLine;
       
   188 	int iLastLine;
       
   189 	String iFileName;
       
   190 	std::vector<String> iData;
       
   191 	};
       
   192 
       
   193 
       
   194 class LocalisationComment // holds the data from a localisation comment
       
   195 	{
       
   196 public:
       
   197 	LocalisationComment(LocalisationLine & aComment);
       
   198 	~LocalisationComment();
       
   199 	String GetFileName();
       
   200 	int GetFirstLineOfComment();
       
   201 	int GetLastLineOfComment();
       
   202 	int GetNumberOfOptionalLinesToAdd();
       
   203 	LocalisationLine GetLine(unsigned int aIndex);
       
   204 	unsigned int GetNumberOfTokensInComment(); // size of originalData
       
   205 	unsigned int GetNumberOfTokensInLine(unsigned int aIndex); // size of iData[aIndex]
       
   206 	unsigned int GetNumberOfLinesInComment(); // size of iData
       
   207 	String GetOriginalElement(unsigned int aIndex);
       
   208 	String GetElementFromLine(unsigned int aLine, unsigned int aElement);
       
   209 	void AddDataLine(LocalisationLine aDataLine);
       
   210 	void SetAnalysed(unsigned int aIndex, bool aParity);
       
   211 	void SetLastLine(int aLineNumber);
       
   212 	bool IsLineAnalysed(unsigned int aIndex);
       
   213 	void SetWholeTagAnalysed(bool aParity);
       
   214 	int GetFirstLine(unsigned int aIndex);
       
   215 	void AddOptionalData(String aOptionalData);
       
   216 	String GetOptionalLineToAdd(unsigned int aLine);
       
   217 private:
       
   218 	LocalisationLine iOriginalData;
       
   219 	std::vector<LocalisationLine> iData;
       
   220 	std::vector<String> iOptionalLinesToAdd;
       
   221 	};
       
   222 
       
   223 class WarningToOutput // an individual localisation warning
       
   224 	{
       
   225 public:
       
   226 	WarningToOutput(const String aFileName, int aLineNumber, String aComment);
       
   227 	WarningToOutput(const WarningToOutput & aWarningToOutput);
       
   228 	~WarningToOutput();
       
   229 	WarningToOutput& operator=(const WarningToOutput& aWarningToOutput);
       
   230 	const String GetFileName();
       
   231 	int GetLineNumber();
       
   232 	String GetComment();
       
   233 private:
       
   234 	String iFileName;
       
   235 	int iLineNumber;
       
   236 	String iComment;
       
   237 	};
       
   238 
       
   239 class GlobalLocalisationData
       
   240 	{
       
   241 public:
       
   242 	GlobalLocalisationData();
       
   243 	~GlobalLocalisationData();
       
   244 
       
   245 	bool LocalisationCommentsExist();
       
   246 	void AnalyseLocalisationData();
       
   247 	void OutputLocalisedFile(String SourceFileName);
       
   248 	void PrintLocalisationWarnings();
       
   249 
       
   250 	void AddWarningToStore(const String aFileName, int aLineNumber, String aComment);
       
   251 	void SetStart(String aFileName, int aLineNumber);
       
   252 	void StoreComment(String aString);
       
   253 	void StoreFinalComment();
       
   254 
       
   255 private:
       
   256 	void ParseCommentTags(unsigned int i);
       
   257 	void CheckIfCommentTagsFullyAnalysed();
       
   258 	void CheckRlsEntries();
       
   259 	void Process(unsigned int aStoreIndex, unsigned int aCurrentIndex);
       
   260 	void ProcessDeclaration(unsigned int aStoreIndex, unsigned int aCurrentIndex);
       
   261 	void ProcessTagParameter(unsigned int aStoreIndex, unsigned int aCurrentIndex);
       
   262 	void ProcessOptional(unsigned int aStoreIndex, unsigned int aCurrentIndex);
       
   263 	void ProcessRequired(unsigned int aStoreIndex, unsigned int aCurrentIndex);
       
   264 	void StoreTagParameter(String aCommandName, String aParameter);
       
   265 	void StoreRlsItem(String aCommandName, String aRlsItem, int aRequired, String aDefault="");
       
   266 	void CheckWhetherAllCommentsPresent(String rlsTypeName, int commentOfInterest, std::vector<String> commentsSeen);
       
   267 	void CheckParametersArePermitted(int aCommentOfInterest, int aLineInComment, int aDefinitionNumber);
       
   268 	void CheckCommands(String aRlsTypeName, int aCommentOfInterest);
       
   269 	void AddCommentToStore();
       
   270 	bool IsAnRlsItem(String aString) const;
       
   271 	
       
   272 	int NeedToAddDefaultData(String aFileName, int aFileLine);
       
   273 	int FindIndex(const String aFileName, int aLineNumber);
       
   274 	bool CheckFirstIsCommand(LocalisationLine aCommandLine);
       
   275 	int GetTagDeclaredIndex(String aCommandName);
       
   276 
       
   277 	bool iCommentStarted;
       
   278 	std::vector<LocalisationComment> iCommentTagStore; // data split up into individual command lines
       
   279 	LocalisationLine iTempCommentStore; // holds the data brought in from yacc parsing
       
   280 	std::vector<CommentTagPair> iCommentDefinitions;
       
   281 	std::vector<WarningToOutput> iWarningStore;
       
   282 	String iTypes[4];
       
   283 	String iRlsTypes[ENumberOfRlsTypes];
       
   284 	};
       
   285 
       
   286 extern GlobalLocalisationData *pGL;	
       
   287 #ifdef __VC32__
       
   288 #pragma warning( pop )
       
   289 #endif
       
   290 
       
   291 #endif
       
   292