williamr@4
|
1 |
/**
|
williamr@4
|
2 |
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@4
|
3 |
* All rights reserved.
|
williamr@4
|
4 |
* This component and the accompanying materials are made available
|
williamr@4
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
williamr@4
|
6 |
* which accompanies this distribution, and is available
|
williamr@4
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Initial Contributors:
|
williamr@4
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Contributors:
|
williamr@4
|
13 |
*
|
williamr@4
|
14 |
* Description:
|
williamr@4
|
15 |
*
|
williamr@4
|
16 |
*/
|
williamr@4
|
17 |
|
williamr@4
|
18 |
|
williamr@4
|
19 |
|
williamr@4
|
20 |
/**
|
williamr@4
|
21 |
@file
|
williamr@4
|
22 |
@publishedPartner
|
williamr@4
|
23 |
@released
|
williamr@4
|
24 |
*/
|
williamr@4
|
25 |
|
williamr@4
|
26 |
#if (!defined METADATA_H)
|
williamr@4
|
27 |
#define METADATA_H
|
williamr@4
|
28 |
|
williamr@4
|
29 |
#include <e32base.h>
|
williamr@4
|
30 |
#include <e32std.h>
|
williamr@4
|
31 |
#include <elements/cftransportmacro.h>
|
williamr@4
|
32 |
#include <elements/h_tdeallocator.h>
|
williamr@4
|
33 |
|
williamr@4
|
34 |
/**
|
williamr@4
|
35 |
Macro used to declare virtual functions from MMetaData interface and the virtual data table
|
williamr@4
|
36 |
*/
|
williamr@4
|
37 |
#define TYPEID_TABLE \
|
williamr@4
|
38 |
/** @internalComponent */ \
|
williamr@4
|
39 |
static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
|
williamr@4
|
40 |
/** @internalComponent */ \
|
williamr@4
|
41 |
static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
|
williamr@4
|
42 |
/** @internalComponent */ \
|
williamr@4
|
43 |
static const Meta::SVDataTableEntry iVDataTable[];
|
williamr@4
|
44 |
|
williamr@4
|
45 |
#define EXPORT_TYPEID_TABLE \
|
williamr@4
|
46 |
/** @internalComponent */ \
|
williamr@4
|
47 |
static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
|
williamr@4
|
48 |
/** @internalComponent */ \
|
williamr@4
|
49 |
IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
|
williamr@4
|
50 |
/** @internalComponent */ \
|
williamr@4
|
51 |
static const Meta::SVDataTableEntry iVDataTable[];
|
williamr@4
|
52 |
|
williamr@4
|
53 |
#define DATA_VTABLE \
|
williamr@4
|
54 |
/** @internalComponent */ \
|
williamr@4
|
55 |
static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
|
williamr@4
|
56 |
/** @internalComponent */ \
|
williamr@4
|
57 |
virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
|
williamr@4
|
58 |
/** @internalComponent */ \
|
williamr@4
|
59 |
virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
|
williamr@4
|
60 |
/** @internalComponent */ \
|
williamr@4
|
61 |
static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
|
williamr@4
|
62 |
/** @internalComponent */ \
|
williamr@4
|
63 |
static const Meta::SVDataTableEntry iVDataTable[];
|
williamr@4
|
64 |
|
williamr@4
|
65 |
#define EXPORT_DATA_VTABLE \
|
williamr@4
|
66 |
/** @internalComponent */ \
|
williamr@4
|
67 |
static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
|
williamr@4
|
68 |
/** @internalComponent */ \
|
williamr@4
|
69 |
virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
|
williamr@4
|
70 |
/** @internalComponent */ \
|
williamr@4
|
71 |
virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
|
williamr@4
|
72 |
/** @internalComponent */ \
|
williamr@4
|
73 |
IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
|
williamr@4
|
74 |
/** @internalComponent */ \
|
williamr@4
|
75 |
static const Meta::SVDataTableEntry iVDataTable[];
|
williamr@4
|
76 |
|
williamr@4
|
77 |
#define EXPORT_DATA_VTABLE_AND_FN \
|
williamr@4
|
78 |
/** @internalComponent */ \
|
williamr@4
|
79 |
static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
|
williamr@4
|
80 |
/** @internalComponent */ \
|
williamr@4
|
81 |
IMPORT_C virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
|
williamr@4
|
82 |
/** @internalComponent */ \
|
williamr@4
|
83 |
IMPORT_C virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
|
williamr@4
|
84 |
/** @internalComponent */ \
|
williamr@4
|
85 |
IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
|
williamr@4
|
86 |
/** @internalComponent */ \
|
williamr@4
|
87 |
static const Meta::SVDataTableEntry iVDataTable[];
|
williamr@4
|
88 |
|
williamr@4
|
89 |
/**
|
williamr@4
|
90 |
Macros used to implement virtual functions from MMetaData interface and construct the v data table
|
williamr@4
|
91 |
*/
|
williamr@4
|
92 |
#define START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
|
williamr@4
|
93 |
/** @internalComponent */ \
|
williamr@4
|
94 |
Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
|
williamr@4
|
95 |
/** @internalComponent */ \
|
williamr@4
|
96 |
TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
|
williamr@4
|
97 |
/** @internalComponent */ \
|
williamr@4
|
98 |
const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
|
williamr@4
|
99 |
/** @internalComponent */ \
|
williamr@4
|
100 |
const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
|
williamr@4
|
101 |
{ uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
|
williamr@4
|
102 |
|
williamr@4
|
103 |
#define EXPORT_START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
|
williamr@4
|
104 |
/** @internalComponent */ \
|
williamr@4
|
105 |
Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
|
williamr@4
|
106 |
/** @internalComponent */ \
|
williamr@4
|
107 |
TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
|
williamr@4
|
108 |
/** @internalComponent */ \
|
williamr@4
|
109 |
EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
|
williamr@4
|
110 |
/** @internalComponent */ \
|
williamr@4
|
111 |
const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
|
williamr@4
|
112 |
{ uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
|
williamr@4
|
113 |
|
williamr@4
|
114 |
#define EXPORT_START_ATTRIBUTE_TABLE_AND_FN( thisMetaClass, uid, typeId ) \
|
williamr@4
|
115 |
/** @internalComponent */ \
|
williamr@4
|
116 |
EXPORT_C Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
|
williamr@4
|
117 |
/** @internalComponent */ \
|
williamr@4
|
118 |
EXPORT_C TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
|
williamr@4
|
119 |
/** @internalComponent */ \
|
williamr@4
|
120 |
EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
|
williamr@4
|
121 |
/** @internalComponent */ \
|
williamr@4
|
122 |
const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
|
williamr@4
|
123 |
{ uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
|
williamr@4
|
124 |
|
williamr@4
|
125 |
#define REGISTER_ATTRIBUTE( thisMetaClass, var, metaType ) \
|
williamr@4
|
126 |
{ _FOFF( thisMetaClass, var ), Meta::metaType::NewL },
|
williamr@4
|
127 |
|
williamr@4
|
128 |
#define END_ATTRIBUTE_TABLE() \
|
williamr@4
|
129 |
{ 0, NULL }};
|
williamr@4
|
130 |
|
williamr@4
|
131 |
#define END_ATTRIBUTE_TABLE_BASE( baseMetaClass, baseId ) \
|
williamr@4
|
132 |
{ (TInt)((TAny*)(baseMetaClass::GetVDataTableStatic)), NULL }};
|
williamr@4
|
133 |
|
williamr@4
|
134 |
#define REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
|
williamr@4
|
135 |
/** @internalComponent */ \
|
williamr@4
|
136 |
const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
|
williamr@4
|
137 |
/** @internalComponent */ \
|
williamr@4
|
138 |
const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
|
williamr@4
|
139 |
{ uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
|
williamr@4
|
140 |
{ 0, NULL }};
|
williamr@4
|
141 |
|
williamr@4
|
142 |
#define EXPORT_REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
|
williamr@4
|
143 |
/** @internalComponent */ \
|
williamr@4
|
144 |
EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
|
williamr@4
|
145 |
/** @internalComponent */ \
|
williamr@4
|
146 |
const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
|
williamr@4
|
147 |
{ uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
|
williamr@4
|
148 |
{ 0, NULL }};
|
williamr@4
|
149 |
|
williamr@4
|
150 |
#define EXPORT_START_ATTRIBUTE_TABLE_NO_FN( thisMetaClass, uid, typeId ) \
|
williamr@4
|
151 |
/** @internalComponent */ \
|
williamr@4
|
152 |
EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
|
williamr@4
|
153 |
/** @internalComponent */ \
|
williamr@4
|
154 |
const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
|
williamr@4
|
155 |
{ uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
|
williamr@4
|
156 |
|
williamr@4
|
157 |
|
williamr@4
|
158 |
namespace Meta
|
williamr@4
|
159 |
{
|
williamr@4
|
160 |
//Panics
|
williamr@4
|
161 |
_LIT (MetaPanic,"MetaDataPanic");
|
williamr@4
|
162 |
const TInt EBadCast = 1;
|
williamr@4
|
163 |
|
williamr@4
|
164 |
struct SMetaData;
|
williamr@4
|
165 |
typedef Elements::TDeAllocator<const SMetaData> TMetaDataDeAllocator;
|
williamr@4
|
166 |
|
williamr@4
|
167 |
class MMetaType;
|
williamr@4
|
168 |
typedef MMetaType* (*TMetaTypeNewL)(const TAny*, const TAny*);
|
williamr@4
|
169 |
|
williamr@4
|
170 |
struct SVDataTableEntry
|
williamr@4
|
171 |
/**
|
williamr@4
|
172 |
|
williamr@4
|
173 |
Single entry of a virtual data table
|
williamr@4
|
174 |
|
williamr@4
|
175 |
@publishedPartner
|
williamr@4
|
176 |
@released since v9.0 */
|
williamr@4
|
177 |
{
|
williamr@4
|
178 |
TInt iOffset;
|
williamr@4
|
179 |
TMetaTypeNewL iMetaNewL;
|
williamr@4
|
180 |
};
|
williamr@4
|
181 |
|
williamr@4
|
182 |
const TInt32 KNetMetaTypeAny = 0;
|
williamr@4
|
183 |
|
williamr@4
|
184 |
struct STypeId
|
williamr@4
|
185 |
/**
|
williamr@4
|
186 |
|
williamr@4
|
187 |
Used to uniquely identify the type of a (meta).object.
|
williamr@4
|
188 |
|
williamr@4
|
189 |
*/
|
williamr@4
|
190 |
{
|
williamr@4
|
191 |
TUid iUid;
|
williamr@4
|
192 |
TInt32 iType;
|
williamr@4
|
193 |
inline TBool operator==(const STypeId& obj) const { return iUid==obj.iUid && iType==obj.iType; };
|
williamr@4
|
194 |
inline TBool operator!=(const STypeId& obj) const { return iUid!=obj.iUid || iType!=obj.iType; };
|
williamr@4
|
195 |
static inline STypeId CreateSTypeId();
|
williamr@4
|
196 |
static inline STypeId CreateSTypeId(TUint32 aUid, TUint32 aTypeId);
|
williamr@4
|
197 |
IMPORT_C static STypeId CreateSTypeId(TPtrC8& aStore);
|
williamr@4
|
198 |
IMPORT_C TInt Check( TPtrC8& aDes ) const;
|
williamr@4
|
199 |
};
|
williamr@4
|
200 |
|
williamr@4
|
201 |
class MMetaData
|
williamr@4
|
202 |
/**
|
williamr@4
|
203 |
|
williamr@4
|
204 |
MetaData interface
|
williamr@4
|
205 |
|
williamr@4
|
206 |
@publishedPartner
|
williamr@4
|
207 |
@released since v9.0 */
|
williamr@4
|
208 |
{
|
williamr@4
|
209 |
public:
|
williamr@4
|
210 |
virtual SVDataTableEntry const* GetVDataTable() const = 0;
|
williamr@4
|
211 |
virtual TUint8* GetAttribPtr(const TInt aOffset) const = 0;
|
williamr@4
|
212 |
};
|
williamr@4
|
213 |
|
williamr@4
|
214 |
struct SMetaData : public MMetaData
|
williamr@4
|
215 |
/**
|
williamr@4
|
216 |
|
williamr@4
|
217 |
Meta object's base type
|
williamr@4
|
218 |
|
williamr@4
|
219 |
Partially implements the MMetaData interface's pure virtual functions
|
williamr@4
|
220 |
|
williamr@4
|
221 |
*/
|
williamr@4
|
222 |
{
|
williamr@4
|
223 |
public:
|
williamr@4
|
224 |
IMPORT_C virtual ~SMetaData();
|
williamr@4
|
225 |
|
williamr@4
|
226 |
//Checks the exact type for match and advances the pointer if matched
|
williamr@4
|
227 |
IMPORT_C TInt Check( TPtrC8& aDes ) const;
|
williamr@4
|
228 |
//Checks the exact type and base types for match and advances the pointer if matched
|
williamr@4
|
229 |
IMPORT_C TInt CheckTypeOf( TPtrC8& aDes ) const;
|
williamr@4
|
230 |
IMPORT_C STypeId GetTypeId() const;
|
williamr@4
|
231 |
IMPORT_C TInt IsTypeOf( const STypeId& aTypeId ) const;
|
williamr@4
|
232 |
|
williamr@4
|
233 |
IMPORT_C void Copy(const SMetaData& aSource);
|
williamr@4
|
234 |
IMPORT_C TInt Store(TDes8& aDes) const;
|
williamr@4
|
235 |
IMPORT_C TInt Load(TPtrC8& aDes);
|
williamr@4
|
236 |
|
williamr@4
|
237 |
IMPORT_C TInt Length() const;
|
williamr@4
|
238 |
|
williamr@4
|
239 |
protected:
|
williamr@4
|
240 |
IMPORT_C explicit SMetaData();
|
williamr@4
|
241 |
};
|
williamr@4
|
242 |
|
williamr@4
|
243 |
struct SMetaDataECom : public SMetaData
|
williamr@4
|
244 |
/**
|
williamr@4
|
245 |
Meta object based on ECom factory base type
|
williamr@4
|
246 |
Implements static LoadL(TPtrC8& aDes) required by templated
|
williamr@4
|
247 |
*/
|
williamr@4
|
248 |
{
|
williamr@4
|
249 |
public:
|
williamr@4
|
250 |
IMPORT_C static SMetaDataECom* LoadL(TPtrC8& aDes);
|
williamr@4
|
251 |
IMPORT_C static SMetaDataECom* NewInstanceL(const STypeId& aTypeId);
|
williamr@4
|
252 |
IMPORT_C virtual ~SMetaDataECom();
|
williamr@4
|
253 |
|
williamr@4
|
254 |
protected:
|
williamr@4
|
255 |
IMPORT_C explicit SMetaDataECom();
|
williamr@4
|
256 |
|
williamr@4
|
257 |
private:
|
williamr@4
|
258 |
TUid iDestroyUid;
|
williamr@4
|
259 |
};
|
williamr@4
|
260 |
|
williamr@4
|
261 |
} //namespace Meta
|
williamr@4
|
262 |
|
williamr@4
|
263 |
|
williamr@4
|
264 |
template <class SMETADATATYPE>
|
williamr@4
|
265 |
SMETADATATYPE& smetadata_cast(Meta::SMetaData& aObject)
|
williamr@4
|
266 |
{
|
williamr@4
|
267 |
__ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
|
williamr@4
|
268 |
return static_cast<SMETADATATYPE&>(aObject);
|
williamr@4
|
269 |
}
|
williamr@4
|
270 |
|
williamr@4
|
271 |
template <class SMETADATATYPE>
|
williamr@4
|
272 |
const SMETADATATYPE& smetadata_cast(const Meta::SMetaData& aObject)
|
williamr@4
|
273 |
{
|
williamr@4
|
274 |
__ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
|
williamr@4
|
275 |
return static_cast<const SMETADATATYPE&>(aObject);
|
williamr@4
|
276 |
}
|
williamr@4
|
277 |
|
williamr@4
|
278 |
template <class SMETADATATYPE>
|
williamr@4
|
279 |
SMETADATATYPE* smetadata_cast(Meta::SMetaData* aObject)
|
williamr@4
|
280 |
{
|
williamr@4
|
281 |
__ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
|
williamr@4
|
282 |
return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<SMETADATATYPE*>(aObject) : NULL;
|
williamr@4
|
283 |
}
|
williamr@4
|
284 |
|
williamr@4
|
285 |
template <class SMETADATATYPE>
|
williamr@4
|
286 |
const SMETADATATYPE* smetadata_cast(const Meta::SMetaData* aObject)
|
williamr@4
|
287 |
{
|
williamr@4
|
288 |
__ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
|
williamr@4
|
289 |
return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<const SMETADATATYPE*>(aObject) : NULL;
|
williamr@4
|
290 |
}
|
williamr@4
|
291 |
|
williamr@4
|
292 |
#include <elements/metadata.inl>
|
williamr@4
|
293 |
|
williamr@4
|
294 |
#endif //METADATA_H
|
williamr@4
|
295 |
|
williamr@4
|
296 |
|