1 /* |
|
2 * Copyright (c) 2007-2008 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: Header for MulDataPath |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mul/muldatapath.h> |
|
20 |
|
21 #include <vector> |
|
22 #include <osn/osnnew.h> |
|
23 #include <osn/ustring.h> |
|
24 #include <algorithm> //for equal algorithm |
|
25 |
|
26 namespace Alf |
|
27 { |
|
28 |
|
29 class MulDataPathImpl |
|
30 { |
|
31 |
|
32 public: |
|
33 |
|
34 MulDataPathImpl():mIndex(-1) |
|
35 { |
|
36 } |
|
37 |
|
38 ~MulDataPathImpl() |
|
39 { |
|
40 mPath.clear(); |
|
41 } |
|
42 |
|
43 public: |
|
44 std::vector<int> mPath; //store index of node for each depth |
|
45 int mIndex; |
|
46 }; |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // MulDataPath |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 OSN_EXPORT MulDataPath::MulDataPath() |
|
53 { |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // MulDataPath |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 OSN_EXPORT MulDataPath::MulDataPath( int aIndexForDepth1 ) |
|
61 { |
|
62 Append( aIndexForDepth1 ); |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // MulDataPath |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 OSN_EXPORT MulDataPath::MulDataPath( int aIndexForDepth1, int aIndexForDepth2) |
|
70 { |
|
71 Append( aIndexForDepth1 ); |
|
72 Append( aIndexForDepth2 ); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // MulDataPath |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 OSN_EXPORT MulDataPath::MulDataPath( const MulDataPath& aPath ) |
|
80 { |
|
81 if(aPath.mData.get()) |
|
82 { |
|
83 SetIndex( aPath.Index() ); |
|
84 for( int i = 0 ; i < aPath.Depth() ; ++i ) |
|
85 { |
|
86 Append( aPath[i] ); |
|
87 } |
|
88 } |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // ~MulDataPath |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 OSN_EXPORT MulDataPath::~MulDataPath() |
|
96 { |
|
97 if( mData.get() ) |
|
98 { |
|
99 mData->mPath.clear(); |
|
100 } |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Append |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 OSN_EXPORT void MulDataPath::Append(int aIndex) |
|
108 { |
|
109 if( !mData.get() ) |
|
110 { |
|
111 mData.reset( new (EMM) MulDataPathImpl() ); |
|
112 } |
|
113 mData->mPath.push_back(aIndex); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Depth |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 OSN_EXPORT int MulDataPath::Depth() const |
|
121 { |
|
122 if( mData.get() ) |
|
123 { |
|
124 return mData->mPath.size(); |
|
125 } |
|
126 else |
|
127 { |
|
128 return -1; |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // operator[] |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 OSN_EXPORT int MulDataPath::operator[]( int aDepth ) const |
|
137 { |
|
138 if( mData.get() ) |
|
139 { |
|
140 return (mData->mPath)[aDepth]; |
|
141 } |
|
142 else |
|
143 { |
|
144 return -1; |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // operator[] |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 bool MulDataPath::operator< ( MulDataPath& aPath) |
|
153 { |
|
154 bool result(false); |
|
155 |
|
156 //i dont wanted to add Index to original path because it is not part of path |
|
157 //but index is quite necessary for comparition so creating temp vector |
|
158 //and copying path to temp vector and also appending index to path |
|
159 std::vector<int> v1 = mData->mPath; |
|
160 v1.push_back(Index()); |
|
161 |
|
162 std::vector<int> v2 = aPath.mData->mPath; |
|
163 v2.push_back(aPath.Index()); |
|
164 |
|
165 result = lexicographical_compare(v1.begin(),v1.end(),v2.begin(),v2.end()); |
|
166 |
|
167 return result; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // Index |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 int MulDataPath::Index() const |
|
175 { |
|
176 if(mData.get()) |
|
177 { |
|
178 return mData->mIndex; |
|
179 } |
|
180 return -1; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // SetIndex |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void MulDataPath::SetIndex(int aIndex) |
|
188 { |
|
189 if( !mData.get() ) |
|
190 { |
|
191 mData.reset( new (EMM) MulDataPathImpl() ); |
|
192 } |
|
193 mData->mIndex = aIndex; |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // IsEqual |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 bool MulDataPath::IsEqual( const MulDataPath& aPath ) |
|
201 { |
|
202 if( (*this) == aPath ) |
|
203 { |
|
204 if( Depth() == -1 && aPath.Depth() == -1 ) |
|
205 { |
|
206 return true; |
|
207 } |
|
208 else |
|
209 { |
|
210 return Index() == aPath.Index(); |
|
211 } |
|
212 } |
|
213 else |
|
214 { |
|
215 return false; |
|
216 } |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Operator == |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 bool MulDataPath::operator == ( const MulDataPath& aPath) |
|
224 { |
|
225 #ifdef _DEBUG |
|
226 int depth1 = Depth(); |
|
227 int depth2 = aPath.Depth(); |
|
228 #endif |
|
229 |
|
230 //if depth is -1 , it mean that it points to root node |
|
231 if( Depth() == -1 && aPath.Depth() == -1 ) |
|
232 { |
|
233 return true; |
|
234 } |
|
235 else if((Depth() == -1 && aPath.Depth() == 0 ) || (Depth() == 0 && aPath.Depth() == -1 )) |
|
236 { |
|
237 return true; |
|
238 } |
|
239 else if( Depth() != aPath.Depth() ) |
|
240 { |
|
241 return false; |
|
242 } |
|
243 else |
|
244 { |
|
245 return equal( mData->mPath.begin(), mData->mPath.end(), aPath.mData->mPath.begin()); |
|
246 } |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // Operator = |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void MulDataPath::operator= ( MulDataPath aPath ) |
|
254 { |
|
255 if( aPath.mData.get() ) |
|
256 { |
|
257 if( mData.get() ) |
|
258 { |
|
259 mData->mPath.clear(); |
|
260 } |
|
261 |
|
262 SetIndex( aPath.Index() ); |
|
263 for( int i = 0 ; i < aPath.Depth() ; ++i ) |
|
264 { |
|
265 Append( aPath[i] ); |
|
266 } |
|
267 } |
|
268 } |
|
269 |
|
270 } //namespace Alf |
|
271 |
|
272 //End of file |
|