|
1 /* |
|
2 * Copyright (c) 2000-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 |
|
18 |
|
19 #ifndef UNIQUEINSTANCEIMPL_H_ |
|
20 #define UNIQUEINSTANCEIMPL_H_ |
|
21 |
|
22 #include "UniqueInstance.h" |
|
23 |
|
24 namespace UniqueInstance |
|
25 { |
|
26 |
|
27 /** |
|
28 @internalComponent |
|
29 */ |
|
30 void DestroyRUniqueInstance(void* runique); |
|
31 /** |
|
32 * Reference-counted object. |
|
33 * |
|
34 * @internalComponent |
|
35 * @since App-frameworks6.1 |
|
36 */ |
|
37 struct SElement |
|
38 { |
|
39 TInt iRefCount; |
|
40 void* iObject; |
|
41 }; |
|
42 |
|
43 /** |
|
44 * Skip list holding sorted, reference counted objects |
|
45 * |
|
46 * @internalComponent |
|
47 * @since App-frameworks6.1 |
|
48 */ |
|
49 class RSkipList |
|
50 { |
|
51 public: |
|
52 struct TSection |
|
53 { |
|
54 TSection* iLinks[1]; |
|
55 SElement iElement; |
|
56 }; |
|
57 |
|
58 RSkipList& operator=(const RSkipList&); |
|
59 RSkipList(const RSkipList&); |
|
60 |
|
61 void TestLinks(TSection* aStart, TSection* aEnd, TInt aLink) const; |
|
62 |
|
63 RSkipList() : iSentinel(0), iCompare(0) {} |
|
64 ~RSkipList(); |
|
65 void Open(TCompareFn* aCompare, TInt aMaxLinks); |
|
66 void Close(); |
|
67 |
|
68 /** |
|
69 * Adds an element only if it already exists, otherwise returns 0 |
|
70 */ |
|
71 SElement* AddExisting(void* aElt); |
|
72 /** |
|
73 * Adds a new element. aNewElt must not already have an equivalent in this |
|
74 * skip list. |
|
75 */ |
|
76 SElement* AddNewL(void* aNewElt); |
|
77 /** |
|
78 * Removes the element, no matter what its reference count is. Return a pointer |
|
79 * to the object, which is now no longer owned. |
|
80 */ |
|
81 void* Remove(void* aNoLongerNeeded); |
|
82 /** |
|
83 * Returns true iff skip list has no elements. |
|
84 */ |
|
85 TBool IsEmpty() const; |
|
86 /** |
|
87 * Runs tests on the integrity of the skip list. |
|
88 * Returns the number of elements in the list. |
|
89 */ |
|
90 TInt Test() const; |
|
91 |
|
92 private: |
|
93 TSection* iSentinel; |
|
94 TInt iLinkCount; |
|
95 TCompareFn* iCompare; |
|
96 |
|
97 TSection** FirstLink() const; |
|
98 |
|
99 TInt GenerateNumLinks() const; |
|
100 }; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Implements the unique instance repository behaviour |
|
105 * |
|
106 * @internalComponent |
|
107 * @since App-frameworks6.1 |
|
108 */ |
|
109 NONSHARABLE_CLASS(UniqueInstance::CRepositoryImpl) : public CBase |
|
110 { |
|
111 public: |
|
112 CRepositoryImpl(TCompareFn* aCompare, TDeleteFn* aDelete, TCopyFnL* aCopyL, |
|
113 TInt aObjectSize); |
|
114 ~CRepositoryImpl(); |
|
115 void ConstructL(TInt aMaxLinks); |
|
116 |
|
117 /** |
|
118 * Adds aElt to the list, passing ownership. |
|
119 */ |
|
120 SElement* InsertOrIncL(void* aElt); |
|
121 /** |
|
122 * Adds aElt to the list with the caller retaining ownership. |
|
123 */ |
|
124 SElement* IncOrCopyL(void* aElt); |
|
125 /** |
|
126 * Deletes from the list. aNoLongerNeeded points to an element of the list. |
|
127 */ |
|
128 void DeleteOrDec(UniqueInstance::SElement* aNoLongerNeeded); |
|
129 /** |
|
130 * Removes from the list, passing ownership back to the caller. |
|
131 */ |
|
132 void* DetatchOrCopyL(UniqueInstance::SElement* aWritableCopyNeeded); |
|
133 /** |
|
134 * Returns a prototype null element. Ownership is retained. |
|
135 */ |
|
136 SElement* NullElement(); |
|
137 /** |
|
138 * Compares the element pointer passed against the prototype null element. |
|
139 */ |
|
140 TBool IsNull(SElement* a) const; |
|
141 /** |
|
142 * Runs an integrity check. Panics on failure. |
|
143 */ |
|
144 void Test() const; |
|
145 |
|
146 private: |
|
147 TCompareFn* iCompare; |
|
148 TDeleteFn* iDelete; |
|
149 TCopyFnL* iCopyL; |
|
150 TInt iObjectSize; |
|
151 |
|
152 SElement iNullElement; |
|
153 RSkipList iSkipList; |
|
154 }; |
|
155 |
|
156 #endif // UNIQUEINSTANCEIMPL_H_ |