chxavbuffer.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:2k
- /*============================================================================*
- *
- * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *============================================================================*/
-
- #include "chxavbuffer.h"
- #include "chxavmemutil.h"
- #include "chxavminmax.h"
- CHXAvBufferRep::CHXAvBufferRep(const CHXAvBufferRep& rep)
- : m_pData(new char[rep.m_maxLen]),
- m_len(rep.m_len),
- m_maxLen(rep.m_maxLen)
- {
- if (rep.m_len > 0)
- CHXAvMemUtil::MemCopy(m_pData, rep.m_pData, rep.m_len);
- }
- CHXAvBufferRep& CHXAvBufferRep::operator=(const CHXAvBufferRep& rep)
- {
- if (&rep != this)
- {
- delete [] m_pData;
- m_pData = new char[rep.m_maxLen]; //XXXLCM can fail
- if (rep.m_len > 0)
- CHXAvMemUtil::MemCopy(m_pData, rep.m_pData, rep.m_len);
- }
- return *this;
- }
- void CHXAvBufferRep::Grow(int size)
- {
- if (m_maxLen < size)
- {
- m_maxLen = 1;
- for (; m_maxLen <= size; m_maxLen <<= 1)
- ;
- char* pData = new char[m_maxLen];
- if (m_pData && m_len > 0)
- CHXAvMemUtil::MemCopy(pData, m_pData, m_len);
- delete [] m_pData;
- m_pData = pData;
- }
- }
- void CHXAvBufferRep::Copy(const char* pBuf, int size)
- {
- if (size > 0)
- {
- if (m_maxLen < size)
- {
- m_maxLen = 1;
- for (; m_maxLen <= size; m_maxLen <<= 1)
- ;
- delete [] m_pData;
- m_pData = new char[m_maxLen];
- }
- CHXAvMemUtil::MemCopy(m_pData, pBuf, size);
- }
- m_len = max(size, 0);
- }
- void CHXAvBufferRep::Append(const char* pBuf, int size)
- {
- if (size > 0)
- {
- if (m_len + size > m_maxLen)
- Grow(m_len + size);
- CHXAvMemUtil::MemCopy(m_pData + m_len, pBuf, size);
- m_len += size;
- }
- }