1 /* |
|
2 * Copyright (c) 2007 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 CAM_RARRAY_H |
|
20 #define CAM_RARRAY_H |
|
21 |
|
22 class CCamRArray : public CBase |
|
23 { |
|
24 public: |
|
25 |
|
26 CCamRArray( TUint32* aArray, TInt aSize ) |
|
27 : iReferenced ( NULL ), |
|
28 iReferenceCount( 0 ), |
|
29 iArray( aArray ), |
|
30 iSize ( aSize ) |
|
31 {}; |
|
32 |
|
33 CCamRArray( CCamRArray& aOther ) |
|
34 { |
|
35 CCamRArray::MakeCopy( aOther, *this ); |
|
36 }; |
|
37 |
|
38 public: |
|
39 |
|
40 void Attach() |
|
41 { |
|
42 ++iReferenceCount; |
|
43 }; |
|
44 |
|
45 void Detach() |
|
46 { |
|
47 if( --iReferenceCount <= 0 ) |
|
48 delete this; |
|
49 } |
|
50 |
|
51 inline TUint32& operator[]( TInt aIndex ) |
|
52 { |
|
53 return iArray[aIndex]; |
|
54 }; |
|
55 |
|
56 inline const TUint32& operator[]( TInt aIndex ) const |
|
57 { |
|
58 return iArray[aIndex]; |
|
59 }; |
|
60 |
|
61 inline TInt Size() const |
|
62 { |
|
63 return iSize; |
|
64 }; |
|
65 |
|
66 private: |
|
67 |
|
68 static void MakeCopy( CCamRArray& aFrom, CCamRArray& aTo ) |
|
69 { |
|
70 aTo.iArray = aFrom.iArray; |
|
71 aTo.iSize = aFrom.iSize; |
|
72 |
|
73 for( TInt i = 1; i < aTo.Size(); i++) |
|
74 { |
|
75 TInt tempp = aTo[i]; |
|
76 TInt tempp2 = aFrom[i]; |
|
77 } |
|
78 |
|
79 aFrom.Attach(); // aTo is one reference more. |
|
80 aTo.iReferenced = &aFrom; // Used to detach aTo from aFrom |
|
81 } |
|
82 |
|
83 ~CCamRArray() |
|
84 { |
|
85 if( iReferenced ) |
|
86 iReferenced->Detach(); |
|
87 else |
|
88 delete [] iArray; |
|
89 |
|
90 iArray = NULL; |
|
91 iSize = 0; |
|
92 }; |
|
93 |
|
94 private: |
|
95 |
|
96 TInt iReferenceCount; |
|
97 CCamRArray* iReferenced; |
|
98 |
|
99 TUint32* iArray; |
|
100 TInt iSize; |
|
101 }; |
|
102 |
|
103 #endif |
|