os/ossrv/genericservices/mimerecognitionfw/apmime/APMSTD.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/mimerecognitionfw/apmime/APMSTD.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,233 @@
     1.4 +// Copyright (c) 1997-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 "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.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 +//
    1.18 +
    1.19 +#include <s32strm.h>
    1.20 +
    1.21 +#include "APMSTD.H"
    1.22 +#include "APMPAN.H"
    1.23 +
    1.24 +//
    1.25 +// class TDataType
    1.26 +//
    1.27 +
    1.28 +EXPORT_C TDataType::TDataType()
    1.29 +	:iDataType(),
    1.30 +	iUid(KNullUid)
    1.31 +/** Default constructor.
    1.32 +
    1.33 +Sets an empty data type string and sets the associated UID to KNullUid. */
    1.34 +	{}
    1.35 +
    1.36 +EXPORT_C TDataType::TDataType(const TDataType& aDataType)
    1.37 +	:iDataType(aDataType.iDataType),
    1.38 +	iUid(aDataType.iUid)
    1.39 +/** Copy constructor.
    1.40 +
    1.41 +@param aDataType The data type to be copied. */
    1.42 +	{}
    1.43 +
    1.44 +EXPORT_C TDataType::TDataType(const TDesC8& aDataType)
    1.45 +	:iDataType(aDataType),
    1.46 +	iUid(KNullUid)
    1.47 +/** Constructor taking a descriptor.
    1.48 +
    1.49 +The data type string is copied from the specified descriptor. By default, 
    1.50 +the associated UID is set to KNullUid.
    1.51 +
    1.52 +If the data type string begins with the characters "x-epoc/x-app", identifying 
    1.53 +data as a native Symbian type, then the associated UID is set to the UID value 
    1.54 +which is expected to follow the characters "x-epoc/x-app".
    1.55 +
    1.56 +If no sensible UID can be extracted from the characters following: "x-epoc/x-app", 
    1.57 +then the associated UID is set to KNullUid.
    1.58 +
    1.59 +@param aDataType The source for the data type string. Note that this is an 
    1.60 +8 bit descriptor. */
    1.61 +	{
    1.62 +	ParseDes();
    1.63 +	}
    1.64 +
    1.65 +EXPORT_C TDataType::TDataType(TUid aUid)
    1.66 +	:iUid(aUid)
    1.67 +/** Constructor taking a UID.
    1.68 +
    1.69 +The data type string is set to "x-epoc/x-app" concatenated with the decimal 
    1.70 +character representation of the specified UID value. The data type is assumed 
    1.71 +to identify data as a native Symbian type.
    1.72 +
    1.73 +@param aUid The associated UID. */
    1.74 +	{
    1.75 +	iDataType=KApaAppTypeDes;
    1.76 +	iDataType.AppendNum(STATIC_CAST(TInt,iUid.iUid));
    1.77 +	}
    1.78 +
    1.79 +EXPORT_C TInt TDataType::operator==(const TDataType& aDataType) const
    1.80 +/** Compares this data type for equality with the specified data type.
    1.81 +
    1.82 +Two data types are equal if their data type strings are the same. Text is 
    1.83 +folded for the purpose of the comparison, removing accents and converting 
    1.84 +letters to a common case form.
    1.85 +
    1.86 +@param aDataType The data type taking part in the comparison.
    1.87 +@return True, if the data types are equal; false, otherwise. */
    1.88 +	{
    1.89 +	return (iDataType.CompareF(aDataType.iDataType)==0);
    1.90 +	}
    1.91 +
    1.92 +EXPORT_C TInt TDataType::operator!=(const TDataType& aDataType) const
    1.93 +/** Compares this data type for inequality with the specified data type.
    1.94 +
    1.95 +Two data types are only equal if their data type strings are the same. Text 
    1.96 +is folded for the purpose of the comparison, removing accents and converting 
    1.97 +letters to a common case form.
    1.98 +
    1.99 +@param aDataType The data type taking part in the comparison.
   1.100 +@return True, if the data types are not equal; false, otherwise. */
   1.101 +	{
   1.102 +	return iDataType.CompareF(aDataType.iDataType);
   1.103 +	}
   1.104 +
   1.105 +EXPORT_C TBool TDataType::IsNative() const
   1.106 +/** Tests whether the data type is a native Symbian type.
   1.107 +
   1.108 +@return True, if the data type is a native Symbian type; false, otherwise. */
   1.109 +	{
   1.110 +	return iUid!=KNullUid;
   1.111 +	}
   1.112 +
   1.113 +EXPORT_C TUid TDataType::Uid() const
   1.114 +/** Gets the UID associated with this data type.
   1.115 +
   1.116 +@return The UID. */
   1.117 +	{
   1.118 +	return iUid;
   1.119 +	}
   1.120 +
   1.121 +EXPORT_C TBuf<KMaxDataTypeLength> TDataType::Des() const
   1.122 +/** Gets a copy of the data type string.
   1.123 +
   1.124 +@return A modifiable buffer descriptor containing a copy of the data type 
   1.125 +string. Note that this descriptor is a build independent type. */
   1.126 +	{
   1.127 +#ifdef _UNICODE
   1.128 +	TBuf16<KMaxDataTypeLength> buf;
   1.129 +	buf.Copy(iDataType);
   1.130 +	return buf;
   1.131 +#else
   1.132 +	return iDataType;
   1.133 +#endif // _UNICODE
   1.134 +	}
   1.135 +
   1.136 +EXPORT_C TPtrC8 TDataType::Des8() const
   1.137 +/** Gets an 8 bit non-modifiable pointer descriptor to the data type string.
   1.138 +
   1.139 +@return A pointer descriptor to the data type string. */
   1.140 +	{
   1.141 +	return iDataType;
   1.142 +	}
   1.143 +
   1.144 +void TDataType::ParseDes()
   1.145 +	{
   1.146 +	TInt desLen=KApaAppTypeDes.Length();
   1.147 +	if (iDataType.Length()<=desLen)
   1.148 +		iUid=KNullUid;
   1.149 +	else
   1.150 +		{
   1.151 +		if (iDataType.Left(desLen).CompareF(KApaAppTypeDes)==0)
   1.152 +			{
   1.153 +			TLex8 lex(iDataType);
   1.154 +			lex.SkipAndMark(desLen);
   1.155 +			TInt err=lex.Val(iUid.iUid);
   1.156 +			if (err!=KErrNone)
   1.157 +				iUid=KNullUid;
   1.158 +			}
   1.159 +		}
   1.160 +	}
   1.161 +
   1.162 +EXPORT_C void TDataType::InternalizeL(RReadStream& aReadStream)
   1.163 +/** Internalizes the data type from a stream.
   1.164 +
   1.165 +The presence of this function means that the standard templated stream operator>>() 
   1.166 +is available to internalize objects of this class.
   1.167 +
   1.168 +@param aReadStream The read stream. */
   1.169 +	{
   1.170 +	aReadStream >> iDataType;
   1.171 +	ParseDes();
   1.172 +	}
   1.173 +
   1.174 +EXPORT_C void TDataType::ExternalizeL(RWriteStream& aWriteStream) const
   1.175 +/** Externalizes the data type to a stream.
   1.176 +
   1.177 +The presence of this function means that the standard templated stream operator<<() 
   1.178 +is available to externalise objects of this class.
   1.179 +
   1.180 +@param aWriteStream The write stream. */
   1.181 +	{
   1.182 +	aWriteStream << iDataType;
   1.183 +	}
   1.184 +
   1.185 +//
   1.186 +// class TDataTypeWithPriority
   1.187 +//
   1.188 +
   1.189 +/** Default constructor */
   1.190 +EXPORT_C TDataTypeWithPriority::TDataTypeWithPriority()
   1.191 +	{
   1.192 +	}
   1.193 +
   1.194 +/** Constructor taking a data type and a priority value.
   1.195 +
   1.196 +@param aDataType The data type.
   1.197 +@param aPriority The priority value. */
   1.198 +EXPORT_C TDataTypeWithPriority::TDataTypeWithPriority(const TDataType& aDataType, TDataTypePriority aPriority)
   1.199 +	: iDataType(aDataType),
   1.200 +	iPriority(aPriority)
   1.201 +	{}
   1.202 +	
   1.203 +/** Internalizes the data type from a stream.
   1.204 +
   1.205 +The presence of this function means that the standard templated stream operator>>() 
   1.206 +is available to internalize objects of this class.
   1.207 +
   1.208 +@param aReadStream The read stream. */
   1.209 +EXPORT_C void TDataTypeWithPriority::InternalizeL(RReadStream& aReadStream)
   1.210 +	{
   1.211 +	aReadStream >> iDataType;
   1.212 +	aReadStream >> iPriority;
   1.213 +	}
   1.214 +
   1.215 +/** Externalizes the data type to a stream.
   1.216 +
   1.217 +The presence of this function means that the standard templated stream operator<<() 
   1.218 +is available to externalise objects of this class.
   1.219 +
   1.220 +@param aWriteStream The write stream. */
   1.221 +EXPORT_C void TDataTypeWithPriority::ExternalizeL(RWriteStream& aWriteStream) const
   1.222 +	{
   1.223 +	aWriteStream << iDataType;
   1.224 +	aWriteStream << iPriority;
   1.225 +	}
   1.226 +
   1.227 +GLDEF_C void Panic(TApmPanic aPanic)
   1.228 +//
   1.229 +// Panic the process with APMIME as the category.
   1.230 +//
   1.231 +	{
   1.232 +	_LIT(KApMimePanicCat,"APMIME");
   1.233 +	User::Panic(KApMimePanicCat,aPanic);
   1.234 +	}
   1.235 +
   1.236 +