|
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: |
|
15 * |
|
16 */ |
|
17 #include "CdlCompilerToolkit/CdlTkInstance.h" |
|
18 #include "CdlTkPriv.h" |
|
19 using namespace std; |
|
20 |
|
21 namespace CdlCompilerToolkit { |
|
22 |
|
23 |
|
24 // |
|
25 // CCdlTkImplementation |
|
26 // |
|
27 |
|
28 CCdlTkImplementation::CCdlTkImplementation(const CCdlTkInstance& aInstance, const CCdlTkApi& aApi) |
|
29 : iInstance(aInstance), iApi(aApi) |
|
30 { |
|
31 SetNull(); |
|
32 } |
|
33 |
|
34 CCdlTkImplementation::~CCdlTkImplementation() |
|
35 { |
|
36 } |
|
37 |
|
38 string CCdlTkImplementation::Definition() const |
|
39 { |
|
40 return iDefn; |
|
41 } |
|
42 |
|
43 void CCdlTkImplementation::SetDefinition(const string& aDefn) |
|
44 { |
|
45 iDefn = aDefn; |
|
46 } |
|
47 |
|
48 const string KTemplateFuncDefn = "\ |
|
49 $TYPE $NAME$PARAMS\n\ |
|
50 \t{\n\ |
|
51 \t//TODO: Implement this function.\n\ |
|
52 \t}"; |
|
53 |
|
54 void CCdlTkImplementation::SetTemplateDefinition() |
|
55 { |
|
56 if (iApi.IsFunc()) |
|
57 { |
|
58 CdlTkUtil::CReplaceSet defnSet; |
|
59 defnSet.Add("$TYPE", iApi.ReturnType()); |
|
60 defnSet.Add("$NAME", iApi.Name()); |
|
61 defnSet.Add("$PARAMS", iApi.ParamsTypeAndNameList()); |
|
62 iDefn = CdlTkUtil::MultiReplace(defnSet, KTemplateFuncDefn); |
|
63 } |
|
64 else |
|
65 { |
|
66 string typeVar; |
|
67 iDefn = GetTranslation(iApi.ReturnType(), typeVar)->Definition(); |
|
68 CdlTkUtil::CReplaceSet defnSet; |
|
69 defnSet.Add(KType, typeVar); |
|
70 defnSet.Add(KName, iApi.Name()); |
|
71 iDefn = CdlTkUtil::MultiReplace(defnSet, iDefn); |
|
72 CdlTkUtil::AppendString(iDefn, ";\t//TODO: Initialise this data."); |
|
73 } |
|
74 } |
|
75 |
|
76 const CCdlTkDataTypeTranslation* CCdlTkImplementation::GetTranslation(const string& aType, string& aTypeVar) |
|
77 { |
|
78 return iApi.Interface().DataTypeTranslations().Find(aType, aTypeVar); |
|
79 } |
|
80 |
|
81 string CCdlTkImplementation::PointerReference() const |
|
82 { |
|
83 return iPtr; |
|
84 } |
|
85 |
|
86 void CCdlTkImplementation::SetPointerReference(const string& aPtr) |
|
87 { |
|
88 iPtr = aPtr; |
|
89 } |
|
90 |
|
91 void CCdlTkImplementation::SetTemplatePointerReference() |
|
92 { |
|
93 if (iApi.IsFunc()) |
|
94 { |
|
95 iPtr = string("&") + iApi.Name(); |
|
96 } |
|
97 else |
|
98 { |
|
99 string typeVar; |
|
100 iPtr = GetTranslation(iApi.ReturnType(), typeVar)->PointerReference(); |
|
101 CdlTkUtil::CReplaceSet ptrSet; |
|
102 ptrSet.Add(KType, typeVar); |
|
103 ptrSet.Add(KName, iApi.Name()); |
|
104 iPtr = CdlTkUtil::MultiReplace(ptrSet, iPtr); |
|
105 } |
|
106 } |
|
107 |
|
108 const CCdlTkInstance& CCdlTkImplementation::Instance() const |
|
109 { |
|
110 return iInstance; |
|
111 } |
|
112 |
|
113 const CCdlTkApi& CCdlTkImplementation::Api() const |
|
114 { |
|
115 return iApi; |
|
116 } |
|
117 |
|
118 const string& CCdlTkImplementation::Name() const |
|
119 { |
|
120 return iApi.Name(); |
|
121 } |
|
122 |
|
123 void CCdlTkImplementation::SetTemplate() |
|
124 { |
|
125 SetTemplateDefinition(); |
|
126 SetTemplatePointerReference(); |
|
127 } |
|
128 |
|
129 void CCdlTkImplementation::SetNull() |
|
130 { |
|
131 SetDefinition(""); |
|
132 SetPointerReference("NULL"); |
|
133 } |
|
134 |
|
135 |
|
136 // |
|
137 // CCdlTkImplementations |
|
138 // |
|
139 |
|
140 CCdlTkImplementations::CCdlTkImplementations(const CCdlTkInstance& aInstance, const CCdlTkApiList& aApiList) |
|
141 { |
|
142 for (CCdlTkApiList::const_iterator pApi = aApiList.begin(); pApi != aApiList.end(); ++pApi) |
|
143 { |
|
144 iImpl.push_back(new CCdlTkImplementation(aInstance, **pApi)); |
|
145 } |
|
146 } |
|
147 |
|
148 CCdlTkImplementations::~CCdlTkImplementations() |
|
149 { |
|
150 for (CImpl::iterator p = iImpl.begin(); p != iImpl.end(); ++p) |
|
151 delete *p; |
|
152 } |
|
153 |
|
154 CCdlTkImplementation* CCdlTkImplementations::Find(const string& aName) const |
|
155 { |
|
156 for (CImpl::const_iterator p = iImpl.begin(); p != iImpl.end(); ++p) |
|
157 { |
|
158 if ((*p)->Name() == aName) |
|
159 return *p; |
|
160 } |
|
161 return 0; |
|
162 } |
|
163 |
|
164 void CCdlTkImplementations::ClearAll() |
|
165 { |
|
166 for (CImpl::iterator pImp = iImpl.begin(); pImp != iImpl.end(); ++pImp) |
|
167 { |
|
168 (*pImp)->SetNull(); |
|
169 } |
|
170 } |
|
171 |
|
172 void CCdlTkImplementations::TemplateAll() |
|
173 { |
|
174 for (CImpl::iterator pImp = iImpl.begin(); pImp != iImpl.end(); ++pImp) |
|
175 { |
|
176 (*pImp)->SetTemplate(); |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 // |
|
182 // CCdlTkInstance |
|
183 // |
|
184 |
|
185 #pragma warning (disable:4355) // using "this" in initialisation list |
|
186 // note: "this" is not accessed during construction of iImpl |
|
187 CCdlTkInstance::CCdlTkInstance(const CCdlTkInterface& aInterface) |
|
188 : iInterface(aInterface), iImpl(*this, aInterface.ApiList()), iId(KCdlTkGetInstanceIdFromHostDll) |
|
189 { |
|
190 if (iInterface.Base() || iInterface.Extension()) |
|
191 throw CdlTkAssert("Can't create instance from extended interface - merge extensions first"); |
|
192 } |
|
193 #pragma warning (default:4355) // using "this" in initialisation list |
|
194 |
|
195 CCdlTkInstance::~CCdlTkInstance() |
|
196 { |
|
197 } |
|
198 |
|
199 CCdlTkImplementations& CCdlTkInstance::Impl() |
|
200 { |
|
201 return iImpl; |
|
202 } |
|
203 |
|
204 const CCdlTkImplementations& CCdlTkInstance::Impl() const |
|
205 { |
|
206 return iImpl; |
|
207 } |
|
208 |
|
209 void CCdlTkInstance::SetName(const string& aName) |
|
210 { |
|
211 iName = aName; |
|
212 } |
|
213 |
|
214 const string& CCdlTkInstance::Name() const |
|
215 { |
|
216 return iName; |
|
217 } |
|
218 |
|
219 std::string CCdlTkInstance::DllInstanceName() const |
|
220 { |
|
221 return InstanceNameToDllInstanceName(iName); |
|
222 } |
|
223 |
|
224 const string KDllInstanceName = "KDllInst_$INST"; |
|
225 |
|
226 std::string CCdlTkInstance::InstanceNameToDllInstanceName(const std::string& aName) |
|
227 { |
|
228 return CdlTkUtil::Replace("$INST", CdlTkUtil::ToCpp(aName), KDllInstanceName); |
|
229 } |
|
230 |
|
231 |
|
232 const CCdlTkInterface& CCdlTkInstance::Interface() const |
|
233 { |
|
234 return iInterface; |
|
235 } |
|
236 |
|
237 void CCdlTkInstance::SetId() |
|
238 { |
|
239 iId = KCdlTkGetInstanceIdFromHostDll; |
|
240 } |
|
241 |
|
242 void CCdlTkInstance::SetId(int aId) |
|
243 { |
|
244 iId = aId; |
|
245 } |
|
246 |
|
247 int CCdlTkInstance::Id() const |
|
248 { |
|
249 return iId; |
|
250 } |
|
251 |
|
252 const string& CCdlTkInstance::ExtraCpp() const |
|
253 { |
|
254 return iExtraCpp; |
|
255 } |
|
256 |
|
257 void CCdlTkInstance::SetExtraCpp(const string& aExtra) |
|
258 { |
|
259 iExtraCpp = aExtra; |
|
260 } |
|
261 |
|
262 void CCdlTkInstance::ClearAllImplementations() |
|
263 { |
|
264 iImpl.ClearAll(); |
|
265 } |
|
266 |
|
267 void CCdlTkInstance::TemplateAllImplementations() |
|
268 { |
|
269 iImpl.TemplateAll(); |
|
270 } |
|
271 |
|
272 } // end of namespace CdlCompilerToolkit |
|
273 |