2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
26 #if (!defined METADATA_H)
31 #include <elements/cftransportmacro.h>
32 #include <elements/h_tdeallocator.h>
35 Macro used to declare virtual functions from MMetaData interface and the virtual data table
37 #define TYPEID_TABLE \
38 /** @internalComponent */ \
39 static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
40 /** @internalComponent */ \
41 static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
42 /** @internalComponent */ \
43 static const Meta::SVDataTableEntry iVDataTable[];
45 #define EXPORT_TYPEID_TABLE \
46 /** @internalComponent */ \
47 static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
48 /** @internalComponent */ \
49 IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
50 /** @internalComponent */ \
51 static const Meta::SVDataTableEntry iVDataTable[];
54 /** @internalComponent */ \
55 static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
56 /** @internalComponent */ \
57 virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
58 /** @internalComponent */ \
59 virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
60 /** @internalComponent */ \
61 static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
62 /** @internalComponent */ \
63 static const Meta::SVDataTableEntry iVDataTable[];
65 #define EXPORT_DATA_VTABLE \
66 /** @internalComponent */ \
67 static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
68 /** @internalComponent */ \
69 virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
70 /** @internalComponent */ \
71 virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
72 /** @internalComponent */ \
73 IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
74 /** @internalComponent */ \
75 static const Meta::SVDataTableEntry iVDataTable[];
77 #define EXPORT_DATA_VTABLE_AND_FN \
78 /** @internalComponent */ \
79 static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
80 /** @internalComponent */ \
81 IMPORT_C virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
82 /** @internalComponent */ \
83 IMPORT_C virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
84 /** @internalComponent */ \
85 IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
86 /** @internalComponent */ \
87 static const Meta::SVDataTableEntry iVDataTable[];
90 Macros used to implement virtual functions from MMetaData interface and construct the v data table
92 #define START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
93 /** @internalComponent */ \
94 Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
95 /** @internalComponent */ \
96 TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
97 /** @internalComponent */ \
98 const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
99 /** @internalComponent */ \
100 const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
101 { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
103 #define EXPORT_START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
104 /** @internalComponent */ \
105 Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
106 /** @internalComponent */ \
107 TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
108 /** @internalComponent */ \
109 EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
110 /** @internalComponent */ \
111 const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
112 { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
114 #define EXPORT_START_ATTRIBUTE_TABLE_AND_FN( thisMetaClass, uid, typeId ) \
115 /** @internalComponent */ \
116 EXPORT_C Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
117 /** @internalComponent */ \
118 EXPORT_C TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
119 /** @internalComponent */ \
120 EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
121 /** @internalComponent */ \
122 const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
123 { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
125 #define REGISTER_ATTRIBUTE( thisMetaClass, var, metaType ) \
126 { _FOFF( thisMetaClass, var ), Meta::metaType::NewL },
128 #define END_ATTRIBUTE_TABLE() \
131 #define END_ATTRIBUTE_TABLE_BASE( baseMetaClass, baseId ) \
132 { (TInt)((TAny*)(baseMetaClass::GetVDataTableStatic)), NULL }};
134 #define REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
135 /** @internalComponent */ \
136 const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
137 /** @internalComponent */ \
138 const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
139 { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
142 #define EXPORT_REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
143 /** @internalComponent */ \
144 EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
145 /** @internalComponent */ \
146 const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
147 { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
150 #define EXPORT_START_ATTRIBUTE_TABLE_NO_FN( thisMetaClass, uid, typeId ) \
151 /** @internalComponent */ \
152 EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
153 /** @internalComponent */ \
154 const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
155 { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
161 _LIT (MetaPanic,"MetaDataPanic");
162 const TInt EBadCast = 1;
165 typedef Elements::TDeAllocator<const SMetaData> TMetaDataDeAllocator;
168 typedef MMetaType* (*TMetaTypeNewL)(const TAny*, const TAny*);
170 struct SVDataTableEntry
173 Single entry of a virtual data table
176 @released since v9.0 */
179 TMetaTypeNewL iMetaNewL;
182 const TInt32 KNetMetaTypeAny = 0;
187 Used to uniquely identify the type of a (meta).object.
193 inline TBool operator==(const STypeId& obj) const { return iUid==obj.iUid && iType==obj.iType; };
194 inline TBool operator!=(const STypeId& obj) const { return iUid!=obj.iUid || iType!=obj.iType; };
195 static inline STypeId CreateSTypeId();
196 static inline STypeId CreateSTypeId(TUint32 aUid, TUint32 aTypeId);
197 IMPORT_C static STypeId CreateSTypeId(TPtrC8& aStore);
198 IMPORT_C TInt Check( TPtrC8& aDes ) const;
207 @released since v9.0 */
210 virtual SVDataTableEntry const* GetVDataTable() const = 0;
211 virtual TUint8* GetAttribPtr(const TInt aOffset) const = 0;
214 struct SMetaData : public MMetaData
217 Meta object's base type
219 Partially implements the MMetaData interface's pure virtual functions
224 IMPORT_C virtual ~SMetaData();
226 //Checks the exact type for match and advances the pointer if matched
227 IMPORT_C TInt Check( TPtrC8& aDes ) const;
228 //Checks the exact type and base types for match and advances the pointer if matched
229 IMPORT_C TInt CheckTypeOf( TPtrC8& aDes ) const;
230 IMPORT_C STypeId GetTypeId() const;
231 IMPORT_C TInt IsTypeOf( const STypeId& aTypeId ) const;
233 IMPORT_C void Copy(const SMetaData& aSource);
234 IMPORT_C TInt Store(TDes8& aDes) const;
235 IMPORT_C TInt Load(TPtrC8& aDes);
237 IMPORT_C TInt Length() const;
240 IMPORT_C explicit SMetaData();
243 struct SMetaDataECom : public SMetaData
245 Meta object based on ECom factory base type
246 Implements static LoadL(TPtrC8& aDes) required by templated
250 IMPORT_C static SMetaDataECom* LoadL(TPtrC8& aDes);
251 IMPORT_C static SMetaDataECom* NewInstanceL(const STypeId& aTypeId);
252 IMPORT_C virtual ~SMetaDataECom();
255 IMPORT_C explicit SMetaDataECom();
264 template <class SMETADATATYPE>
265 SMETADATATYPE& smetadata_cast(Meta::SMetaData& aObject)
267 __ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
268 return static_cast<SMETADATATYPE&>(aObject);
271 template <class SMETADATATYPE>
272 const SMETADATATYPE& smetadata_cast(const Meta::SMetaData& aObject)
274 __ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
275 return static_cast<const SMETADATATYPE&>(aObject);
278 template <class SMETADATATYPE>
279 SMETADATATYPE* smetadata_cast(Meta::SMetaData* aObject)
281 __ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
282 return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<SMETADATATYPE*>(aObject) : NULL;
285 template <class SMETADATATYPE>
286 const SMETADATATYPE* smetadata_cast(const Meta::SMetaData* aObject)
288 __ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
289 return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<const SMETADATATYPE*>(aObject) : NULL;
292 #include <elements/metadata.inl>