|
1 /* |
|
2 * Copyright (c) 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: Class to hold description about one object and it's properties |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __MDSOBJECTDEF_H__ |
|
19 #define __MDSOBJECTDEF_H__ |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "mdsitemdef.h" |
|
23 |
|
24 class CMdsPropertyDef; |
|
25 |
|
26 |
|
27 /** |
|
28 * Metadata object class |
|
29 * |
|
30 * This class is responsible for holding information about one object |
|
31 * |
|
32 */ |
|
33 class CMdsObjectDef : public CMdsItemDef |
|
34 { |
|
35 friend class CMdsSchema; |
|
36 friend class CMdsNamespaceDef; |
|
37 |
|
38 public: |
|
39 |
|
40 struct TMdsColumnOrder |
|
41 { |
|
42 TInt32 iColumnId; |
|
43 const CMdsPropertyDef& iPropertyDef; |
|
44 }; |
|
45 |
|
46 enum TObjectDefFlags |
|
47 { |
|
48 EObjectDefFlagsNone = 0x0000, |
|
49 EObjectDefFlagsContext = 0x0001, |
|
50 }; |
|
51 |
|
52 /** |
|
53 * Create new objectdef object |
|
54 * @param aId id of object |
|
55 * @param aName name of object |
|
56 * @param aParent parent to actual object |
|
57 * @return pointer to new created object |
|
58 */ |
|
59 static CMdsObjectDef* NewL( const TDesC& aName, const CMdsObjectDef* aParent ); |
|
60 |
|
61 /** |
|
62 * Create new objectdef object |
|
63 * @param aId id of object |
|
64 * @param aName name of object |
|
65 * @param aParent parent to actual object |
|
66 * @return pointer to new created object |
|
67 */ |
|
68 static CMdsObjectDef* NewLC( const TDesC& aName, const CMdsObjectDef* aParent ); |
|
69 |
|
70 virtual ~CMdsObjectDef(); |
|
71 |
|
72 /** |
|
73 * Add property to property array |
|
74 * @see CommonAddPropertyL |
|
75 * @see AddMinMaxValue |
|
76 */ |
|
77 |
|
78 void AddPropertyL( const TDesC& aName, TPropertyType aType, |
|
79 const TMdCValueUnion& aMinAdd, const TMdCValueUnion& aMaxAdd, |
|
80 TBool aReadOnly, TBool aMandatory, TBool aIndexed ); |
|
81 |
|
82 /** |
|
83 * Add property to property array |
|
84 * @see CommonAddPropertyL |
|
85 * @see AddMinMaxValue |
|
86 */ |
|
87 void AddPropertyL( const TDesC& aName, TPropertyType aType, |
|
88 TInt32 aMinAdd, TInt32 aMaxAdd, |
|
89 TBool aReadOnly, TBool aMandatory, TBool aIndexed ); |
|
90 |
|
91 /** |
|
92 * Add property to property array |
|
93 * @see CommonAddPropertyL |
|
94 * @see AddMinMaxValue |
|
95 */ |
|
96 void AddPropertyL( const TDesC& aName, TPropertyType aType, |
|
97 TUint32 aMinAdd, TUint32 aMaxAdd, |
|
98 TBool aReadOnly, TBool aMandatory, TBool aIndexed ); |
|
99 |
|
100 /** |
|
101 * Add property to property array |
|
102 * @see CommonAddPropertyL |
|
103 * @see AddMinMaxValue |
|
104 */ |
|
105 void AddPropertyL( const TDesC& aName, TPropertyType aType, |
|
106 const TInt64& aMinAdd, const TInt64& aMaxAdd, |
|
107 TBool aReadOnly, TBool aMandatory, TBool aIndexed ); |
|
108 |
|
109 /** |
|
110 * Add property to property array |
|
111 * @see CommonAddPropertyL |
|
112 * @see CMdsPropertyDef::AddMinMaxValue |
|
113 */ |
|
114 void AddPropertyL( const TDesC& aName, TPropertyType aType, |
|
115 const TReal& aMinAdd, const TReal& aMaxAdd, |
|
116 TBool aReadOnly, TBool aMandatory, TBool aIndexed ); |
|
117 |
|
118 const CMdsPropertyDef* GetPropertyByIdL( TDefId aId ) const; |
|
119 |
|
120 CMdsPropertyDef* GetProperty( TUint32 aIndex ) const; |
|
121 |
|
122 CMdsPropertyDef* GetProperty( const TDesC& aName ) const; |
|
123 |
|
124 /** |
|
125 * How many properties have object |
|
126 * return properties.Count() |
|
127 */ |
|
128 inline TInt GetPropertiesCount() const; |
|
129 |
|
130 /** |
|
131 * Gets property count of object including it's parents |
|
132 * |
|
133 * @return property count |
|
134 */ |
|
135 TInt GetAllPropertiesCount() const; |
|
136 |
|
137 /** |
|
138 * Get property count of mandatory properties. |
|
139 * |
|
140 * @return mandatory property count |
|
141 */ |
|
142 TInt GetMandatoryPropertyCount() const; |
|
143 |
|
144 void SetStoredEveryInDB(); |
|
145 |
|
146 void SetNotStoredEveryInDB(); |
|
147 |
|
148 /* |
|
149 * Set that object is already stored in DB |
|
150 */ |
|
151 inline void SetC2PStoredInDB(); |
|
152 |
|
153 inline TBool GetC2PStoredInDB() const; |
|
154 |
|
155 /* |
|
156 * Gets parent of the object |
|
157 */ |
|
158 inline const CMdsObjectDef* GetParent() const; |
|
159 |
|
160 /** |
|
161 * Get property column Id |
|
162 * |
|
163 * @param aPropertyNo number of property in property array |
|
164 * @return ColumnId |
|
165 */ |
|
166 inline const TMdsColumnOrder& GetPropertyColumnL( TInt aIndex ) const; |
|
167 |
|
168 void ImportFromDBL(); |
|
169 |
|
170 /** |
|
171 * Def flags support |
|
172 */ |
|
173 inline void ResetFlags(); |
|
174 |
|
175 inline TObjectDefFlags GetFlags() const; |
|
176 |
|
177 inline void SetFlags(TObjectDefFlags aFlags); |
|
178 |
|
179 /** |
|
180 * Get required size of serialized buffer when this is serialized. |
|
181 * |
|
182 * @return required size of serialized buffer |
|
183 */ |
|
184 TUint32 RequiredBufferSize(); |
|
185 |
|
186 /** |
|
187 * Serialize own data to serialized buffer (correct position must be set |
|
188 * before calling) and return new position of serialized buffer. |
|
189 * |
|
190 * @param aBuffer serialized buffer. |
|
191 */ |
|
192 TMdCOffset SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreeSpace); |
|
193 |
|
194 protected: |
|
195 |
|
196 /** |
|
197 * Create and add property to array |
|
198 * @param aName name of property |
|
199 * @param aType type of property |
|
200 * @param aReadOnly if property is read-only |
|
201 * @param aReadOnly if property is mandatory |
|
202 * @param aId property id |
|
203 * @return pointer to new created property (on error - leave) |
|
204 */ |
|
205 CMdsPropertyDef* CommonAddPropertyL( const TDesC& aName, TPropertyType aType, |
|
206 TBool aReadOnly, TBool aMandatory, TBool aIndexed ); |
|
207 |
|
208 CMdsPropertyDef* CommonAddPropertyL( const TDesC& aName, TPropertyType aType, |
|
209 TUint32 aFlags, TDefId aId ); |
|
210 |
|
211 void MergeL( CMdsObjectDef* aObjectDef, const TBool& aDryRun ); |
|
212 |
|
213 void AddPropertyL( const TDefId aId, TPropertyType aType, TUint32 aFlags, |
|
214 const TDesC& aMinAdd, const TDesC& aMaxAdd, const TDesC& aName ); |
|
215 |
|
216 void StoreToDBL( TDefId aNamespaceDefId ); |
|
217 |
|
218 /** |
|
219 * Searching for property only in actual object (not in parents) |
|
220 * |
|
221 * @param aName name of property to find |
|
222 * @return finded property or NULL |
|
223 */ |
|
224 CMdsPropertyDef* FindProperty( const TDesC& aName ) const; |
|
225 |
|
226 private: |
|
227 inline CMdsObjectDef( const CMdsObjectDef* aParent ); |
|
228 |
|
229 /** |
|
230 * 2nd phase constructor |
|
231 * @param aName name of property |
|
232 */ |
|
233 void ConstructL( const TDesC& aName ); |
|
234 |
|
235 private: // data |
|
236 |
|
237 /** |
|
238 * Store every property read from schema file. |
|
239 */ |
|
240 RPointerArray<CMdsPropertyDef> iPropertyDefs; |
|
241 |
|
242 /** |
|
243 * store bind between column and property in object |
|
244 */ |
|
245 RArray<TMdsColumnOrder> iCol2Prop; |
|
246 |
|
247 /** |
|
248 * ObjectDef parent, there is no exist object without parent |
|
249 * (exeption is Object as an ancesor to everyone, but it's created in code |
|
250 * and cannot be read from file) |
|
251 * DO NOT DELETE, NOT OWN !!! |
|
252 */ |
|
253 const CMdsObjectDef* iParent; |
|
254 |
|
255 /** |
|
256 * object flags (e.g. context object) |
|
257 * check TObjectDefFlags |
|
258 */ |
|
259 TObjectDefFlags iFlags; |
|
260 |
|
261 /** |
|
262 * Count of mandatory properties. |
|
263 */ |
|
264 TInt iMandatoryPropertyCount; |
|
265 }; |
|
266 |
|
267 #include "mdsobjectdef.inl" |
|
268 |
|
269 #endif // __MDSOBJECTDEF_H__ |