|
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 UNIQUEINSTANCEBASE_H_ |
|
20 #define UNIQUEINSTANCEBASE_H_ |
|
21 |
|
22 #include <e32base.h> |
|
23 |
|
24 // The namespace UniqueInstance contains definitions that are not useful to the |
|
25 // user, but are useful to the implementation. There is no need to use any symbols |
|
26 // within it directly. |
|
27 namespace UniqueInstance |
|
28 { |
|
29 |
|
30 /** |
|
31 @internalComponent |
|
32 */ |
|
33 typedef TInt TCompareFn(void*,void*); |
|
34 |
|
35 /** |
|
36 destroy free aObject. |
|
37 @internalComponent |
|
38 */ |
|
39 typedef void TDeleteFn(void* aObjectToBeDeleted); |
|
40 /** |
|
41 Copy aObjectToCopy into a newly allocated buffer, return the new object. |
|
42 aObjectSize is the size of the object that the repository has been specialised |
|
43 to work with. If this is not a true size of the object (for example in the case |
|
44 of HBufC) this value should be ignored. |
|
45 @internalComponent |
|
46 */ |
|
47 typedef void* TCopyFnL(void* aObjectToCopy, TInt aObjectSize); |
|
48 |
|
49 struct SElement; |
|
50 class CRepositoryImpl; |
|
51 class RInstanceImpl; |
|
52 |
|
53 /** |
|
54 * Type-unsafe repository with shared equivalent objects. |
|
55 * |
|
56 * @internalComponent |
|
57 * @since App-frameworks6.1 |
|
58 */ |
|
59 NONSHARABLE_CLASS(CUniqueInstanceRepositoryBase) : public CBase |
|
60 { |
|
61 public: |
|
62 static void* DumbCopyL(void* aObjectTocopy, TInt aNumberOfBytes); |
|
63 static void DumbDelete(void* aDeleteThis); |
|
64 |
|
65 void ConstructL(TCompareFn*, TDeleteFn*, TCopyFnL*, |
|
66 TInt aMaxLinks, TInt aObjectSize); |
|
67 ~CUniqueInstanceRepositoryBase(); |
|
68 void Test() const; |
|
69 |
|
70 private: |
|
71 friend class RInstanceImpl; |
|
72 CRepositoryImpl* iImpl; |
|
73 }; |
|
74 |
|
75 /** |
|
76 * Type-unsafe repository client. |
|
77 * |
|
78 * @internalComponent |
|
79 * @since App-frameworks6.1 |
|
80 */ |
|
81 class RInstanceImpl |
|
82 { |
|
83 public: |
|
84 explicit RInstanceImpl(CUniqueInstanceRepositoryBase& aRepository); |
|
85 ~RInstanceImpl(); // asserts that no object is owned |
|
86 |
|
87 void TakeL(void* aObject); |
|
88 void TakeCopyL(void* aObject); |
|
89 void* Peek() const; |
|
90 void CopyTo(RInstanceImpl& aOther) const; |
|
91 void MoveTo(RInstanceImpl& aOther); |
|
92 void* DropL(); |
|
93 void Close(); |
|
94 |
|
95 private: |
|
96 RInstanceImpl(RInstanceImpl&); // unimplemented |
|
97 RInstanceImpl &operator=(const RInstanceImpl&); // unimplemented |
|
98 |
|
99 SElement* iPtr; |
|
100 CRepositoryImpl* iRepository; |
|
101 }; |
|
102 } |
|
103 |
|
104 #endif // UNIQUEINSTANCEBASE_H_ |
|
105 |