sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <s32file.h>
|
sl@0
|
17 |
#include <e32test.h>
|
sl@0
|
18 |
|
sl@0
|
19 |
const TInt KTestCleanupStack=0x20;
|
sl@0
|
20 |
|
sl@0
|
21 |
// This is a path specification and should not be used as is
|
sl@0
|
22 |
_LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_SHAPE.DAT");
|
sl@0
|
23 |
|
sl@0
|
24 |
class CShape;
|
sl@0
|
25 |
enum TShape {ENotAShape,ESquare,ECircle};
|
sl@0
|
26 |
typedef CShape* (*TShapeCtor)();
|
sl@0
|
27 |
class CShape : public CBase
|
sl@0
|
28 |
{
|
sl@0
|
29 |
public:
|
sl@0
|
30 |
static TShapeCtor Ctor(TShape type);
|
sl@0
|
31 |
//
|
sl@0
|
32 |
virtual void ExternalizeL(RWriteStream& aStream) const=0;
|
sl@0
|
33 |
virtual void InternalizeL(RReadStream& aStream)=0;
|
sl@0
|
34 |
//
|
sl@0
|
35 |
TStreamId StoreL(CStreamStore& aStore) const;
|
sl@0
|
36 |
void RestoreL(const CStreamStore& aStore,TStreamId anId);
|
sl@0
|
37 |
//
|
sl@0
|
38 |
virtual TPtrC Name() const=0;
|
sl@0
|
39 |
virtual TSize Extent() const=0;
|
sl@0
|
40 |
virtual TPoint Centre() const=0;
|
sl@0
|
41 |
};
|
sl@0
|
42 |
class CSquare : public CShape
|
sl@0
|
43 |
{
|
sl@0
|
44 |
public:
|
sl@0
|
45 |
static CShape* New();
|
sl@0
|
46 |
CSquare() {}
|
sl@0
|
47 |
CSquare(const TPoint& aCentre,TInt aSide);
|
sl@0
|
48 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
49 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
50 |
TPtrC Name() const;
|
sl@0
|
51 |
TSize Extent() const;
|
sl@0
|
52 |
TPoint Centre() const;
|
sl@0
|
53 |
private:
|
sl@0
|
54 |
TRect iRect;
|
sl@0
|
55 |
};
|
sl@0
|
56 |
class CCircle : public CShape
|
sl@0
|
57 |
{
|
sl@0
|
58 |
public:
|
sl@0
|
59 |
static CShape* New();
|
sl@0
|
60 |
CCircle() {}
|
sl@0
|
61 |
CCircle(const TPoint& aCentre,TInt aRadius);
|
sl@0
|
62 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
63 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
64 |
TPtrC Name() const;
|
sl@0
|
65 |
TSize Extent() const;
|
sl@0
|
66 |
TPoint Centre() const;
|
sl@0
|
67 |
private:
|
sl@0
|
68 |
TPoint iCentre;
|
sl@0
|
69 |
TInt iRadius;
|
sl@0
|
70 |
};
|
sl@0
|
71 |
|
sl@0
|
72 |
class TShapeHolder
|
sl@0
|
73 |
{
|
sl@0
|
74 |
public:
|
sl@0
|
75 |
TShapeHolder();
|
sl@0
|
76 |
TShapeHolder(TShape aType,CShape* aShape);
|
sl@0
|
77 |
//
|
sl@0
|
78 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
79 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
80 |
void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap) const;
|
sl@0
|
81 |
void RestoreComponentsL(const CStreamStore& aStore);
|
sl@0
|
82 |
//
|
sl@0
|
83 |
void ExternalizeSerialL(RWriteStream& aStream) const;
|
sl@0
|
84 |
void InternalizeSerialL(RReadStream& aStream);
|
sl@0
|
85 |
//
|
sl@0
|
86 |
TStreamId StoreL(CStreamStore& aStore) const;
|
sl@0
|
87 |
void RestoreL(const CStreamStore& aStore,TStreamId anId);
|
sl@0
|
88 |
//
|
sl@0
|
89 |
CShape* Shape() const;
|
sl@0
|
90 |
private:
|
sl@0
|
91 |
TShape iType;
|
sl@0
|
92 |
TSwizzle<CShape> iShape;
|
sl@0
|
93 |
};
|
sl@0
|
94 |
|
sl@0
|
95 |
LOCAL_D RTest test(_L("t_storshape"));
|
sl@0
|
96 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
97 |
LOCAL_D RFs TheFs;
|
sl@0
|
98 |
//LOCAL_D CBufStore* TheStore;
|
sl@0
|
99 |
LOCAL_D CFileStore* TheStore;
|
sl@0
|
100 |
LOCAL_D RStoreWriteStream TheSink;
|
sl@0
|
101 |
LOCAL_D RStoreReadStream TheSource;
|
sl@0
|
102 |
//LOCAL_D RFileWriteStream TheSink;
|
sl@0
|
103 |
//LOCAL_D RFileReadStream TheSource;
|
sl@0
|
104 |
|
sl@0
|
105 |
/**
|
sl@0
|
106 |
@SYMTestCaseID PDS-STORE-CT-4025
|
sl@0
|
107 |
@SYMTestCaseDesc Basic test for CStoreMap Forget() and Unbind() API
|
sl@0
|
108 |
@SYMTestPriority High
|
sl@0
|
109 |
@SYMTestActions Unbind stream from Map, forget sgtream from map
|
sl@0
|
110 |
@SYMTestExpectedResults map stream ID should be NUll
|
sl@0
|
111 |
@SYMDEF DEF135804
|
sl@0
|
112 |
*/
|
sl@0
|
113 |
LOCAL_C void testExtraStoreMapAPIsL()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
test.Next(_L("@SYMTestCaseID PDS-STORE-CT-4025"));
|
sl@0
|
116 |
CShape* shape=new(ELeave) CCircle(TPoint(70,80),40);
|
sl@0
|
117 |
CleanupStack::PushL(shape);
|
sl@0
|
118 |
CStoreMap* map=CStoreMap::NewLC(*TheStore);
|
sl@0
|
119 |
TStreamId id = shape->StoreL(*TheStore);
|
sl@0
|
120 |
|
sl@0
|
121 |
map->BindL(shape,id);
|
sl@0
|
122 |
test(id == map->At(shape));
|
sl@0
|
123 |
//Unbind the twizzle(shape) and test to make sure it is unbinded
|
sl@0
|
124 |
map->Unbind(shape);
|
sl@0
|
125 |
test(KNullStreamId == map->At(shape));
|
sl@0
|
126 |
|
sl@0
|
127 |
map->BindL(shape,id);
|
sl@0
|
128 |
test(shape == map->Label(id));
|
sl@0
|
129 |
//Forget the stream id and test to make sure it is forgotten
|
sl@0
|
130 |
map->Forget(id);
|
sl@0
|
131 |
test(shape != map->Label(id));
|
sl@0
|
132 |
CleanupStack::PopAndDestroy(2,shape);
|
sl@0
|
133 |
}
|
sl@0
|
134 |
/**
|
sl@0
|
135 |
@SYMTestCaseID SYSLIB-STORE-CT-1200
|
sl@0
|
136 |
@SYMTestCaseDesc Shape streaming test
|
sl@0
|
137 |
@SYMTestPriority High
|
sl@0
|
138 |
@SYMTestActions Attempt for streaming of different shapes
|
sl@0
|
139 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
140 |
@SYMREQ REQ0000
|
sl@0
|
141 |
*/
|
sl@0
|
142 |
LOCAL_C void testShapesL()
|
sl@0
|
143 |
{
|
sl@0
|
144 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1200 Shape streaming "));
|
sl@0
|
145 |
|
sl@0
|
146 |
TParsePtrC parse(KFileLocationSpec);
|
sl@0
|
147 |
//
|
sl@0
|
148 |
// TheStore=CDirectFileStore::ReplaceLC(TheFs,KTestFile,EFileRead|EFileWrite);
|
sl@0
|
149 |
TheStore=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
|
sl@0
|
150 |
TheStore->SetTypeL(TheStore->Layout());
|
sl@0
|
151 |
//
|
sl@0
|
152 |
RStoreWriteStream snk;
|
sl@0
|
153 |
TStreamId id=snk.CreateL(*TheStore);
|
sl@0
|
154 |
TShapeHolder hldr(ESquare,new(ELeave) CSquare(TPoint(20,30),40));
|
sl@0
|
155 |
hldr.ExternalizeSerialL(snk);
|
sl@0
|
156 |
delete hldr.Shape();
|
sl@0
|
157 |
hldr=TShapeHolder(ECircle,new(ELeave) CCircle(TPoint(70,80),40));
|
sl@0
|
158 |
hldr.ExternalizeSerialL(snk);
|
sl@0
|
159 |
delete hldr.Shape();
|
sl@0
|
160 |
snk.Close();
|
sl@0
|
161 |
RStoreReadStream src;
|
sl@0
|
162 |
src.OpenL(*TheStore,id);
|
sl@0
|
163 |
hldr.InternalizeSerialL(src);
|
sl@0
|
164 |
delete hldr.Shape();
|
sl@0
|
165 |
hldr.InternalizeSerialL(src);
|
sl@0
|
166 |
delete hldr.Shape();
|
sl@0
|
167 |
src.Close();
|
sl@0
|
168 |
//
|
sl@0
|
169 |
hldr=TShapeHolder(ESquare,new(ELeave) CSquare(TPoint(20,30),40));
|
sl@0
|
170 |
id=hldr.StoreL(*TheStore);
|
sl@0
|
171 |
delete hldr.Shape();
|
sl@0
|
172 |
hldr.RestoreL(*TheStore,id);
|
sl@0
|
173 |
delete hldr.Shape();
|
sl@0
|
174 |
//
|
sl@0
|
175 |
CShape* shape=new(ELeave) CCircle(TPoint(70,80),40);
|
sl@0
|
176 |
CStoreMap* map=CStoreMap::NewL(*TheStore);
|
sl@0
|
177 |
TStreamId id2 = shape->StoreL(*TheStore);
|
sl@0
|
178 |
|
sl@0
|
179 |
testExtraStoreMapAPIsL();
|
sl@0
|
180 |
|
sl@0
|
181 |
map->BindL(shape,id2);
|
sl@0
|
182 |
snk=RStoreWriteStream(*map);
|
sl@0
|
183 |
id=snk.CreateL(*TheStore);
|
sl@0
|
184 |
snk<<shape;
|
sl@0
|
185 |
snk.Close();
|
sl@0
|
186 |
delete shape;
|
sl@0
|
187 |
src.OpenL(*TheStore,id);
|
sl@0
|
188 |
src>>id;
|
sl@0
|
189 |
src.Close();
|
sl@0
|
190 |
shape=new(ELeave) CCircle;
|
sl@0
|
191 |
shape->RestoreL(*TheStore,id);
|
sl@0
|
192 |
delete map;
|
sl@0
|
193 |
TRAPD(r,shape->RestoreL(*TheStore,id));
|
sl@0
|
194 |
test(r==KErrNotFound);
|
sl@0
|
195 |
delete shape;
|
sl@0
|
196 |
//
|
sl@0
|
197 |
CleanupStack::PopAndDestroy();
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
//
|
sl@0
|
201 |
// Prepare the test directory.
|
sl@0
|
202 |
//
|
sl@0
|
203 |
LOCAL_C void setupTestDirectory()
|
sl@0
|
204 |
{
|
sl@0
|
205 |
TInt r=TheFs.Connect();
|
sl@0
|
206 |
test(r==KErrNone);
|
sl@0
|
207 |
//
|
sl@0
|
208 |
TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));
|
sl@0
|
209 |
TParse parse;
|
sl@0
|
210 |
parse.Set(drive.Name(), &KFileLocationSpec, NULL);
|
sl@0
|
211 |
|
sl@0
|
212 |
r=TheFs.MkDir(parse.DriveAndPath());
|
sl@0
|
213 |
test(r==KErrNone||r==KErrAlreadyExists);
|
sl@0
|
214 |
r=TheFs.SetSessionPath(parse.DriveAndPath());
|
sl@0
|
215 |
test(r==KErrNone);
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
//
|
sl@0
|
219 |
// Initialise the cleanup stack.
|
sl@0
|
220 |
//
|
sl@0
|
221 |
LOCAL_C void setupCleanup()
|
sl@0
|
222 |
{
|
sl@0
|
223 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
224 |
test(TheTrapCleanup!=NULL);
|
sl@0
|
225 |
TRAPD(r,\
|
sl@0
|
226 |
{\
|
sl@0
|
227 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
228 |
CleanupStack::PushL((TAny*)1);\
|
sl@0
|
229 |
test(r==KErrNone);\
|
sl@0
|
230 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
231 |
});
|
sl@0
|
232 |
test(r==KErrNone);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
236 |
{
|
sl@0
|
237 |
RFs fsSession;
|
sl@0
|
238 |
TInt err = fsSession.Connect();
|
sl@0
|
239 |
if(err == KErrNone)
|
sl@0
|
240 |
{
|
sl@0
|
241 |
TEntry entry;
|
sl@0
|
242 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
245 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
246 |
if(err != KErrNone)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
249 |
}
|
sl@0
|
250 |
err = fsSession.Delete(aFullName);
|
sl@0
|
251 |
if(err != KErrNone)
|
sl@0
|
252 |
{
|
sl@0
|
253 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
}
|
sl@0
|
256 |
fsSession.Close();
|
sl@0
|
257 |
}
|
sl@0
|
258 |
else
|
sl@0
|
259 |
{
|
sl@0
|
260 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
261 |
}
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
//
|
sl@0
|
265 |
// Test the streaming framework.
|
sl@0
|
266 |
//
|
sl@0
|
267 |
GLDEF_C TInt E32Main()
|
sl@0
|
268 |
{
|
sl@0
|
269 |
test.Title();
|
sl@0
|
270 |
setupTestDirectory();
|
sl@0
|
271 |
setupCleanup();
|
sl@0
|
272 |
__UHEAP_MARK;
|
sl@0
|
273 |
//
|
sl@0
|
274 |
TRAPD(r,testShapesL());
|
sl@0
|
275 |
test(r==KErrNone);
|
sl@0
|
276 |
|
sl@0
|
277 |
//deletion of data files must be before call to .End() - DEF047652
|
sl@0
|
278 |
TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));
|
sl@0
|
279 |
TParse parse;
|
sl@0
|
280 |
parse.Set(drive.Name(), &KFileLocationSpec, NULL);
|
sl@0
|
281 |
::DeleteDataFile(parse.FullName());
|
sl@0
|
282 |
|
sl@0
|
283 |
test.End();
|
sl@0
|
284 |
//
|
sl@0
|
285 |
__UHEAP_MARKEND;
|
sl@0
|
286 |
|
sl@0
|
287 |
delete TheTrapCleanup;
|
sl@0
|
288 |
TheFs.Close();
|
sl@0
|
289 |
test.Close();
|
sl@0
|
290 |
return 0;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
TShapeCtor CShape::Ctor(TShape type)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
switch (type)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
case ESquare:
|
sl@0
|
298 |
return &CSquare::New;
|
sl@0
|
299 |
case ECircle:
|
sl@0
|
300 |
return &CCircle::New;
|
sl@0
|
301 |
default:
|
sl@0
|
302 |
return NULL;
|
sl@0
|
303 |
}
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
TStreamId CShape::StoreL(CStreamStore& aStore) const
|
sl@0
|
307 |
{
|
sl@0
|
308 |
RStoreWriteStream stream;
|
sl@0
|
309 |
TStreamId id=stream.CreateLC(aStore);
|
sl@0
|
310 |
ExternalizeL(stream);
|
sl@0
|
311 |
stream.CommitL();
|
sl@0
|
312 |
CleanupStack::PopAndDestroy();
|
sl@0
|
313 |
return id;
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
void CShape::RestoreL(const CStreamStore& aStore,TStreamId anId)
|
sl@0
|
317 |
{
|
sl@0
|
318 |
RStoreReadStream stream;
|
sl@0
|
319 |
stream.OpenLC(aStore,anId);
|
sl@0
|
320 |
InternalizeL(stream);
|
sl@0
|
321 |
CleanupStack::PopAndDestroy();
|
sl@0
|
322 |
}
|
sl@0
|
323 |
|
sl@0
|
324 |
CShape* CSquare::New()
|
sl@0
|
325 |
{
|
sl@0
|
326 |
return new CSquare;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
CSquare::CSquare(const TPoint& aCentre,TInt aSide)
|
sl@0
|
330 |
{
|
sl@0
|
331 |
TInt offset=aSide/2;
|
sl@0
|
332 |
iRect.iTl.iX=aCentre.iX-offset;
|
sl@0
|
333 |
iRect.iTl.iY=aCentre.iY-offset;
|
sl@0
|
334 |
iRect.iBr.iX=iRect.iTl.iX+aSide;
|
sl@0
|
335 |
iRect.iBr.iY=iRect.iTl.iY+aSide;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
void CSquare::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
339 |
{
|
sl@0
|
340 |
aStream.WriteUint32L(iRect.iTl.iX);
|
sl@0
|
341 |
aStream.WriteUint32L(iRect.iTl.iY);
|
sl@0
|
342 |
aStream.WriteUint32L(iRect.iBr.iX);
|
sl@0
|
343 |
aStream.WriteUint32L(iRect.iBr.iY);
|
sl@0
|
344 |
}
|
sl@0
|
345 |
|
sl@0
|
346 |
void CSquare::InternalizeL(RReadStream& aStream)
|
sl@0
|
347 |
{
|
sl@0
|
348 |
iRect.iTl.iX=aStream.ReadUint32L();
|
sl@0
|
349 |
iRect.iTl.iY=aStream.ReadUint32L();
|
sl@0
|
350 |
iRect.iBr.iX=aStream.ReadUint32L();
|
sl@0
|
351 |
iRect.iBr.iY=aStream.ReadUint32L();
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
sl@0
|
354 |
TPtrC CSquare::Name() const
|
sl@0
|
355 |
{
|
sl@0
|
356 |
return _L("Square");
|
sl@0
|
357 |
}
|
sl@0
|
358 |
|
sl@0
|
359 |
TSize CSquare::Extent() const
|
sl@0
|
360 |
{
|
sl@0
|
361 |
return (iRect.iBr-iRect.iTl).AsSize();
|
sl@0
|
362 |
}
|
sl@0
|
363 |
|
sl@0
|
364 |
TPoint CSquare::Centre() const
|
sl@0
|
365 |
{
|
sl@0
|
366 |
return TPoint((iRect.iBr.iX-iRect.iTl.iX)/2,(iRect.iBr.iY-iRect.iTl.iY)/2);
|
sl@0
|
367 |
}
|
sl@0
|
368 |
|
sl@0
|
369 |
CShape* CCircle::New()
|
sl@0
|
370 |
{
|
sl@0
|
371 |
return new CCircle;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
CCircle::CCircle(const TPoint& aCentre,TInt aRadius)
|
sl@0
|
375 |
: iCentre(aCentre),iRadius(aRadius)
|
sl@0
|
376 |
{}
|
sl@0
|
377 |
|
sl@0
|
378 |
void CCircle::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
379 |
{
|
sl@0
|
380 |
aStream.WriteUint32L(iCentre.iX);
|
sl@0
|
381 |
aStream.WriteUint32L(iCentre.iY);
|
sl@0
|
382 |
aStream.WriteUint32L(iRadius);
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
void CCircle::InternalizeL(RReadStream& aStream)
|
sl@0
|
386 |
{
|
sl@0
|
387 |
iCentre.iX=aStream.ReadUint32L();
|
sl@0
|
388 |
iCentre.iY=aStream.ReadUint32L();
|
sl@0
|
389 |
iRadius=aStream.ReadUint32L();
|
sl@0
|
390 |
}
|
sl@0
|
391 |
|
sl@0
|
392 |
TPtrC CCircle::Name() const
|
sl@0
|
393 |
{
|
sl@0
|
394 |
return _L("Circle");
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
TSize CCircle::Extent() const
|
sl@0
|
398 |
{
|
sl@0
|
399 |
TInt diameter=iRadius*2;
|
sl@0
|
400 |
return TSize(diameter,diameter);
|
sl@0
|
401 |
}
|
sl@0
|
402 |
|
sl@0
|
403 |
TPoint CCircle::Centre() const
|
sl@0
|
404 |
{
|
sl@0
|
405 |
return iCentre;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
|
sl@0
|
408 |
TShapeHolder::TShapeHolder()
|
sl@0
|
409 |
: iType(ENotAShape),iShape(NULL)
|
sl@0
|
410 |
{}
|
sl@0
|
411 |
|
sl@0
|
412 |
TShapeHolder::TShapeHolder(TShape aType,CShape* aShape)
|
sl@0
|
413 |
: iType(aType),iShape(aShape)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
__ASSERT_DEBUG((iType==ENotAShape)==(aShape==NULL),User::Panic(_L("gargl"),0));
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
void TShapeHolder::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
419 |
{
|
sl@0
|
420 |
aStream.WriteUint8L(iType);
|
sl@0
|
421 |
aStream<<iShape;
|
sl@0
|
422 |
}
|
sl@0
|
423 |
|
sl@0
|
424 |
void TShapeHolder::InternalizeL(RReadStream& aStream)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
TShape type=TShape(aStream.ReadUint8L());
|
sl@0
|
427 |
if ((type==ENotAShape)!=(CShape::Ctor(type)==NULL))
|
sl@0
|
428 |
User::Leave(KErrCorrupt); // representation violation!!!
|
sl@0
|
429 |
//
|
sl@0
|
430 |
aStream>>iShape;
|
sl@0
|
431 |
iType=type;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
|
sl@0
|
434 |
void TShapeHolder::StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap) const
|
sl@0
|
435 |
{
|
sl@0
|
436 |
if (iShape!=NULL)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
TStreamId id=iShape->StoreL(aStore);
|
sl@0
|
439 |
aMap.BindL(iShape,id);
|
sl@0
|
440 |
}
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
void TShapeHolder::RestoreComponentsL(const CStreamStore& aStore)
|
sl@0
|
444 |
{
|
sl@0
|
445 |
TShapeCtor ctor=CShape::Ctor(iType);
|
sl@0
|
446 |
CShape* shape=NULL;
|
sl@0
|
447 |
if (ctor!=NULL)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
User::LeaveIfNull(shape=(*ctor)());
|
sl@0
|
450 |
CleanupStack::PushL(shape);
|
sl@0
|
451 |
shape->RestoreL(aStore,iShape.AsId());
|
sl@0
|
452 |
CleanupStack::Pop();
|
sl@0
|
453 |
}
|
sl@0
|
454 |
iShape=shape;
|
sl@0
|
455 |
}
|
sl@0
|
456 |
|
sl@0
|
457 |
void TShapeHolder::ExternalizeSerialL(RWriteStream& aStream) const
|
sl@0
|
458 |
{
|
sl@0
|
459 |
aStream.WriteUint8L(iType);
|
sl@0
|
460 |
if (iShape!=NULL)
|
sl@0
|
461 |
aStream<<*iShape;
|
sl@0
|
462 |
}
|
sl@0
|
463 |
|
sl@0
|
464 |
void TShapeHolder::InternalizeSerialL(RReadStream& aStream)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
TShape type=TShape(aStream.ReadUint8L());
|
sl@0
|
467 |
TShapeCtor ctor=CShape::Ctor(type);
|
sl@0
|
468 |
if ((type==ENotAShape)!=(ctor==NULL))
|
sl@0
|
469 |
User::Leave(1832); // representation violation!!!
|
sl@0
|
470 |
//
|
sl@0
|
471 |
CShape* shape=NULL;
|
sl@0
|
472 |
if (ctor!=NULL)
|
sl@0
|
473 |
{
|
sl@0
|
474 |
User::LeaveIfNull(shape=(*ctor)());
|
sl@0
|
475 |
CleanupStack::PushL(shape);
|
sl@0
|
476 |
aStream>>*shape;
|
sl@0
|
477 |
CleanupStack::Pop();
|
sl@0
|
478 |
}
|
sl@0
|
479 |
iType=type;
|
sl@0
|
480 |
iShape=shape;
|
sl@0
|
481 |
}
|
sl@0
|
482 |
|
sl@0
|
483 |
TStreamId TShapeHolder::StoreL(CStreamStore& aStore) const
|
sl@0
|
484 |
{
|
sl@0
|
485 |
CStoreMap* map=CStoreMap::NewLC(aStore);
|
sl@0
|
486 |
StoreComponentsL(aStore,*map);
|
sl@0
|
487 |
//
|
sl@0
|
488 |
RStoreWriteStream stream(*map);
|
sl@0
|
489 |
TStreamId id=stream.CreateLC(aStore);
|
sl@0
|
490 |
ExternalizeL(stream);
|
sl@0
|
491 |
stream.CommitL();
|
sl@0
|
492 |
//
|
sl@0
|
493 |
map->Reset();
|
sl@0
|
494 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
495 |
return id;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
void TShapeHolder::RestoreL(const CStreamStore& aStore,TStreamId anId)
|
sl@0
|
499 |
{
|
sl@0
|
500 |
RStoreReadStream stream;
|
sl@0
|
501 |
stream.OpenLC(aStore,anId);
|
sl@0
|
502 |
InternalizeL(stream);
|
sl@0
|
503 |
CleanupStack::PopAndDestroy();
|
sl@0
|
504 |
//
|
sl@0
|
505 |
RestoreComponentsL(aStore);
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
CShape* TShapeHolder::Shape() const
|
sl@0
|
509 |
{
|
sl@0
|
510 |
return iShape;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|