1 /* |
|
2 * Copyright (c) 2006 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: This file implements the various types of operations to be performed on model. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 //INCLUDES |
|
22 #include "alf/alfmodeloperation.h" |
|
23 #include <alf/alfvarianttype.h> |
|
24 #include <alf/alfexceptions.h> |
|
25 #include <osn/osnnew.h> |
|
26 |
|
27 using namespace Alf; |
|
28 |
|
29 |
|
30 OSN_EXPORT AlfModelOperation* AlfModelOperation::create( |
|
31 OperationType aOperation, int aNumContainerIndices, |
|
32 int* aContainerIndices, IAlfVariantType* aData ) |
|
33 { |
|
34 return new( EMM ) AlfModelOperation( |
|
35 aOperation, aNumContainerIndices, aContainerIndices, aData ); |
|
36 } |
|
37 |
|
38 |
|
39 OSN_EXPORT AlfModelOperation* AlfModelOperation::create( OperationType aOperation, int aNumContainerIndices, |
|
40 int* aContainerIndices, IAlfVariantType* aData, |
|
41 const UString& aDataName ) |
|
42 { |
|
43 return new( EMM ) AlfModelOperation( |
|
44 aOperation, aNumContainerIndices, aContainerIndices, aData, aDataName ); |
|
45 } |
|
46 |
|
47 AlfModelOperation::AlfModelOperation( |
|
48 OperationType aOperation, int aNumContainerIndices, |
|
49 int* aContainerIndices, IAlfVariantType* aData ) |
|
50 { |
|
51 mOperation = aOperation ; |
|
52 mNumContainerIndices = aNumContainerIndices; |
|
53 mContainerIndices = aContainerIndices ; |
|
54 mData = aData; |
|
55 } |
|
56 |
|
57 |
|
58 AlfModelOperation::AlfModelOperation( OperationType aOperation, int aNumContainerIndices, |
|
59 int* aContainerIndices, IAlfVariantType* aData, |
|
60 const UString& aDataName ) |
|
61 { |
|
62 mOperation = aOperation ; |
|
63 mNumContainerIndices = aNumContainerIndices; |
|
64 mContainerIndices = aContainerIndices ; |
|
65 mDataName = aDataName; |
|
66 mData = aData; |
|
67 } |
|
68 |
|
69 |
|
70 OSN_EXPORT AlfModelOperation::~AlfModelOperation() |
|
71 { |
|
72 delete mData; |
|
73 delete [] mContainerIndices; |
|
74 } |
|
75 |
|
76 OSN_EXPORT IAlfVariantType& AlfModelOperation::newData() const |
|
77 { |
|
78 if(mOperation == EOperationRemove) |
|
79 { |
|
80 ALF_THROW(AlfDataException,EInvalidModelOperation,"AlfModelOperation") |
|
81 } |
|
82 return *mData; |
|
83 } |
|
84 |
|
85 OSN_EXPORT const UString& AlfModelOperation::newDataName() const |
|
86 { |
|
87 if(mOperation == EOperationRemove) |
|
88 { |
|
89 ALF_THROW(AlfDataException,EInvalidModelOperation,"AlfModelOperation") |
|
90 } |
|
91 return mDataName; |
|
92 } |
|
93 |
|
94 OSN_EXPORT IAlfVariantType* AlfModelOperation::getNewData() |
|
95 { |
|
96 if(mOperation == EOperationRemove) |
|
97 { |
|
98 ALF_THROW(AlfDataException,EInvalidModelOperation,"AlfModelOperation") |
|
99 } |
|
100 IAlfVariantType* data = mData; |
|
101 mData = NULL; |
|
102 return data; |
|
103 } |
|
104 |
|
105 OSN_EXPORT AlfModelOperation::OperationType AlfModelOperation::operation() const |
|
106 { |
|
107 return mOperation; |
|
108 } |
|
109 |
|
110 |
|
111 OSN_EXPORT IAlfVariantType* AlfModelOperation::parentData( IAlfVariantType& aRoot ) const |
|
112 { |
|
113 try |
|
114 { |
|
115 if ( mNumContainerIndices == 0 ) |
|
116 { |
|
117 return NULL; |
|
118 } |
|
119 IAlfVariantType* current = &aRoot; |
|
120 for ( int i = 0; current && i < mNumContainerIndices - 1; ++i ) |
|
121 { |
|
122 if ( current->type() == IAlfVariantType::EContainer && |
|
123 mContainerIndices[i] < current->container()->count() ) |
|
124 { |
|
125 current = current->container()->item( mContainerIndices[i] ); |
|
126 } |
|
127 else if ( current->type() == IAlfVariantType::EMap && |
|
128 mContainerIndices[i] < current->map()->count() ) |
|
129 { |
|
130 current = current->map()->item( mContainerIndices[i] ); |
|
131 } |
|
132 else if ( current->type() == IAlfVariantType::EBranch ) |
|
133 { |
|
134 if ( mContainerIndices[i] == 0 ) |
|
135 { |
|
136 // Index 0 is for the parent data |
|
137 current = current->branch()->data(); |
|
138 } |
|
139 else if ( mContainerIndices[i] == 1 ) |
|
140 { |
|
141 // Index 1 is for the child data |
|
142 current = current->branch()->childData(); |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 // Not found |
|
148 return NULL; |
|
149 } |
|
150 } |
|
151 return current; |
|
152 } |
|
153 catch(AlfDataException& aException) |
|
154 { |
|
155 ALF_THROW(AlfDataException,EInvalidContainerOperation,"AlfModelOperation") |
|
156 } |
|
157 } |
|
158 |
|
159 OSN_EXPORT int AlfModelOperation::index() const |
|
160 { |
|
161 return mContainerIndices[mNumContainerIndices - 1]; |
|
162 } |
|
163 |
|
164 OSN_EXPORT int AlfModelOperation::numContainerIndices() const |
|
165 { |
|
166 return mNumContainerIndices; |
|
167 } |
|
168 |
|
169 OSN_EXPORT int AlfModelOperation::containerIndex( int aIndex ) const |
|
170 { |
|
171 return mContainerIndices[aIndex]; |
|
172 } |
|
173 |
|