|
1 /* |
|
2 * Copyright (c) 2002 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 |
|
20 #include "LayPerfWriter.h" |
|
21 #include "Lay2Cdl.h" // for static methods |
|
22 #include "Layout.h" // for constants |
|
23 #include "CodeGenConsts.h" |
|
24 |
|
25 #include <cdlcompilertoolkit/cdltkutil.h> |
|
26 |
|
27 #include <iostream> |
|
28 #include <sstream> |
|
29 #include <set> |
|
30 #include <fstream> |
|
31 #include <algorithm> |
|
32 |
|
33 using namespace std; |
|
34 using namespace CdlCompilerToolkit; |
|
35 |
|
36 |
|
37 // |
|
38 // TLayPerfTableWriter |
|
39 // |
|
40 |
|
41 TLayPerfTableWriter::TLayPerfTableWriter(TLayoutTable& aTable, string& aInterfaceName, int aTableId) |
|
42 : |
|
43 iTable(aTable), |
|
44 iInterfaceName(aInterfaceName), |
|
45 iTableId(aTableId) |
|
46 { |
|
47 } |
|
48 |
|
49 TLayPerfTableWriter::~TLayPerfTableWriter() |
|
50 { |
|
51 } |
|
52 |
|
53 void TLayPerfTableWriter::Write(ostream& out) |
|
54 { |
|
55 if (IsWindowTable()) |
|
56 { |
|
57 WriteWindowTable(out); |
|
58 } |
|
59 else if (IsTextTable()) |
|
60 { |
|
61 WriteTextTable(out); |
|
62 } |
|
63 else |
|
64 { |
|
65 cout << "Unknown " << "Table " << iTable.Name() << endl; |
|
66 } |
|
67 } |
|
68 |
|
69 bool TLayPerfTableWriter::IsWindowTable() |
|
70 { |
|
71 return iTable.iType == TLayoutTable::EWindowTable; |
|
72 } |
|
73 |
|
74 |
|
75 const string KTestAPITableFuntionSig = "\ |
|
76 testLayout_$LAYOUT_$TABLEID()"; |
|
77 |
|
78 string GenerateFunctionName(string aInterfaceName, int aTableId) |
|
79 { |
|
80 string tableNum = CdlTkUtil::IntToString(aTableId); |
|
81 |
|
82 CdlTkUtil::CReplaceSet rep; |
|
83 rep.Add("$LAYOUT", aInterfaceName); |
|
84 rep.Add("$TABLEID", tableNum); |
|
85 return CdlTkUtil::MultiReplace(rep, KTestAPITableFuntionSig); |
|
86 } |
|
87 |
|
88 void TLayPerfTableWriter::WriteWindowTable(ostream& out) |
|
89 { |
|
90 out << "void " << GenerateFunctionName(iInterfaceName, iTableId) << endl; |
|
91 |
|
92 out << "{" << endl; // start of function |
|
93 out << "DECLARE_LOCAL_VARS_COUNTS" << endl; |
|
94 out << "DECLARE_LOCAL_VARS_LIMITS" << endl; |
|
95 |
|
96 out << "\n// Layout MACROs for LAF Table : "; |
|
97 out << iTable.Name() << endl; |
|
98 |
|
99 for (int i=0; i<iTable.size(); ++i) |
|
100 { |
|
101 WriteWindowLine(out, *iTable[i]); |
|
102 } |
|
103 |
|
104 out << endl; |
|
105 out << "}\n" << endl; // end of function |
|
106 } |
|
107 |
|
108 void TLayPerfTableWriter::WriteWindowLine(ostream& out, TLayoutLine& aLine) |
|
109 { |
|
110 string params; |
|
111 string limits; |
|
112 |
|
113 bool mirrored = aLine.iIsMirroredHorizontally; |
|
114 const string* KParams = mirrored ? KWindowOutputOrderMirrored : KWindowOutputOrder; |
|
115 int count = KWindowOutputOrderSize; |
|
116 |
|
117 BuildGenericLine(aLine, KParams, count, params, limits); |
|
118 |
|
119 out << limits << endl; |
|
120 |
|
121 out << "LAYOUT_TEST_WINDOW_LINE( "; // macro name |
|
122 out << iInterfaceName << "::"; // namespace name |
|
123 out << LayoutToCdl::LineApiName(aLine); // api name |
|
124 out << "("; |
|
125 |
|
126 out << params << " )"; |
|
127 out << " )" << endl; // this ends the macro call |
|
128 } |
|
129 |
|
130 void TLayPerfTableWriter::BuildGenericLine(TLayoutLine& aLine, const string* aKParams, int aCount, string& aParams, string& aLimits) |
|
131 { |
|
132 vector<string> paramList; |
|
133 bool mirrored = aLine.iIsMirroredHorizontally; |
|
134 |
|
135 if (aLine.iNeedsP) |
|
136 { |
|
137 aParams += "aParent"; |
|
138 } |
|
139 |
|
140 if (aLine.iNeedsIndex) |
|
141 { |
|
142 for (int i=0; i < aCount; i++) |
|
143 { |
|
144 const string& name = aKParams[i]; |
|
145 const TValues& defValues = aLine[name]; |
|
146 if (defValues.iNeedsIndex) |
|
147 { |
|
148 string paramName = CdlTkUtil::ToCpp(defValues.ParamName()); |
|
149 if (mirrored) |
|
150 { |
|
151 if (paramName == KParamNameL) |
|
152 paramName = KParamNameR; |
|
153 else if (paramName == KParamNameR) |
|
154 paramName = KParamNameL; |
|
155 } |
|
156 |
|
157 if(find(paramList.begin(), paramList.end(), paramName) == paramList.end()) |
|
158 { |
|
159 if(aParams.size() > 0) |
|
160 aParams += ", "; |
|
161 aParams += paramName; |
|
162 paramList.push_back(paramName); |
|
163 |
|
164 aLimits += paramName + "_Limit" + " = "; |
|
165 aLimits += CdlTkUtil::IntToString(defValues.size() - 1) + "; "; // subtract one from the max value to give the upper limit |
|
166 } |
|
167 } |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 void TLayPerfTableWriter::WriteCell(ostream& out, TValues& values) |
|
173 { |
|
174 if (values.size() > 1) |
|
175 out << "{"; |
|
176 |
|
177 for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal) |
|
178 { |
|
179 if (pVal != values.begin()) |
|
180 out << ", "; |
|
181 out << *pVal; |
|
182 } |
|
183 |
|
184 if (values.size() > 1) |
|
185 out << "}"; |
|
186 |
|
187 if (values.iParam.length()) |
|
188 out << "[" << values.iParam << "]"; |
|
189 } |
|
190 |
|
191 |
|
192 bool TLayPerfTableWriter::IsTextTable() |
|
193 { |
|
194 return iTable.iType == TLayoutTable::ETextTable; |
|
195 } |
|
196 |
|
197 void TLayPerfTableWriter::WriteTextTable(ostream& out) |
|
198 { |
|
199 out << "void " << GenerateFunctionName(iInterfaceName, iTableId) << endl; |
|
200 |
|
201 out << "{" << endl; // start of function |
|
202 out << "DECLARE_LOCAL_VARS_COUNTS" << endl; |
|
203 out << "DECLARE_LOCAL_VARS_LIMITS" << endl; |
|
204 |
|
205 out << "// Layout MACROs for LAF Table : "; |
|
206 out << iTable.Name() << endl; |
|
207 |
|
208 for (int i=0; i<iTable.size(); ++i) |
|
209 { |
|
210 WriteTextLine(out, *iTable[i]); |
|
211 } |
|
212 |
|
213 out << endl; |
|
214 out << "}\n" << endl; // end of function |
|
215 } |
|
216 |
|
217 void TLayPerfTableWriter::WriteTextLine(ostream& out, TLayoutLine& aLine) |
|
218 { |
|
219 string params; |
|
220 string limits; |
|
221 |
|
222 bool mirrored = aLine.iIsMirroredHorizontally; |
|
223 const string* KParams = mirrored ? KTextOutputOrderMirrored : KTextOutputOrder; |
|
224 int count = KTextOutputOrderSize; |
|
225 |
|
226 BuildGenericLine(aLine, KParams, count, params, limits); |
|
227 |
|
228 out << limits << endl; |
|
229 |
|
230 out << "LAYOUT_TEST_TEXT_LINE( "; // macro name |
|
231 out << iInterfaceName << "::"; // namespace name |
|
232 out << LayoutToCdl::LineApiName(aLine); // api name |
|
233 out << "("; |
|
234 |
|
235 out << params << " )"; |
|
236 out << " )" << endl; // this ends the macro call |
|
237 } |
|
238 |
|
239 |
|
240 // |
|
241 // TLayPerfWriter |
|
242 // |
|
243 |
|
244 TLayPerfWriter::TLayPerfWriter(TLayout& aLayout, const std::string& aName) |
|
245 : TLayWriterBase(aLayout, aName) |
|
246 { |
|
247 } |
|
248 |
|
249 void TLayPerfWriter::Write(const std::string& aCdlName) |
|
250 { |
|
251 ofstream out(iName.c_str()); |
|
252 |
|
253 cout << "writing layout " << iName << endl; |
|
254 string cdlFileName(CdlTkUtil::StripPath(aCdlName)); |
|
255 string ifName(LayoutToCdl::InterfaceName(cdlFileName)); |
|
256 |
|
257 out << "// function implementations: " << endl; |
|
258 int tableId = 0; |
|
259 for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) |
|
260 { |
|
261 TLayPerfTableWriter writer(**pTab, ifName, tableId++); |
|
262 writer.Write(out); |
|
263 } |
|
264 |
|
265 out << "void testLayout_" << ifName << "()\n{" << endl; |
|
266 tableId = 0; |
|
267 for(;tableId < iLayout.size(); tableId++) |
|
268 { |
|
269 out << GenerateFunctionName(ifName, tableId) << ";" << endl; |
|
270 } |
|
271 out << "}\n" << endl; |
|
272 |
|
273 |
|
274 out.close(); |
|
275 } |
|
276 |
|
277 // End of File |