1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/elements/metadata.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,296 @@
1.4 +/**
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @publishedPartner
1.26 + @released
1.27 +*/
1.28 +
1.29 +#if (!defined METADATA_H)
1.30 +#define METADATA_H
1.31 +
1.32 +#include <e32base.h>
1.33 +#include <e32std.h>
1.34 +#include <elements/cftransportmacro.h>
1.35 +#include <elements/h_tdeallocator.h>
1.36 +
1.37 +/**
1.38 +Macro used to declare virtual functions from MMetaData interface and the virtual data table
1.39 +*/
1.40 +#define TYPEID_TABLE \
1.41 + /** @internalComponent */ \
1.42 + static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
1.43 + /** @internalComponent */ \
1.44 + static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
1.45 + /** @internalComponent */ \
1.46 + static const Meta::SVDataTableEntry iVDataTable[];
1.47 +
1.48 +#define EXPORT_TYPEID_TABLE \
1.49 + /** @internalComponent */ \
1.50 + static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
1.51 + /** @internalComponent */ \
1.52 + IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
1.53 + /** @internalComponent */ \
1.54 + static const Meta::SVDataTableEntry iVDataTable[];
1.55 +
1.56 +#define DATA_VTABLE \
1.57 + /** @internalComponent */ \
1.58 + static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
1.59 + /** @internalComponent */ \
1.60 + virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
1.61 + /** @internalComponent */ \
1.62 + virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
1.63 + /** @internalComponent */ \
1.64 + static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
1.65 + /** @internalComponent */ \
1.66 + static const Meta::SVDataTableEntry iVDataTable[];
1.67 +
1.68 +#define EXPORT_DATA_VTABLE \
1.69 + /** @internalComponent */ \
1.70 + static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
1.71 + /** @internalComponent */ \
1.72 + virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
1.73 + /** @internalComponent */ \
1.74 + virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
1.75 + /** @internalComponent */ \
1.76 + IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
1.77 + /** @internalComponent */ \
1.78 + static const Meta::SVDataTableEntry iVDataTable[];
1.79 +
1.80 +#define EXPORT_DATA_VTABLE_AND_FN \
1.81 + /** @internalComponent */ \
1.82 + static inline const Meta::STypeId TypeId() { const Meta::SVDataTableEntry* entry = GetVDataTableStatic(); return Meta::STypeId::CreateSTypeId(entry->iOffset,reinterpret_cast<TInt32>(entry->iMetaNewL)); } \
1.83 + /** @internalComponent */ \
1.84 + IMPORT_C virtual Meta::SVDataTableEntry const* GetVDataTable() const; \
1.85 + /** @internalComponent */ \
1.86 + IMPORT_C virtual TUint8* GetAttribPtr(const TInt aOffset) const; \
1.87 + /** @internalComponent */ \
1.88 + IMPORT_C static const Meta::SVDataTableEntry* GetVDataTableStatic(); \
1.89 + /** @internalComponent */ \
1.90 + static const Meta::SVDataTableEntry iVDataTable[];
1.91 +
1.92 +/**
1.93 +Macros used to implement virtual functions from MMetaData interface and construct the v data table
1.94 +*/
1.95 +#define START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
1.96 + /** @internalComponent */ \
1.97 + Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
1.98 + /** @internalComponent */ \
1.99 + TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
1.100 + /** @internalComponent */ \
1.101 + const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
1.102 + /** @internalComponent */ \
1.103 + const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
1.104 + { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
1.105 +
1.106 +#define EXPORT_START_ATTRIBUTE_TABLE( thisMetaClass, uid, typeId ) \
1.107 + /** @internalComponent */ \
1.108 + Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
1.109 + /** @internalComponent */ \
1.110 + TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
1.111 + /** @internalComponent */ \
1.112 + EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
1.113 + /** @internalComponent */ \
1.114 + const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
1.115 + { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
1.116 +
1.117 +#define EXPORT_START_ATTRIBUTE_TABLE_AND_FN( thisMetaClass, uid, typeId ) \
1.118 + /** @internalComponent */ \
1.119 + EXPORT_C Meta::SVDataTableEntry const* thisMetaClass::GetVDataTable() const { return &iVDataTable[0]; }; \
1.120 + /** @internalComponent */ \
1.121 + EXPORT_C TUint8* thisMetaClass::GetAttribPtr(const TInt aOffset) const { return (TUint8*)this + aOffset; }; \
1.122 + /** @internalComponent */ \
1.123 + EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
1.124 + /** @internalComponent */ \
1.125 + const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
1.126 + { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
1.127 +
1.128 +#define REGISTER_ATTRIBUTE( thisMetaClass, var, metaType ) \
1.129 + { _FOFF( thisMetaClass, var ), Meta::metaType::NewL },
1.130 +
1.131 +#define END_ATTRIBUTE_TABLE() \
1.132 + { 0, NULL }};
1.133 +
1.134 +#define END_ATTRIBUTE_TABLE_BASE( baseMetaClass, baseId ) \
1.135 + { (TInt)((TAny*)(baseMetaClass::GetVDataTableStatic)), NULL }};
1.136 +
1.137 +#define REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
1.138 + /** @internalComponent */ \
1.139 + const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
1.140 + /** @internalComponent */ \
1.141 + const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
1.142 + { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
1.143 + { 0, NULL }};
1.144 +
1.145 +#define EXPORT_REGISTER_TYPEID( thisMetaClass, uid, typeId ) \
1.146 + /** @internalComponent */ \
1.147 + EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
1.148 + /** @internalComponent */ \
1.149 + const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
1.150 + { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) }, \
1.151 + { 0, NULL }};
1.152 +
1.153 +#define EXPORT_START_ATTRIBUTE_TABLE_NO_FN( thisMetaClass, uid, typeId ) \
1.154 + /** @internalComponent */ \
1.155 + EXPORT_C const Meta::SVDataTableEntry* thisMetaClass::GetVDataTableStatic() { return &iVDataTable[0]; }; \
1.156 + /** @internalComponent */ \
1.157 + const Meta::SVDataTableEntry thisMetaClass::iVDataTable[] = { \
1.158 + { uid, reinterpret_cast<Meta::TMetaTypeNewL>(typeId) },
1.159 +
1.160 +
1.161 +namespace Meta
1.162 +{
1.163 +//Panics
1.164 +_LIT (MetaPanic,"MetaDataPanic");
1.165 +const TInt EBadCast = 1;
1.166 +
1.167 +struct SMetaData;
1.168 +typedef Elements::TDeAllocator<const SMetaData> TMetaDataDeAllocator;
1.169 +
1.170 +class MMetaType;
1.171 +typedef MMetaType* (*TMetaTypeNewL)(const TAny*, const TAny*);
1.172 +
1.173 +struct SVDataTableEntry
1.174 +/**
1.175 +
1.176 +Single entry of a virtual data table
1.177 +
1.178 +@publishedPartner
1.179 +@released since v9.0 */
1.180 + {
1.181 + TInt iOffset;
1.182 + TMetaTypeNewL iMetaNewL;
1.183 + };
1.184 +
1.185 +const TInt32 KNetMetaTypeAny = 0;
1.186 +
1.187 +struct STypeId
1.188 +/**
1.189 +
1.190 +Used to uniquely identify the type of a (meta).object.
1.191 +
1.192 +*/
1.193 + {
1.194 + TUid iUid;
1.195 + TInt32 iType;
1.196 + inline TBool operator==(const STypeId& obj) const { return iUid==obj.iUid && iType==obj.iType; };
1.197 + inline TBool operator!=(const STypeId& obj) const { return iUid!=obj.iUid || iType!=obj.iType; };
1.198 + static inline STypeId CreateSTypeId();
1.199 + static inline STypeId CreateSTypeId(TUint32 aUid, TUint32 aTypeId);
1.200 + IMPORT_C static STypeId CreateSTypeId(TPtrC8& aStore);
1.201 + IMPORT_C TInt Check( TPtrC8& aDes ) const;
1.202 + };
1.203 +
1.204 +class MMetaData
1.205 +/**
1.206 +
1.207 +MetaData interface
1.208 +
1.209 +@publishedPartner
1.210 +@released since v9.0 */
1.211 + {
1.212 +public:
1.213 + virtual SVDataTableEntry const* GetVDataTable() const = 0;
1.214 + virtual TUint8* GetAttribPtr(const TInt aOffset) const = 0;
1.215 + };
1.216 +
1.217 +struct SMetaData : public MMetaData
1.218 +/**
1.219 +
1.220 +Meta object's base type
1.221 +
1.222 +Partially implements the MMetaData interface's pure virtual functions
1.223 +
1.224 +*/
1.225 + {
1.226 +public:
1.227 + IMPORT_C virtual ~SMetaData();
1.228 +
1.229 + //Checks the exact type for match and advances the pointer if matched
1.230 + IMPORT_C TInt Check( TPtrC8& aDes ) const;
1.231 + //Checks the exact type and base types for match and advances the pointer if matched
1.232 + IMPORT_C TInt CheckTypeOf( TPtrC8& aDes ) const;
1.233 + IMPORT_C STypeId GetTypeId() const;
1.234 + IMPORT_C TInt IsTypeOf( const STypeId& aTypeId ) const;
1.235 +
1.236 + IMPORT_C void Copy(const SMetaData& aSource);
1.237 + IMPORT_C TInt Store(TDes8& aDes) const;
1.238 + IMPORT_C TInt Load(TPtrC8& aDes);
1.239 +
1.240 + IMPORT_C TInt Length() const;
1.241 +
1.242 +protected:
1.243 + IMPORT_C explicit SMetaData();
1.244 + };
1.245 +
1.246 +struct SMetaDataECom : public SMetaData
1.247 +/**
1.248 +Meta object based on ECom factory base type
1.249 +Implements static LoadL(TPtrC8& aDes) required by templated
1.250 +*/
1.251 + {
1.252 +public:
1.253 + IMPORT_C static SMetaDataECom* LoadL(TPtrC8& aDes);
1.254 + IMPORT_C static SMetaDataECom* NewInstanceL(const STypeId& aTypeId);
1.255 + IMPORT_C virtual ~SMetaDataECom();
1.256 +
1.257 +protected:
1.258 + IMPORT_C explicit SMetaDataECom();
1.259 +
1.260 +private:
1.261 + TUid iDestroyUid;
1.262 + };
1.263 +
1.264 +} //namespace Meta
1.265 +
1.266 +
1.267 +template <class SMETADATATYPE>
1.268 +SMETADATATYPE& smetadata_cast(Meta::SMetaData& aObject)
1.269 + {
1.270 + __ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
1.271 + return static_cast<SMETADATATYPE&>(aObject);
1.272 + }
1.273 +
1.274 +template <class SMETADATATYPE>
1.275 +const SMETADATATYPE& smetadata_cast(const Meta::SMetaData& aObject)
1.276 + {
1.277 + __ASSERT_DEBUG(aObject.IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)),User::Panic(Meta::MetaPanic, Meta::EBadCast));
1.278 + return static_cast<const SMETADATATYPE&>(aObject);
1.279 + }
1.280 +
1.281 +template <class SMETADATATYPE>
1.282 +SMETADATATYPE* smetadata_cast(Meta::SMetaData* aObject)
1.283 + {
1.284 + __ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
1.285 + return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<SMETADATATYPE*>(aObject) : NULL;
1.286 + }
1.287 +
1.288 +template <class SMETADATATYPE>
1.289 +const SMETADATATYPE* smetadata_cast(const Meta::SMetaData* aObject)
1.290 + {
1.291 + __ASSERT_DEBUG(aObject,User::Panic(Meta::MetaPanic, Meta::EBadCast));
1.292 + return aObject->IsTypeOf(Meta::STypeId::CreateSTypeId(SMETADATATYPE::EUid, SMETADATATYPE::ETypeId)) ? static_cast<const SMETADATATYPE*>(aObject) : NULL;
1.293 + }
1.294 +
1.295 +#include <elements/metadata.inl>
1.296 +
1.297 +#endif //METADATA_H
1.298 +
1.299 +