3gppttutils.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:6k
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: RCSL 1.0/RPSL 1.0
- *
- * Portions Copyright (c) 1995-2003 RealNetworks, Inc. All Rights Reserved.
- *
- * The contents of this file, and the files included with this file, are
- * subject to the current version of the RealNetworks Public Source License
- * Version 1.0 (the "RPSL") available at
- * http://www.helixcommunity.org/content/rpsl unless you have licensed
- * the file under the RealNetworks Community Source License Version 1.0
- * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
- * in which case the RCSL will apply. You may also obtain the license terms
- * directly from RealNetworks. You may not use this file except in
- * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
- * applicable to this file, the RCSL. Please see the applicable RPSL or
- * RCSL for the rights, obligations and limitations governing use of the
- * contents of the file.
- *
- * This file is part of the Helix DNA Technology. RealNetworks is the
- * developer of the Original Code and owns the copyrights in the portions
- * it created.
- *
- * This file, and the files included with this file, is distributed and made
- * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- *
- * Technology Compatibility Kit Test Suite(s) Location:
- * http://www.helixcommunity.org/content/tck
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** */
- #ifndef _3GPPTTUTILS_H_
- #define _3GPPTTUTILS_H_
- /****************************************************************************
- * Includes
- */
- #include "hxtypes.h"
- #include "hxresult.h"
- #include "hxassert.h"
- /*
- * Utilities
- */
- inline int swapEndian(UCHAR* pInOut, UINT32 ulLen)
- {
- UINT32 i = 0, j = 0;
- UCHAR c;
- for (j = ulLen-1; i < ulLen/2; ++i, --j)
- {
- c = pInOut[i];
- pInOut[i] = pInOut[j];
- pInOut[j] = c;
- }
- return 0;
- }
- inline ULONG32 GetUL32(const UINT8* pData)
- {
- return (*pData << 24) |
- (*(pData + 1) << 16) |
- (*(pData + 2) << 8 ) |
- *(pData + 3);
- }
- inline UINT16 GetUI16(const UINT8* pData)
- {
- return (*pData << 8) |
- *(pData + 1);
- }
- inline UINT32 ReadARGB(const UINT8*& pData)
- {
- // 0xff = fully opaque in 3gpp; 0x00 = fully opaque in Helix ARGB format
- UINT32 alpha = 0xFF - pData[3];
- UINT32 argb =
- (alpha << 24) |
- (UINT32(pData[0]) << 16) |
- (UINT32(pData[1]) << 8) |
- UINT32(pData[2]);
- pData += 4;
- return argb;
- }
- inline ULONG32 ReadUL32(const UINT8*& pData)
- {
- ULONG32 val = GetUL32(pData);
- pData += 4;
- return val;
- }
- inline UINT16 ReadUI16(const UINT8*& pData)
- {
- UINT16 val = GetUI16(pData);
- pData += 2;
- return val;
- }
- // /Returns TRUE if the string passed in is UTF-16, else returns FALSE. UTF16
- // text always starts with 0xFEFF flag unless it's reverse UTF16, in which
- // case it's 0xFFFE. (Rel5 spec says reverse does not have to be supported):
- inline BOOL
- IsUTF16Encoded(const UCHAR* pText, INT32 lTextLen, BOOL& bREFIsReverseUTF16)
- {
- bREFIsReverseUTF16 = FALSE;
- if (!pText || lTextLen < 2)
- {
- return FALSE;
- }
- if (0xFE == pText[0] && 0xFF == pText[1])
- {
- return TRUE;
- }
- else if (0xFF == pText[0] && 0xFE == pText[1])
- {
- bREFIsReverseUTF16 = TRUE;
- return TRUE;
- }
- return FALSE;
- }
- inline BOOL
- isUTF16NewlineChar(UINT16 ch16, BOOL bPriorCharWasCarriageReturn,
- BOOL& bREFCurCharIsCarriageReturn,
- BOOL& bREFCurCharIsAtomicNewline)
- {
- // u000a (LF) 00000000000000000000000000001010
- // u000d (CR) 00000000000000000000000000001101
- // u000du000a (CRLF)
- // u0085 (NEXT LINE) 00000000000000000000000010000101
- // u2028 (LINE SEP) 00000000000000000010000000101000
- // u2029 (PARA SEP) 00000000000000000010000000101001
- bREFCurCharIsCarriageReturn = FALSE;
- bREFCurCharIsAtomicNewline = TRUE; // /TRUE unless it is LF part of CRLF
- if (0x000a == ch16) // /(LF)
- {
- if (bPriorCharWasCarriageReturn)
- {
- bREFCurCharIsAtomicNewline = FALSE;
- }
- return TRUE;
- }
- else if (0x000d == ch16) // /(CR)
- {
- bREFCurCharIsCarriageReturn = TRUE;
- return TRUE;
- }
- else if (0x0085 == ch16 || // /(NEXT LINE)
- 0x2028 == ch16 || // /(LINE SEP)
- 0x2029 == ch16) // /(PARA SEP)
- {
- return TRUE;
- }
- return FALSE;
- }
- class SimpleString
- {
- public:
- SimpleString() : m_psz(0) {}
- HX_RESULT Set(const char* pch, UINT32 cch);
-
- UINT32 Length() const { return m_length; }
- ~SimpleString()
- {
- delete [] m_psz;
- }
- operator const char*() const { return m_psz ? m_psz : ""; }
- private:
- // disallow assignment and copy
- SimpleString(const SimpleString& rhs);
- SimpleString& operator=(const SimpleString& rhs);
- private:
- char* m_psz;
- UINT32 m_length;
- };
- class SimpleArray
- {
- public:
- SimpleArray() : m_ppVoid(0), m_count(0) {}
- HX_RESULT Reset(UINT32 count);
-
- UINT32 GetCount() const { return m_count; }
- ~SimpleArray(){ delete [] m_ppVoid; }
- // get for non-const
- void* GetItem(UINT32 idx) { HX_ASSERT(idx < m_count); return m_ppVoid[idx]; }
- // get/set for non-const
- void*& operator[](UINT32 idx) { HX_ASSERT(idx < m_count); return m_ppVoid[idx]; }
- // get for const
- const void* GetItem(UINT32 idx) const { HX_ASSERT(idx < m_count); return m_ppVoid[idx]; }
- private:
- // disallow assignment and copy
- SimpleArray(const SimpleArray& rhs);
- SimpleArray& operator=(const SimpleArray& rhs);
- private:
- void** m_ppVoid;
- UINT32 m_count;
- };
- #endif // _3GPPTTUTILS_H_