⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hxvalues.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    else
    {
	return HXR_OUTOFMEMORY;
    }
}

STDMETHODIMP 
CKeyValueList::ImportValues(THIS_
			    IHXValues* pValues)
{
    HX_RESULT hResult = HXR_OK;
    const char* pName  = NULL;
    IHXBuffer* pBuffer = NULL;

    // Copy all CStrings
    hResult = pValues->GetFirstPropertyCString(pName, pBuffer);
    while (hResult == HXR_OK)
    {
	this->AddKeyValue(pName,pBuffer);
	HX_RELEASE(pBuffer);

	hResult = pValues->GetNextPropertyCString(pName, pBuffer);
    }

    // Copy all ULONGs
    ULONG32 ul;
    hResult = pValues->GetFirstPropertyULONG32(pName, ul);
    while (hResult == HXR_OK)
    {
	this->SetPropertyULONG32(pName,ul);
	hResult = pValues->GetNextPropertyULONG32(pName, ul);
    }

    // Copy all Buffers
    hResult = pValues->GetFirstPropertyBuffer(pName, pBuffer);
    while (hResult == HXR_OK)
    {
	this->SetPropertyBuffer(pName,pBuffer);
	HX_RELEASE(pBuffer);
	hResult = pValues->GetNextPropertyBuffer(pName, pBuffer);
    }

    return HXR_OK;
}


////////// Support IHXValues interface for CKeyValueList

STDMETHODIMP
CKeyValueList::SetPropertyULONG32(const char*      pPropertyName,
				  ULONG32          uPropertyValue)
{
    return m_UlongMap.SetProperty(pPropertyName,uPropertyValue);
}

STDMETHODIMP
CKeyValueList::GetPropertyULONG32(const char*      pPropertyName,
				  REF(ULONG32)     uPropertyName)
{
    return m_UlongMap.GetProperty(pPropertyName,uPropertyName);
}

STDMETHODIMP
CKeyValueList::GetFirstPropertyULONG32(REF(const char*) pPropertyName,
				       REF(ULONG32)     uPropertyValue)
{
    return m_UlongMap.GetFirstProperty(pPropertyName, uPropertyValue);
}

STDMETHODIMP
CKeyValueList::GetNextPropertyULONG32(REF(const char*) pPropertyName,
				      REF(ULONG32)     uPropertyValue)
{
    return m_UlongMap.GetNextProperty(pPropertyName, uPropertyValue);
}


STDMETHODIMP
CKeyValueList::SetPropertyBuffer(const char*      pPropertyName,
				 IHXBuffer*      pPropertyValue)
{
    return m_BufferMap.SetProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CKeyValueList::GetPropertyBuffer(const char*      pPropertyName,
				 REF(IHXBuffer*) pPropertyValue)
{
    return m_BufferMap.GetProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CKeyValueList::GetFirstPropertyBuffer(REF(const char*) pPropertyName,
				      REF(IHXBuffer*) pPropertyValue)
{
    return m_BufferMap.GetFirstProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CKeyValueList::GetNextPropertyBuffer(REF(const char*) pPropertyName,
				     REF(IHXBuffer*) pPropertyValue)
{
    return m_BufferMap.GetNextProperty(pPropertyName,pPropertyValue);
}


STDMETHODIMP
CKeyValueList::SetPropertyCString(const char*      pPropertyName,
				  IHXBuffer*      pPropertyValue)
{
    if (!pPropertyValue)
    {
	HX_ASSERT(0);
	return HXR_FAIL;
    }

    // I am trying to preserve the semantics that Kirk had here.
    // I replace the first instance of the key, if any, or if the
    // key does not exist yet, I simply add to the list.
    node *p;
    for (p = m_pList->m_pHead; p; p = p->pNext)
    {
	if (!strcasecmp(pPropertyName,p->pKey))
	{
	    IHXBuffer* pOldStr = p->pStr;
	    p->pStr = pPropertyValue;
	    p->pStr->AddRef();
    	    HX_RELEASE(pOldStr);
	    return HXR_OK;
	}
    }
    
    return AddKeyValue(pPropertyName,pPropertyValue);
}

STDMETHODIMP 
CKeyValueList::GetPropertyCString(const char*      pPropertyName,
				  REF(IHXBuffer*) pPropertyValue)
{
    node *p;
    for (p = m_pList->m_pHead; p; p = p->pNext)
    {
	if (!strcasecmp(pPropertyName,p->pKey))
	{
	    pPropertyValue = p->pStr;
	    pPropertyValue->AddRef();
	    return HXR_OK;
	}
    }
    return HXR_FAIL;
}

STDMETHODIMP
CKeyValueList::GetFirstPropertyCString(REF(const char*) pPropertyName,
				       REF(IHXBuffer*) pPropertyValue)
{
    m_NonReentrantIterator.m_pCurr = m_pList->m_pHead;

    if (m_NonReentrantIterator.m_pCurr)
    {
	pPropertyName  = m_NonReentrantIterator.m_pCurr->pKey;
	pPropertyValue = m_NonReentrantIterator.m_pCurr->pStr;
	pPropertyValue->AddRef();
	return HXR_OK;
    }
    else
    {
	return HXR_FAIL;
    }
}

STDMETHODIMP
CKeyValueList::GetNextPropertyCString(REF(const char*) pPropertyName,
	    			      REF(IHXBuffer*) pPropertyValue)
{
    if (!m_NonReentrantIterator.m_pCurr)
    {
	HX_ASSERT(0);
	return HXR_UNEXPECTED;
    }

    m_NonReentrantIterator.m_pCurr = m_NonReentrantIterator.m_pCurr->pNext;

    if (m_NonReentrantIterator.m_pCurr)
    {
	pPropertyName  = m_NonReentrantIterator.m_pCurr->pKey;
	pPropertyValue = m_NonReentrantIterator.m_pCurr->pStr;
	pPropertyValue->AddRef();
	return HXR_OK;
    }
    else
    {
	return HXR_FAIL;
    }
}


/////////  Implement CKeyValueList::list

void CKeyValueList::list::AddRef()
{
    InterlockedIncrement(&m_lRefCount);
}

void CKeyValueList::list::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return;
    }
    else
    {
    	delete this;
    }
}

CKeyValueList::list::list() : m_pHead(NULL), m_lRefCount(0) 
{
}

CKeyValueList::list::~list()
{
    while (m_pHead)
    {
	node *p = m_pHead;
	HX_RELEASE(p->pStr);
	delete[] p->pKey;
	m_pHead = p->pNext;
	delete p;
    }
    m_pHead = NULL; // paranoid
}

///////////// Implement CKeyValueListIter

STDMETHODIMP CKeyValueListIter::QueryInterface(REFIID riid, void** ppvObj)
{
    if (IsEqualIID(riid, IID_IHXKeyValueListIter))
    {
	AddRef();
	*ppvObj = (IHXKeyValueListIter*)this;
	return HXR_OK;
    }
    else if (IsEqualIID(riid, IID_IUnknown))
    {
	AddRef();
	*ppvObj = this;
	return HXR_OK;
    }

    *ppvObj = NULL;
    return HXR_NOINTERFACE;
}

STDMETHODIMP_(ULONG32) CKeyValueListIter::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) CKeyValueListIter::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return m_lRefCount;
    }

    delete this;
    return 0;
}

CKeyValueListIter::CKeyValueListIter(CKeyValueList::list* pList) 
    :	m_pList(pList), 
	m_pCurr(NULL),
	m_lRefCount(0) 
{
    m_pList->AddRef();
}
    
CKeyValueListIter::~CKeyValueListIter() 
{
    if (m_pList)
    {
        m_pList->Release();
        m_pList = NULL;
    }
}


STDMETHODIMP 
CKeyValueListIter::GetNextPair(REF(const char*) pKey, REF(IHXBuffer*) pStr)
{
    if (m_pCurr == NULL)
    {
	m_pCurr = m_pList->m_pHead;
    }
    else
    {
	m_pCurr = m_pCurr->pNext;
    }
    if (m_pCurr)
    {
	pKey = m_pCurr->pKey;
	pStr = m_pCurr->pStr;
	pStr->AddRef();
	// important -- don't advance m_pCurr till next
	// call, or you'll break ReplaceCurr
	return HXR_OK;
    }
    else
    {
	return HXR_FAILED;
    }
}

STDMETHODIMP 
CKeyValueListIter::ReplaceCurr(IHXBuffer* pStr)
{
    // overwrites string from last call to GetNextPair
    if (!m_pCurr)
    {
	HX_ASSERT(0);
	return HXR_UNEXPECTED;
    }
    else
    {
	IHXBuffer *pOld = m_pCurr->pStr;
	m_pCurr->pStr = pStr;
	m_pCurr->pStr->AddRef();
	HX_RELEASE(pOld);
    }
    return HXR_OK;
}


////////////////// Implement CKeyValueListIterOneKey


STDMETHODIMP CKeyValueListIterOneKey::QueryInterface(REFIID riid, void** ppvObj)
{
    if (IsEqualIID(riid, IID_IHXKeyValueListIterOneKey))
    {
	AddRef();
	*ppvObj = (IHXKeyValueListIterOneKey*)this;
	return HXR_OK;
    }
    else if (IsEqualIID(riid, IID_IUnknown))
    {
	AddRef();
	*ppvObj = this;
	return HXR_OK;
    }

    *ppvObj = NULL;
    return HXR_NOINTERFACE;
}

STDMETHODIMP_(ULONG32) CKeyValueListIterOneKey::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) CKeyValueListIterOneKey::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return m_lRefCount;
    }

    delete this;
    return 0;
}

CKeyValueListIterOneKey::CKeyValueListIterOneKey(const char* pKey,
						 CKeyValueList::list* pList) 
    :	m_pList(pList), 
	m_pCurr(pList->m_pHead),
	m_pReplace(0),
	m_lRefCount(0) 
{
    m_pList->AddRef();
    m_pKey = new_string(pKey);
}
    
CKeyValueListIterOneKey::~CKeyValueListIterOneKey() 
{
    if (m_pList)
    {
        m_pList->Release();
        m_pList = NULL;
    }
    delete[] m_pKey;
}


STDMETHODIMP 
CKeyValueListIterOneKey::GetNextString(REF(IHXBuffer*) pStr)
{
    while (m_pCurr)
    {
	if (!strcasecmp(m_pCurr->pKey,m_pKey))
	{
	    pStr = m_pCurr->pStr;
	    pStr->AddRef();
	    m_pReplace = m_pCurr;
       	    m_pCurr = m_pCurr->pNext;
	    return HXR_OK;
	}
	m_pCurr = m_pCurr->pNext;
    }

    return HXR_FAILED;
}

STDMETHODIMP 
CKeyValueListIterOneKey::ReplaceCurr(IHXBuffer* pStr)
{
    // overwrites string from last call to GetNextString
    if (!m_pReplace)
    {
	HX_ASSERT(0);
	return HXR_UNEXPECTED;
    }
    else
    {
	IHXBuffer *pOld = m_pReplace->pStr;
	m_pReplace->pStr = pStr;
	m_pReplace->pStr->AddRef();
	HX_RELEASE(pOld);
    }
    return HXR_OK;
}

////////////// CHXUniquelyKeyedList

STDMETHODIMP CHXUniquelyKeyedList::QueryInterface(REFIID riid, void** ppvObj)
{
	QInterfaceList qiList[] =
	{
		{ GET_IIDHANDLE(IID_IUnknown), this },
		{ GET_IIDHANDLE(IID_IHXValues), (IHXValues*) this },
		{ GET_IIDHANDLE(IID_IHXValuesRemove), (IHXValuesRemove*) this },
	};	
    return QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);   
}

STDMETHODIMP_(ULONG32) CHXUniquelyKeyedList::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) CHXUniquelyKeyedList::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return m_lRefCount;
    }

    delete this;
    return 0;
}

CHXUniquelyKeyedList::CHXUniquelyKeyedList() : m_lRefCount(0)
{
    // most members construct themselves
}

CHXUniquelyKeyedList::~CHXUniquelyKeyedList()
{
    // members destruct themselves
}

STDMETHODIMP
CHXUniquelyKeyedList::SetPropertyULONG32(const char*      pPropertyName,
				          ULONG32          uPropertyValue)
{
    return m_UlongMap.SetProperty(pPropertyName,uPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetPropertyULONG32(const char*      pPropertyName,
				          REF(ULONG32)     uPropertyName)
{
    return m_UlongMap.GetProperty(pPropertyName,uPropertyName);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetFirstPropertyULONG32(REF(const char*) pPropertyName,
				               REF(ULONG32)     uPropertyValue)
{
    return m_UlongMap.GetFirstProperty(pPropertyName, uPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetNextPropertyULONG32(REF(const char*) pPropertyName,
				              REF(ULONG32)     uPropertyValue)
{
    return m_UlongMap.GetNextProperty(pPropertyName, uPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::SetPropertyBuffer(const char*      pPropertyName,
				         IHXBuffer*      pPropertyValue)
{
    return m_BufferMap.SetProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetPropertyBuffer(const char*      pPropertyName,
				         REF(IHXBuffer*) pPropertyValue)
{
    return m_BufferMap.GetProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetFirstPropertyBuffer(REF(const char*) pPropertyName,
		    		              REF(IHXBuffer*) pPropertyValue)
{
    return m_BufferMap.GetFirstProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetNextPropertyBuffer(REF(const char*) pPropertyName,
				             REF(IHXBuffer*) pPropertyValue)
{
    return m_BufferMap.GetNextProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::SetPropertyCString(const char*      pPropertyName,
				         IHXBuffer*      pPropertyValue)
{
    return m_CStringMap.SetProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetPropertyCString(const char*      pPropertyName,
				          REF(IHXBuffer*) pPropertyValue)
{
    return m_CStringMap.GetProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetFirstPropertyCString(REF(const char*) pPropertyName,
		    		              REF(IHXBuffer*) pPropertyValue)
{
    return m_CStringMap.GetFirstProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::GetNextPropertyCString(REF(const char*) pPropertyName,
				              REF(IHXBuffer*) pPropertyValue)
{
    return m_CStringMap.GetNextProperty(pPropertyName,pPropertyValue);
}

STDMETHODIMP
CHXUniquelyKeyedList::Remove(const char* pPropertyName)
{
    m_UlongMap.Remove(pPropertyName);
    m_BufferMap.Remove(pPropertyName);
    m_CStringMap.Remove(pPropertyName);
    return HXR_OK;
}

STDMETHODIMP
CHXUniquelyKeyedList::RemoveULONG32(const char* pPropertyName)
{
    m_UlongMap.Remove(pPropertyName);
    return HXR_OK;
}

STDMETHODIMP
CHXUniquelyKeyedList::RemoveBuffer(const char* pPropertyName)
{
    m_BufferMap.Remove(pPropertyName);
    return HXR_OK;
}

STDMETHODIMP
CHXUniquelyKeyedList::RemoveCString(const char* pPropertyName)
{
    m_CStringMap.Remove(pPropertyName);
    return HXR_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -