|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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 * Note: This file may contain code to generate corrupt files for test purposes. |
|
16 * Such code is excluded from production builds by use of compiler defines; |
|
17 * it is recommended that such code should be removed if this code is ever published publicly. |
|
18 * counter for smart ponters. See CElement. |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent |
|
26 @released |
|
27 */ |
|
28 |
|
29 #ifndef __SHAREDCOUNT_H__ |
|
30 #define __SHAREDCOUNT_H__ |
|
31 |
|
32 |
|
33 #include <functional> |
|
34 #include "actualcounterbase.h" |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 class CSharedCount |
|
41 { |
|
42 friend inline bool operator == (CSharedCount const& aLeft, CSharedCount const& aRight); |
|
43 friend inline bool operator < (CSharedCount const& aLeft, CSharedCount const& aRight); |
|
44 |
|
45 private: |
|
46 CCounterBase* iBase; |
|
47 |
|
48 public: |
|
49 CSharedCount (); |
|
50 CSharedCount (CSharedCount const& aInitialiser); |
|
51 ~CSharedCount (); |
|
52 |
|
53 template <class P> CSharedCount (P aP) : iBase (0) |
|
54 { |
|
55 iBase = new CActualCounterBase <P> (aP); |
|
56 } |
|
57 |
|
58 CSharedCount & operator = (CSharedCount const& aInitialiser); |
|
59 void swap (CSharedCount & asc); |
|
60 long UseCount () const; |
|
61 |
|
62 }; |
|
63 |
|
64 |
|
65 |
|
66 inline CSharedCount::CSharedCount () : |
|
67 iBase (0) |
|
68 { |
|
69 } |
|
70 |
|
71 inline CSharedCount::~CSharedCount () |
|
72 { |
|
73 if (iBase != NULL) |
|
74 { |
|
75 iBase -> Release (); |
|
76 } |
|
77 } |
|
78 |
|
79 inline CSharedCount::CSharedCount (CSharedCount const& aInitialiser) : |
|
80 iBase (aInitialiser.iBase) |
|
81 { |
|
82 if (iBase != NULL) |
|
83 { |
|
84 iBase -> AddRef (); |
|
85 } |
|
86 } |
|
87 |
|
88 inline long CSharedCount::UseCount () const |
|
89 { |
|
90 return (iBase != NULL) ? iBase -> UseCount (): 0; |
|
91 } |
|
92 |
|
93 inline bool operator == (CSharedCount const& aLeft, CSharedCount const& aRight) |
|
94 { |
|
95 return aLeft.iBase == aRight.iBase; |
|
96 } |
|
97 |
|
98 inline bool operator < (CSharedCount const& aLeft, CSharedCount const& aRight) |
|
99 { |
|
100 return std::less <CCounterBase*> () (aLeft.iBase, aRight.iBase); |
|
101 } |
|
102 |
|
103 |
|
104 #endif // __SHAREDCOUNT_H__ |