|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "UT_STD.H" |
|
17 |
|
18 EXPORT_C TStreamId TSwizzleCBase::AsId() const |
|
19 /** Gets the streamid of the represented object. |
|
20 |
|
21 This swizzle must currently represent the object as a stream id, otherwise |
|
22 the function raises a STORE-Store 3 panic. |
|
23 |
|
24 @return The stream id of the represented object */ |
|
25 { |
|
26 __ASSERT_ALWAYS(IsId(),Panic(EStoreSwizzleBadId)); |
|
27 return iPtr==NULL?KNullStreamId:TStreamId((TUint32)iPtr>>1); // implementation dependency |
|
28 } |
|
29 |
|
30 EXPORT_C void TSwizzleCBase::InternalizeL(RReadStream& aStream) |
|
31 /** Internalises a stream id from the read stream, constructs a swizzle from this |
|
32 stream id and copies the swizzle to this swizzle. |
|
33 |
|
34 The presence of this function means that the standard templated operator>>() |
|
35 can be used to internalise objects of this class. |
|
36 |
|
37 @param aStream Stream from which the stream id should be internalised */ |
|
38 { |
|
39 TStreamId id; |
|
40 aStream>>id; |
|
41 *this=TSwizzleCBase(id); |
|
42 } |
|
43 |
|
44 EXPORT_C TSwizzleCBase::TSwizzleCBase(TStreamId anId) |
|
45 // |
|
46 // Construct from a stream id. |
|
47 // |
|
48 : iPtr(anId==KNullStreamId?NULL:(TAny*)((anId.Value()<<1)|0x1)) |
|
49 {} |
|
50 |
|
51 EXPORT_C void TSwizzleCBase::DoExternalizeL(RWriteStream& aStream,TExternalizer<TAny> anExter) const |
|
52 // |
|
53 // Write this swizzle to aStream as an out-of-stream reference. |
|
54 // |
|
55 { |
|
56 aStream<<TStreamRef(iPtr,(IsPtr()?anExter.Function():NULL)); |
|
57 } |
|
58 |
|
59 EXPORT_C TBool TSwizzleCBase::IsPtrRep(const TAny* aPtr) |
|
60 // |
|
61 // Test whether aPtr is a valid representation for a pointer. |
|
62 // |
|
63 { |
|
64 return !((TUint32)aPtr&0x3); // implementation dependency |
|
65 } |
|
66 |
|
67 EXPORT_C TBool TSwizzleCBase::IsIdRep(const TAny* aPtr) |
|
68 // |
|
69 // Test whether aPtr is a valid representation for a stream id. |
|
70 // |
|
71 { |
|
72 return aPtr==NULL||(TUint32)aPtr&0x1; // implementation dependency |
|
73 } |
|
74 |
|
75 EXPORT_C void TSwizzleCBase::__DbgChkPtr(const TAny* aPtr) |
|
76 // |
|
77 // Check for invalid pointers. |
|
78 // |
|
79 { |
|
80 __ASSERT_ALWAYS(IsPtrRep(aPtr),Panic(EStoreSwizzleBadPtr)); |
|
81 } |
|
82 |
|
83 EXPORT_C void TSwizzleCBase::__DbgChkRef(TStreamRef aRef) |
|
84 // |
|
85 // Check for an invalid out-of-stream reference. |
|
86 // |
|
87 { |
|
88 __ASSERT_ALWAYS((IsPtrRep(aRef.Ptr())&&aRef.Function()!=NULL)||(IsIdRep(aRef.Ptr())&&aRef.Function()==NULL),Panic(EStoreSwizzleBadReference)); |
|
89 } |
|
90 |