|
1 /* |
|
2 * Copyright (c) 2002-2006 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 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
20 #pragma warning (disable:4786) |
|
21 |
|
22 #include "MLCompData2Cdl.h" |
|
23 #include "MLCompDataParse.h" |
|
24 #include "MLAttributesParse.h" |
|
25 #include "LayoutCompilerErr.h" |
|
26 #include <cdlcompilertoolkit/cdltkprocess.h> |
|
27 #include <fstream> |
|
28 #include <iostream> |
|
29 #include <algorithm> |
|
30 #include "CppWriter.h" |
|
31 #include "CodeGenConsts.h" |
|
32 |
|
33 using namespace std; |
|
34 |
|
35 typedef LayoutProcessArgsErr<MLCompDataToCdl> MLCompDataToCdlArgsErr; |
|
36 |
|
37 // constants |
|
38 |
|
39 const int KGeneratedInterfaceMajorVer = 1; |
|
40 const int KGeneratedInterfaceMinorVer = 0; |
|
41 |
|
42 const string KCompDataFileNameSuffix("compData"); |
|
43 const string KAttributesFileNameSuffix("attributes"); |
|
44 |
|
45 |
|
46 // |
|
47 // MLCompDataToCdl |
|
48 // |
|
49 MLCompDataToCdl::CApiNamesUsed MLCompDataToCdl::iInterfaceNamesUsed; |
|
50 |
|
51 string MLCompDataToCdl::InterfaceName(const string& aFileName) |
|
52 { |
|
53 return aFileName.substr(0,aFileName.find_last_of('.')); |
|
54 } |
|
55 |
|
56 int MLCompDataToCdl::Process(const vector<string>& args) |
|
57 { |
|
58 iInterfaceNamesUsed.clear(); |
|
59 |
|
60 int numExpectedArgs = 4; |
|
61 if(args.size() < numExpectedArgs) |
|
62 throw MLCompDataToCdlArgsErr(); |
|
63 |
|
64 int arg = 2; |
|
65 bool deletesAllowed = true; |
|
66 if (args[arg] == "-nodeletes") |
|
67 { |
|
68 deletesAllowed = false; |
|
69 arg++; |
|
70 numExpectedArgs++; |
|
71 } |
|
72 |
|
73 bool allParams = false; |
|
74 if (args[arg] == "-allparams") |
|
75 { |
|
76 allParams = true; |
|
77 arg++; |
|
78 numExpectedArgs++; |
|
79 } |
|
80 |
|
81 bool romOnly = false; |
|
82 if (args[arg] == "-romonly") |
|
83 { |
|
84 romOnly = true; |
|
85 arg++; |
|
86 numExpectedArgs++; |
|
87 } |
|
88 |
|
89 int numLayouts = args.size() - numExpectedArgs; |
|
90 if (numLayouts < 1) |
|
91 throw MLCompDataToCdlArgsErr(); |
|
92 |
|
93 TMLCompData* mergedLayout = NULL; |
|
94 TMLAttributes* mergedAttribs = NULL; |
|
95 for(int ii = 0; ii < numLayouts; ii++) |
|
96 { |
|
97 string layoutName = args[arg++]; |
|
98 string attribsName = CdlTkUtil::Replace(KCompDataFileNameSuffix, KAttributesFileNameSuffix, layoutName); |
|
99 |
|
100 auto_ptr<TMLCompDataParseLayout> layoutParse = TMLCompDataParseLayout::Parse(layoutName); |
|
101 auto_ptr<TMLCompData> layout(layoutParse.get()); |
|
102 layoutParse.release(); |
|
103 |
|
104 auto_ptr<TMLAttributesParse> attribsParse = TMLAttributesParse::Parse(attribsName); |
|
105 auto_ptr<TMLAttributes> attribs(attribsParse.get()); |
|
106 attribsParse.release(); |
|
107 |
|
108 if (mergedLayout || mergedAttribs) |
|
109 { |
|
110 // first we merge the components and the attributes |
|
111 mergedLayout->MergeComponents(*layout); |
|
112 mergedAttribs->Merge(*attribs); |
|
113 } |
|
114 else |
|
115 { |
|
116 // first time around |
|
117 mergedLayout = layout.get(); |
|
118 mergedAttribs = attribs.get(); |
|
119 } |
|
120 layout.release(); |
|
121 attribs.release(); |
|
122 } |
|
123 |
|
124 mergedLayout->iAttributes = mergedAttribs; // transfer ownership |
|
125 |
|
126 // once merged, we can compile the tables |
|
127 mergedLayout->Compile(); |
|
128 |
|
129 string cdlName = args[arg++]; |
|
130 int uid = CdlTkUtil::ParseInt(args[arg++]); |
|
131 |
|
132 auto_ptr<CCdlTkInterface> iface(new CCdlTkInterface); |
|
133 CCdlTkCdlFileParser parser(cdlName); |
|
134 try |
|
135 { |
|
136 iface = parser.LoadAndParse(true); |
|
137 } |
|
138 catch (const CdlTkFileOpenErr& aErr) |
|
139 { |
|
140 // there was no file, so presume that we are creating a new interface. |
|
141 aErr.Show(cerr); |
|
142 cout << "Creating new CDL API from scratch." << endl; |
|
143 } |
|
144 |
|
145 LayoutToInterface(*iface, *mergedLayout, deletesAllowed, allParams); |
|
146 |
|
147 stringstream comment; |
|
148 comment << "// Generated from "; |
|
149 |
|
150 // ignore the args up to and including the app name, the mode name, and the optional flags, |
|
151 arg = numExpectedArgs-2; |
|
152 |
|
153 // so that we get a list of processed files to output to the comment |
|
154 for(ii = 0; ii < numLayouts; ii++) |
|
155 comment << args[arg++] << ", "; |
|
156 comment << endl; |
|
157 comment << "// which was generated with timestamp " << mergedLayout->iTimestamp << endl; |
|
158 |
|
159 SetHeaders(*iface, cdlName, comment.str(), uid, romOnly); |
|
160 |
|
161 CCdlTkWriteCdlFile writer(*iface); |
|
162 cout << "writing CDL file " << cdlName << endl; |
|
163 writer.Process(); |
|
164 |
|
165 iInterfaceNamesUsed.clear(); |
|
166 return 0; |
|
167 } |
|
168 |
|
169 void MLCompDataToCdl::ShowHelp(ostream& stream) |
|
170 { |
|
171 stream << "MLCompData2Cdl [-nodeletes] [-allparams] [-romonly] (<MLCompDataName>)+ <cdlName> <UID>" << endl; |
|
172 stream << " If the CDL file does not exist, writes out the API in the order of the MLCompData." << endl; |
|
173 stream << " If the CDL file does exist, and -nodeletes is not used, fills holes and appends new APIs to the end, to preseve API compatibility." << endl; |
|
174 stream << " If the CDL file does exist, and -nodeletes is used, processing will halt and report an error if any of the existing APIs are missing." << endl; |
|
175 stream << " If the CDL file does exist, existing APIs that do not have required params will be updated, appending missing params with default values." << endl; |
|
176 stream << " If -allparams is used, all processed APIs will have all available params added, otherwise only needed params are added." << endl; |
|
177 stream << " If -romonly is used, and if there is a previous CDL API it did not include the KCdlFlagRomOnly flag, then the flag will be added to the updated API." << endl; |
|
178 stream << " If more than one layout is supplied, they are merged together, and then the interface of the merged data is generated. " << endl; |
|
179 stream << " e.g. from \\S60\\AknLayout2\\group run " << endl; |
|
180 stream << " aknlayoutcompiler MLCompData2CDL -nodeletes ..\\xml\\pdp_av_dbl_prt\\display_eur_compData.xml ..\\xml\\pdl_av_dbl_lsc\\display_eur_compData.xml ..\\cdl\\AknLayoutScalable_Avkon.cdl 0x1020384E" << endl; |
|
181 stream << " aknlayoutcompiler MLCompData2CDL -nodeletes ..\\xml\\pdp_apps_dbl_prt\\display_eur_compData.xml ..\\xml\\pdl_apps_dbl_lsc\\display_eur_compData.xml ..\\cdl\\AknLayoutScalable_Apps.cdl 0x1020384F" << endl; |
|
182 } |
|
183 |
|
184 void MLCompDataToCdl::LayoutToInterface(CCdlTkInterface& aInterface, const TMLCompData& aLayout, bool aDeletesAllowed, bool aAllParams) |
|
185 { |
|
186 const bool needsOptions = true; |
|
187 const bool needsColsRows = true; |
|
188 const bool doesntNeedOptions = false; |
|
189 const bool doesntNeedColsRows = false; |
|
190 |
|
191 AddGenericApiToInterface(aInterface, KTypeLayoutScalableComponentType, KFuncGetComponentTypeById, doesntNeedOptions, doesntNeedColsRows); |
|
192 AddGenericApiToInterface(aInterface, KTypeLayoutScalableParameterLimits, KFuncGetParamLimitsById, needsOptions, doesntNeedColsRows); |
|
193 AddGenericApiToInterface(aInterface, KTypeWindowComponentLayout, KFuncGetWindowComponentById, needsOptions, needsColsRows); |
|
194 AddGenericApiToInterface(aInterface, KTypeTextComponentLayout, KFuncGetTextComponentById, needsOptions, needsColsRows); |
|
195 |
|
196 for (TMLCompData::const_iterator pTab = aLayout.begin(); pTab != aLayout.end(); ++pTab) |
|
197 { |
|
198 AddTableToInterface(aInterface, **pTab, aAllParams); |
|
199 } |
|
200 ReplaceRemovedAPIs(aInterface, aLayout, aDeletesAllowed); |
|
201 CleanUpAPIComments(aInterface); |
|
202 } |
|
203 |
|
204 void MLCompDataToCdl::AddGenericApiToInterface(CCdlTkInterface& aInterface, const string& aReturnType, const string& aName, bool aNeedsOptions, bool aRequiresColsRows) |
|
205 { |
|
206 bool isNew = false; |
|
207 const bool needsComponentId = true; |
|
208 const bool doesntNeedAllParams = false; |
|
209 CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, aReturnType, aName, isNew); |
|
210 |
|
211 CCdlTkApiParams& params = funcApi->Params(); |
|
212 CCdlTkApiParams oldParams = params; |
|
213 UpdateParams(oldParams, params, aName, doesntNeedAllParams, aRequiresColsRows, isNew, needsComponentId, aNeedsOptions, aRequiresColsRows, aRequiresColsRows); |
|
214 |
|
215 funcApi->SetComment(string("// Generic API\n")); |
|
216 } |
|
217 |
|
218 void MLCompDataToCdl::AddTableToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, bool aAllParams) |
|
219 { |
|
220 int line = 0; |
|
221 for (TMLCompDataTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) |
|
222 { |
|
223 // only add parameter limits if the line is not simple |
|
224 bool needsParamLimits = (*pLine)->NeedsOptions() || (*pLine)->NeedsCols() || (*pLine)->NeedsRows(); |
|
225 if(needsParamLimits) |
|
226 { |
|
227 AddParamLimitsToInterface(aInterface, **pLine, aAllParams); |
|
228 } |
|
229 AddLineToInterface(aInterface, **pLine, aAllParams); |
|
230 |
|
231 for (TMLCompDataTable::TMLCompDataSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) |
|
232 { |
|
233 TMLCompDataTable::TMLCompDataSubTable& sub = **pSub; |
|
234 int last = *(sub.rbegin()); |
|
235 if(line == last) |
|
236 { |
|
237 AddSubTableLimitsToInterface(aInterface, aTable, sub); |
|
238 if(needsParamLimits) |
|
239 AddSubTableParamLimitsToInterface(aInterface, aTable, sub, aAllParams); |
|
240 AddSubTableToInterface(aInterface, aTable, sub, aAllParams); |
|
241 } |
|
242 } |
|
243 |
|
244 line++; |
|
245 } |
|
246 } |
|
247 |
|
248 void MLCompDataToCdl::AddTableCommentToApi(TMLCompDataTable& aTable, CCdlTkApi& aApi) |
|
249 { |
|
250 aApi.SetComment(string("// LAF Table : ") + aTable.Name() + "\n"); |
|
251 } |
|
252 |
|
253 void MLCompDataToCdl::AddTableCommentToApi(TMLCompDataLine& aLine, CCdlTkApi& aApi) |
|
254 { |
|
255 if(aLine.iParentTable) |
|
256 { |
|
257 TMLCompDataTable& table = *(aLine.iParentTable); |
|
258 AddTableCommentToApi(table, aApi); |
|
259 } |
|
260 } |
|
261 |
|
262 void MLCompDataToCdl::AddLineToInterface(CCdlTkInterface& aInterface, TMLCompDataLine& aLine, bool aAllParams) |
|
263 { |
|
264 bool isNew = false; |
|
265 const bool requiresColsRows = true; |
|
266 CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, ReturnType(aLine), LineApiName(aLine), isNew); |
|
267 AddParamsToFunc(aLine, *funcApi, aAllParams, isNew, requiresColsRows); |
|
268 AddTableCommentToApi(aLine, *funcApi); |
|
269 } |
|
270 |
|
271 void MLCompDataToCdl::AddParamLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataLine& aLine, bool aAllParams) |
|
272 { |
|
273 bool isNew = false; |
|
274 const bool doesntRequireColsRows = false; |
|
275 CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, KTypeLayoutScalableParameterLimits, LineParamLimitsApiName(aLine), isNew); |
|
276 AddParamsToFunc(aLine, *funcApi, aAllParams, isNew, doesntRequireColsRows); |
|
277 AddTableCommentToApi(aLine, *funcApi); |
|
278 } |
|
279 |
|
280 void MLCompDataToCdl::AddSubTableToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, bool aAllParams) |
|
281 { |
|
282 bool isNew = false; |
|
283 const bool requiresColsRows = true; |
|
284 TMLCompDataLine& line = *aTable[aSubTable[0]]; |
|
285 CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, ReturnType(line), SubTableApiName(aSubTable), isNew); |
|
286 AddParamsToFunc(aTable, aSubTable, *funcApi, aAllParams, isNew, requiresColsRows); |
|
287 AddTableCommentToApi(aTable, *funcApi); |
|
288 } |
|
289 |
|
290 void MLCompDataToCdl::AddSubTableLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable) |
|
291 { |
|
292 bool isNew = false; |
|
293 CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, KTypeLayoutScalableTableLimits, SubTableLimitsApiName(aSubTable), isNew); |
|
294 AddTableCommentToApi(aTable, *funcApi); |
|
295 } |
|
296 |
|
297 void MLCompDataToCdl::AddSubTableParamLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, bool aAllParams) |
|
298 { |
|
299 bool isNew = false; |
|
300 const bool doesntRequireColsRows = false; |
|
301 CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, KTypeLayoutScalableParameterLimits, SubTableParamLimtsApiName(aSubTable), isNew); |
|
302 AddParamsToFunc(aTable, aSubTable, *funcApi, aAllParams, isNew, doesntRequireColsRows); |
|
303 AddTableCommentToApi(aTable, *funcApi); |
|
304 } |
|
305 |
|
306 void MLCompDataToCdl::AddParamsToFunc(TMLCompDataLine& aLine, CCdlTkFunctionApi& aFunc, bool aAllParams, bool aIsNew, bool aColsRowsRequired) |
|
307 { |
|
308 CCdlTkApiParams& params = aFunc.Params(); |
|
309 CCdlTkApiParams oldParams = params; |
|
310 |
|
311 const bool doesntNeedComponentId = false; |
|
312 bool options = aLine.NeedsOptions(); |
|
313 bool cols = aLine.NeedsCols(); |
|
314 bool rows = aLine.NeedsRows(); |
|
315 UpdateParams(oldParams, params, LineApiName(aLine), aAllParams, aColsRowsRequired, aIsNew, doesntNeedComponentId, options, cols, rows); |
|
316 } |
|
317 |
|
318 void MLCompDataToCdl::AddParamsToFunc(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CCdlTkFunctionApi& aFunc, bool aAllParams, bool aIsNew, bool aColsRowsRequired) |
|
319 { |
|
320 CCdlTkApiParams& params = aFunc.Params(); |
|
321 CCdlTkApiParams oldParams = params; |
|
322 |
|
323 if(aIsNew || params.FindByName(KParamLineIndex) == params.end()) |
|
324 params.insert(params.begin(), CCdlTkApiParam(KTypeInt, KParamLineIndex)); |
|
325 |
|
326 const bool doesntNeedComponentId = false; |
|
327 bool options = aSubTable.iNeedsOption; |
|
328 bool cols = aSubTable.iNeedsCol; |
|
329 bool rows = aSubTable.iNeedsRow; |
|
330 UpdateParams(oldParams, params, SubTableApiName(aSubTable), aAllParams, aColsRowsRequired, aIsNew, doesntNeedComponentId, options, cols, rows); |
|
331 } |
|
332 |
|
333 void MLCompDataToCdl::SetHeaders(CCdlTkInterface& aInterface, const string& aCdlName, const string& aComment, int aUid, bool aRomOnly) |
|
334 { |
|
335 aInterface.SetFileName(aCdlName); |
|
336 aInterface.SetAdditionalComment(aComment); |
|
337 aInterface.Header().SetUid(aUid); |
|
338 |
|
339 // Note that if the rom only flag was already set in the existing API, then it will remain on |
|
340 // even if -romonly was not supplied as a command line argument. To remove the flag, |
|
341 // the CDL file must be manually edited. |
|
342 if(aRomOnly) |
|
343 aInterface.Header().Flags().SetFlag("KCdlFlagRomOnly"); |
|
344 |
|
345 string ifName(InterfaceName(CdlTkUtil::StripPath(aCdlName))); |
|
346 aInterface.Header().SetName(ifName); |
|
347 aInterface.Header().SetVersion(CCdlTkInterfaceHeader::CVersion(KGeneratedInterfaceMajorVer, KGeneratedInterfaceMinorVer)); |
|
348 |
|
349 CCdlTkCpp& cpp = aInterface.Cpp(); |
|
350 int size = cpp.size(); |
|
351 if(!find(cpp.begin(), cpp.end(), KIncludeLayoutInstanceHeaderScalableDef)) |
|
352 cpp.push_back(KIncludeLayoutInstanceHeaderScalableDef); |
|
353 } |
|
354 |
|
355 string MLCompDataToCdl::SubTableApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable) |
|
356 { |
|
357 return CdlTkUtil::ToCpp(aSubTable.iName); |
|
358 } |
|
359 |
|
360 string MLCompDataToCdl::SubTableLimitsApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable) |
|
361 { |
|
362 return CdlTkUtil::ToCpp(aSubTable.iName + KFuncLimitsSuffix); |
|
363 } |
|
364 |
|
365 string MLCompDataToCdl::SubTableParamLimtsApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable) |
|
366 { |
|
367 return CdlTkUtil::ToCpp(aSubTable.iName + KFuncParamLimitsSuffix); |
|
368 } |
|
369 |
|
370 string MLCompDataToCdl::LineApiName(TMLCompDataLine& aLine) |
|
371 { |
|
372 return CdlTkUtil::ToCpp(aLine.iName); |
|
373 } |
|
374 |
|
375 string MLCompDataToCdl::LineParamLimitsApiName(TMLCompDataLine& aLine) |
|
376 { |
|
377 return CdlTkUtil::ToCpp(aLine.iName + KFuncParamLimitsSuffix); |
|
378 } |
|
379 |
|
380 string MLCompDataToCdl::ReturnType(TMLCompDataLine& aLine) |
|
381 { |
|
382 string returnType = "BadType"; |
|
383 switch(aLine.iType) |
|
384 { |
|
385 case TMLCompDataLine::EScreenComponent: |
|
386 case TMLCompDataLine::EContainerComponent: |
|
387 case TMLCompDataLine::EPaneComponent: |
|
388 case TMLCompDataLine::EGraphicComponent: |
|
389 { |
|
390 returnType = KTypeWindowComponentLayout; |
|
391 break; |
|
392 } |
|
393 case TMLCompDataLine::ETextComponent: |
|
394 { |
|
395 returnType = KTypeTextComponentLayout; |
|
396 break; |
|
397 } |
|
398 default: |
|
399 { |
|
400 throw GeneralErr(" MLCompDataToCdl::ReturnType - uncategorised component"); |
|
401 break; |
|
402 } |
|
403 } |
|
404 |
|
405 return returnType; |
|
406 } |
|
407 |
|
408 void MLCompDataToCdl::ReplaceRemovedAPIs(CCdlTkInterface& aInterface, const TMLCompData& aLayout, bool aDeletesAllowed) |
|
409 { |
|
410 bool error = false; |
|
411 // look for apis for which there is no equivalent internal structure. |
|
412 CCdlTkApiList& apiList = aInterface.ApiList(); |
|
413 for(CCdlTkApiList::reverse_iterator pApi = apiList.rbegin(); pApi != apiList.rend(); ++pApi) |
|
414 { |
|
415 CCdlTkApi*& api = *pApi; |
|
416 string apiName = api->Name(); |
|
417 if(iInterfaceNamesUsed.find(apiName) == iInterfaceNamesUsed.end()) |
|
418 { |
|
419 if(aDeletesAllowed) |
|
420 { |
|
421 delete api; // remove the missing api |
|
422 CCdlTkApi*& last = *(apiList.rbegin()); // get a reference to the pointer to the last element |
|
423 api = last; // copy the last element pointer to fill the gap |
|
424 |
|
425 // erasing the last element will not invalidate our reverse iterator |
|
426 // but we need a forward iterator to the last element, |
|
427 // so take the address of our reference to the pointer |
|
428 apiList.erase(&last); |
|
429 cout << "Replacing missing API: " << apiName << " <- " << api->Name() << endl; |
|
430 } |
|
431 else |
|
432 { |
|
433 error = true; |
|
434 cout << "Detected missing API: " << apiName << endl; |
|
435 } |
|
436 } |
|
437 } |
|
438 if(error) |
|
439 { |
|
440 throw GeneralErr("Error: -nodeletes was specified on command line, but some APIs were missing."); |
|
441 } |
|
442 } |
|
443 |
|
444 void MLCompDataToCdl::CleanUpAPIComments(CCdlTkInterface& aInterface) |
|
445 { |
|
446 string currentComment; |
|
447 CCdlTkApiList& apiList = aInterface.ApiList(); |
|
448 for(CCdlTkApiList::iterator pApi = apiList.begin(); pApi != apiList.end(); ++pApi) |
|
449 { |
|
450 CCdlTkApi& api = **pApi; |
|
451 string nextComment = api.Comment(); |
|
452 if(nextComment == currentComment) |
|
453 api.SetComment(string()); |
|
454 else |
|
455 currentComment = nextComment; |
|
456 } |
|
457 } |
|
458 |
|
459 CCdlTkFunctionApi* MLCompDataToCdl::ProcessFunctionApi(CCdlTkInterface& aInterface, string aReturnType, string aName, bool& aIsNew) |
|
460 { |
|
461 iInterfaceNamesUsed.insert(aName); |
|
462 CCdlTkFunctionApi* funcApi; |
|
463 CCdlTkApi* api = aInterface.ApiList().Find(aName); |
|
464 if(api) |
|
465 { |
|
466 funcApi = static_cast<CCdlTkFunctionApi*>(api); |
|
467 UpdateFunctionApi(*funcApi, aInterface, aReturnType, aName); |
|
468 } |
|
469 else |
|
470 { |
|
471 funcApi = CreateFunctionApi(aInterface, aReturnType, aName); |
|
472 aIsNew = true; |
|
473 } |
|
474 funcApi->SetReturnType(aReturnType); |
|
475 funcApi->SetName(aName); |
|
476 return funcApi; |
|
477 } |
|
478 |
|
479 CCdlTkFunctionApi* MLCompDataToCdl::CreateFunctionApi(CCdlTkInterface& aInterface, string aReturnType, string aName) |
|
480 { |
|
481 cout << "Adding new API: " << aName << endl; |
|
482 CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); |
|
483 api->SetReturnType(aReturnType); |
|
484 api->SetName(aName); |
|
485 aInterface.ApiList().push_back(api); |
|
486 return api; |
|
487 } |
|
488 |
|
489 void MLCompDataToCdl::UpdateFunctionApi(CCdlTkFunctionApi& aApi, CCdlTkInterface& aInterface, string aReturnType, string aName) |
|
490 { |
|
491 aApi.SetReturnType(aReturnType); |
|
492 aApi.SetName(aName); |
|
493 } |
|
494 |
|
495 void MLCompDataToCdl::UpdateParams( |
|
496 CCdlTkApiParams& aOldParams, |
|
497 CCdlTkApiParams& aParams, |
|
498 string aApiName, |
|
499 bool aAllParamsRequested, |
|
500 bool aColsRowsRequired, |
|
501 bool aIsNew, |
|
502 bool aNeedsComponentId, |
|
503 bool aNeedsOptions, |
|
504 bool aNeedsCols, |
|
505 bool aNeedsRows) |
|
506 { |
|
507 const bool allParamsDoesntApply = false; |
|
508 AddParamToParams(aOldParams, aParams, KParamComponentId, allParamsDoesntApply, aIsNew, aNeedsComponentId); |
|
509 AddParamToParams(aOldParams, aParams, KParamOptionIndex, aAllParamsRequested, aIsNew, aNeedsOptions); |
|
510 AddParamToParams(aOldParams, aParams, KParamColIndex, aAllParamsRequested && aColsRowsRequired, aIsNew, aNeedsCols && aColsRowsRequired); |
|
511 AddParamToParams(aOldParams, aParams, KParamRowIndex, aAllParamsRequested && aColsRowsRequired, aIsNew, aNeedsRows && aColsRowsRequired); |
|
512 |
|
513 if(aOldParams != aParams) |
|
514 cout << "Updating parameters: " << aApiName << endl; |
|
515 } |
|
516 |
|
517 void MLCompDataToCdl::AddParamToParams( |
|
518 CCdlTkApiParams& aOldParams, |
|
519 CCdlTkApiParams& aParams, |
|
520 string aType, |
|
521 bool aAllParamsRequested, |
|
522 bool aIsNewLine, |
|
523 bool aNeedsParam) |
|
524 { |
|
525 // only add new params if needed |
|
526 bool alreadyPresent = aOldParams.FindByName(aType) != aOldParams.end(); |
|
527 if((aNeedsParam || aAllParamsRequested) && !alreadyPresent) |
|
528 { |
|
529 // the only circumstance in which we don't use a default parameter, |
|
530 // is if we're adding a needed param to a new line |
|
531 bool needsDefaultValue = !(aIsNewLine && aNeedsParam); |
|
532 |
|
533 string defaultValue; |
|
534 if(aParams.size() != 0 && aParams.back().DefaultValue() == CdlTkUtil::IntToString(0)) |
|
535 { |
|
536 defaultValue = CdlTkUtil::IntToString(0); |
|
537 } |
|
538 else |
|
539 { |
|
540 defaultValue = needsDefaultValue ? CdlTkUtil::IntToString(0) : string(); |
|
541 } |
|
542 CCdlTkApiParam param(KTypeInt, aType, defaultValue); |
|
543 aParams.push_back(param); |
|
544 } |
|
545 } |
|
546 |