1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/comms-infras/metatypevariablelen.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,238 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// 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
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// MetaTypeVariableLen.h
1.18 +//
1.19 +//
1.20 +
1.21 +
1.22 +
1.23 +/**
1.24 + @file MetaTypeVariableLen.h
1.25 + @internalTechnology
1.26 +*/
1.27 +
1.28 +#if (!defined METATYPEVARIABLELEN_H)
1.29 +#define METATYPEVARIABLELEN_H
1.30 +
1.31 +#include <comms-infras/metatype.h>
1.32 +
1.33 +namespace Meta
1.34 +{
1.35 +
1.36 +template<class TYPE> class TMetaVarLen8;
1.37 +template<class TYPE> class TMetaVarLen16;
1.38 +typedef TMetaVarLen8<TDes8> TMetaDes8;
1.39 +typedef TMetaVarLen16<TDes16> TMetaDes16;
1.40 +
1.41 +#if defined(_UNICODE)
1.42 +typedef TMetaDes16 TMetaDes;
1.43 +#else
1.44 +typedef TMetaDes8 TMetaDes;
1.45 +#endif
1.46 +
1.47 +class TMetaVarLenBase : public MMetaType
1.48 + {
1.49 + public:
1.50 + IMPORT_C virtual TInt Load(TPtrC8& aBuffer);
1.51 + IMPORT_C virtual TInt Store(TDes8& aBuffer) const;
1.52 +
1.53 + protected:
1.54 + TInt CheckBuf( TPtrC8& aBuffer );
1.55 + virtual void CopyBuf(TPtrC8& aBuffer,TInt aLen) = 0;
1.56 + virtual void AppendToBuf( TDes8& aBuffer ) const = 0;
1.57 + };
1.58 +
1.59 +template<class TYPE>
1.60 +class TMetaVarLen : public TMetaVarLenBase
1.61 +/**
1.62 +
1.63 +Implementation of MMetaType for anything that provides Length(), SetLength(), MaxLength(),
1.64 +Copy() and Left() functions with arbitrarry element size
1.65 +
1.66 +@internalComponent
1.67 +@released since v9.0 */
1.68 + {
1.69 +public:
1.70 + virtual void Copy(const TAny* aData);
1.71 +
1.72 +protected:
1.73 + TMetaVarLen(const TAny* aData);
1.74 +
1.75 +protected:
1.76 + TYPE* iData;
1.77 + };
1.78 +
1.79 +template<class TYPE>
1.80 +inline TMetaVarLen<TYPE>::TMetaVarLen(const TAny* aData)
1.81 +: iData((TYPE*)aData)
1.82 +/**
1.83 + * Constructor
1.84 + */
1.85 + {
1.86 + __ASSERT_DEBUG(iData!=NULL,User::Panic(_L("TMetaVarLen"),KErrArgument));
1.87 + }
1.88 +
1.89 +template<class TYPE>
1.90 +void TMetaVarLen<TYPE>::Copy(const TAny* aData)
1.91 +/**
1.92 + * Copies content of the member
1.93 + */
1.94 + {
1.95 + const TYPE& var = *((TYPE*)aData);
1.96 + iData->Copy(var.Left( iData->MaxLength() ));
1.97 + }
1.98 +
1.99 +template<class TYPE>
1.100 +class TMetaVarLen8 : public TMetaVarLen<TYPE>
1.101 +/**
1.102 +
1.103 +Implementation of MMetaType for anything that provides Length(), SetLength(), MaxLength(),
1.104 +Copy() and Left() functions with element size 1 byte
1.105 +Like for example TDes8, TBuf8, TPtr8.
1.106 +
1.107 +@internalComponent
1.108 +@released since v9.0 */
1.109 + {
1.110 +public:
1.111 + inline static MMetaType* NewL(const TAny* aMem, const TAny* aData);
1.112 +
1.113 + virtual TInt Length() const;
1.114 +
1.115 +protected:
1.116 + TMetaVarLen8(const TAny* aData);
1.117 + virtual void AppendToBuf( TDes8& aBuffer ) const;
1.118 + virtual void CopyBuf(TPtrC8& aBuffer,TInt aLen);
1.119 +
1.120 + };
1.121 +
1.122 +template<class TYPE>
1.123 +class TMetaVarLen16 : public TMetaVarLen<TYPE>
1.124 +/**
1.125 +
1.126 +Implementation of MMetaType for anything that provides Length(), SetLength(), MaxLength(),
1.127 +Copy() and Left() functions with element size 2 bytes
1.128 +Like for example TDes16, TBuf16, TPtr16 (ELEMENT is short).
1.129 +
1.130 +@internalComponent
1.131 +@released since v9.0 */
1.132 + {
1.133 +public:
1.134 + inline static MMetaType* NewL(const TAny* aMem, const TAny* aData);
1.135 +
1.136 + virtual TInt Length() const;
1.137 +
1.138 +protected:
1.139 + TMetaVarLen16(const TAny* aData);
1.140 + virtual void AppendToBuf( TDes8& aBuffer ) const;
1.141 + virtual void CopyBuf(TPtrC8& aBuffer,TInt aLen);
1.142 +
1.143 + };
1.144 +
1.145 +
1.146 +template<class TYPE>
1.147 +inline TMetaVarLen16<TYPE>::TMetaVarLen16(const TAny* aData)
1.148 +: TMetaVarLen<TYPE>(aData)
1.149 +/**
1.150 + * Constructor
1.151 + */
1.152 + {
1.153 + }
1.154 +
1.155 +template<class TYPE>
1.156 +MMetaType* TMetaVarLen16<TYPE>::NewL(const TAny* aMem, const TAny* aData)
1.157 +/**
1.158 + * Instantiates a meta type of a particular type.
1.159 + * Used for attribure registration (in the data v-table).
1.160 + */
1.161 + {
1.162 + return ::new ((TUint8*)aMem) TMetaVarLen16<TYPE>(aData);
1.163 + }
1.164 +
1.165 +template<class TYPE>
1.166 +void TMetaVarLen16<TYPE>::AppendToBuf( TDes8& aBuffer ) const
1.167 + {
1.168 + //copy whatever fits in (no loosing high byte as the ::Copy normally would)
1.169 + //a litle bit dirty solution assuming a flat memory model and byte addressing mode
1.170 + aBuffer.Append(reinterpret_cast<const TUint8*>(this->iData->Ptr()), this->iData->Length() * 2);
1.171 + }
1.172 +
1.173 +template<class TYPE>
1.174 +void TMetaVarLen16<TYPE>::CopyBuf(TPtrC8& aBuffer,TInt aLen)
1.175 + {
1.176 + //copy whatever fits in
1.177 + //a litle bit dirty solution assuming a flat memory model and byte addressing mode
1.178 + this->iData->Copy( reinterpret_cast<const TUint16*>(aBuffer.Ptr()), Min( this->iData->MaxLength(), aLen / 2 ));
1.179 + }
1.180 +
1.181 +template<class TYPE>
1.182 +TInt TMetaVarLen16<TYPE>::Length() const
1.183 +/**
1.184 + * Returns the length of the data member
1.185 + */
1.186 + {
1.187 + return this->iData->Length() * 2 + sizeof(TUint32);
1.188 + }
1.189 +
1.190 +template<class TYPE>
1.191 +inline TMetaVarLen8<TYPE>::TMetaVarLen8(const TAny* aData)
1.192 +: TMetaVarLen<TYPE>(aData)
1.193 +/**
1.194 + * Constructor
1.195 + */
1.196 + {
1.197 + }
1.198 +
1.199 +template<class TYPE>
1.200 +MMetaType* TMetaVarLen8<TYPE>::NewL(const TAny* aMem, const TAny* aData)
1.201 +/**
1.202 + * Instantiates a meta type of a particular type.
1.203 + * Used for attribure registration (in the data v-table).
1.204 + */
1.205 + {
1.206 + return ::new ((TUint8*)aMem) TMetaVarLen8<TYPE>(aData);
1.207 + }
1.208 +
1.209 +template<class TYPE>
1.210 +#ifdef SYMBIAN_NETWORKING_CFTRANSPORT
1.211 +void TMetaVarLen8<TYPE>::CopyBuf(TPtrC8& aBuffer,TInt aLen)
1.212 + {
1.213 + //copy whatever fits in
1.214 + this->iData->Copy( aBuffer.Left( Min(this->iData->MaxLength(), aLen) ) );
1.215 + }
1.216 +#else
1.217 +void TMetaVarLen8<TYPE>::CopyBuf(TPtrC8& aBuffer,TInt /*aLen*/)
1.218 + {
1.219 + this->iData->Copy( aBuffer.Left( this->iData->MaxLength() ) );
1.220 + }
1.221 +#endif
1.222 +
1.223 +template<class TYPE>
1.224 +void TMetaVarLen8<TYPE>::AppendToBuf( TDes8& aBuffer ) const
1.225 + {
1.226 + aBuffer.Append(*this->iData);
1.227 + }
1.228 +
1.229 +template<class TYPE>
1.230 +TInt TMetaVarLen8<TYPE>::Length() const
1.231 +/**
1.232 + * Returns the length of the data member
1.233 + */
1.234 + {
1.235 + return this->iData->Length() + sizeof(TUint32);
1.236 + }
1.237 +
1.238 +} //namespace Meta
1.239 +
1.240 +
1.241 +#endif //METATYPE_H