1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // MetaTypeVariableLen.h
21 @file MetaTypeVariableLen.h
25 #if (!defined METATYPEVARIABLELEN_H)
26 #define METATYPEVARIABLELEN_H
28 #include <comms-infras/metatype.h>
33 template<class TYPE> class TMetaVarLen8;
34 template<class TYPE> class TMetaVarLen16;
35 typedef TMetaVarLen8<TDes8> TMetaDes8;
36 typedef TMetaVarLen16<TDes16> TMetaDes16;
39 typedef TMetaDes16 TMetaDes;
41 typedef TMetaDes8 TMetaDes;
44 class TMetaVarLenBase : public MMetaType
47 IMPORT_C virtual TInt Load(TPtrC8& aBuffer);
48 IMPORT_C virtual TInt Store(TDes8& aBuffer) const;
51 TInt CheckBuf( TPtrC8& aBuffer );
52 virtual void CopyBuf(TPtrC8& aBuffer,TInt aLen) = 0;
53 virtual void AppendToBuf( TDes8& aBuffer ) const = 0;
57 class TMetaVarLen : public TMetaVarLenBase
60 Implementation of MMetaType for anything that provides Length(), SetLength(), MaxLength(),
61 Copy() and Left() functions with arbitrarry element size
64 @released since v9.0 */
67 virtual void Copy(const TAny* aData);
70 TMetaVarLen(const TAny* aData);
77 inline TMetaVarLen<TYPE>::TMetaVarLen(const TAny* aData)
83 __ASSERT_DEBUG(iData!=NULL,User::Panic(_L("TMetaVarLen"),KErrArgument));
87 void TMetaVarLen<TYPE>::Copy(const TAny* aData)
89 * Copies content of the member
92 const TYPE& var = *((TYPE*)aData);
93 iData->Copy(var.Left( iData->MaxLength() ));
97 class TMetaVarLen8 : public TMetaVarLen<TYPE>
100 Implementation of MMetaType for anything that provides Length(), SetLength(), MaxLength(),
101 Copy() and Left() functions with element size 1 byte
102 Like for example TDes8, TBuf8, TPtr8.
105 @released since v9.0 */
108 inline static MMetaType* NewL(const TAny* aMem, const TAny* aData);
110 virtual TInt Length() const;
113 TMetaVarLen8(const TAny* aData);
114 virtual void AppendToBuf( TDes8& aBuffer ) const;
115 virtual void CopyBuf(TPtrC8& aBuffer,TInt aLen);
120 class TMetaVarLen16 : public TMetaVarLen<TYPE>
123 Implementation of MMetaType for anything that provides Length(), SetLength(), MaxLength(),
124 Copy() and Left() functions with element size 2 bytes
125 Like for example TDes16, TBuf16, TPtr16 (ELEMENT is short).
128 @released since v9.0 */
131 inline static MMetaType* NewL(const TAny* aMem, const TAny* aData);
133 virtual TInt Length() const;
136 TMetaVarLen16(const TAny* aData);
137 virtual void AppendToBuf( TDes8& aBuffer ) const;
138 virtual void CopyBuf(TPtrC8& aBuffer,TInt aLen);
144 inline TMetaVarLen16<TYPE>::TMetaVarLen16(const TAny* aData)
145 : TMetaVarLen<TYPE>(aData)
153 MMetaType* TMetaVarLen16<TYPE>::NewL(const TAny* aMem, const TAny* aData)
155 * Instantiates a meta type of a particular type.
156 * Used for attribure registration (in the data v-table).
159 return ::new ((TUint8*)aMem) TMetaVarLen16<TYPE>(aData);
163 void TMetaVarLen16<TYPE>::AppendToBuf( TDes8& aBuffer ) const
165 //copy whatever fits in (no loosing high byte as the ::Copy normally would)
166 //a litle bit dirty solution assuming a flat memory model and byte addressing mode
167 aBuffer.Append(reinterpret_cast<const TUint8*>(this->iData->Ptr()), this->iData->Length() * 2);
171 void TMetaVarLen16<TYPE>::CopyBuf(TPtrC8& aBuffer,TInt aLen)
173 //copy whatever fits in
174 //a litle bit dirty solution assuming a flat memory model and byte addressing mode
175 this->iData->Copy( reinterpret_cast<const TUint16*>(aBuffer.Ptr()), Min( this->iData->MaxLength(), aLen / 2 ));
179 TInt TMetaVarLen16<TYPE>::Length() const
181 * Returns the length of the data member
184 return this->iData->Length() * 2 + sizeof(TUint32);
188 inline TMetaVarLen8<TYPE>::TMetaVarLen8(const TAny* aData)
189 : TMetaVarLen<TYPE>(aData)
197 MMetaType* TMetaVarLen8<TYPE>::NewL(const TAny* aMem, const TAny* aData)
199 * Instantiates a meta type of a particular type.
200 * Used for attribure registration (in the data v-table).
203 return ::new ((TUint8*)aMem) TMetaVarLen8<TYPE>(aData);
207 #ifdef SYMBIAN_NETWORKING_CFTRANSPORT
208 void TMetaVarLen8<TYPE>::CopyBuf(TPtrC8& aBuffer,TInt aLen)
210 //copy whatever fits in
211 this->iData->Copy( aBuffer.Left( Min(this->iData->MaxLength(), aLen) ) );
214 void TMetaVarLen8<TYPE>::CopyBuf(TPtrC8& aBuffer,TInt /*aLen*/)
216 this->iData->Copy( aBuffer.Left( this->iData->MaxLength() ) );
221 void TMetaVarLen8<TYPE>::AppendToBuf( TDes8& aBuffer ) const
223 aBuffer.Append(*this->iData);
227 TInt TMetaVarLen8<TYPE>::Length() const
229 * Returns the length of the data member
232 return this->iData->Length() + sizeof(TUint32);