📄 hxvalues.cpp
字号:
{ pNewList = new CKeyValueList; if (pNewList) { pNewList->AddRef(); return HXR_OK; } 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 CKeyValueListSTDMETHODIMPCKeyValueList::SetPropertyULONG32(const char* pPropertyName, ULONG32 uPropertyValue){ return m_UlongMap.SetProperty(pPropertyName,uPropertyValue);}STDMETHODIMPCKeyValueList::GetPropertyULONG32(const char* pPropertyName, REF(ULONG32) uPropertyName){ return m_UlongMap.GetProperty(pPropertyName,uPropertyName);}STDMETHODIMPCKeyValueList::GetFirstPropertyULONG32(REF(const char*) pPropertyName, REF(ULONG32) uPropertyValue){ return m_UlongMap.GetFirstProperty(pPropertyName, uPropertyValue);}STDMETHODIMPCKeyValueList::GetNextPropertyULONG32(REF(const char*) pPropertyName, REF(ULONG32) uPropertyValue){ return m_UlongMap.GetNextProperty(pPropertyName, uPropertyValue);}STDMETHODIMPCKeyValueList::SetPropertyBuffer(const char* pPropertyName, IHXBuffer* pPropertyValue){ return m_BufferMap.SetProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCKeyValueList::GetPropertyBuffer(const char* pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_BufferMap.GetProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCKeyValueList::GetFirstPropertyBuffer(REF(const char*) pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_BufferMap.GetFirstProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCKeyValueList::GetNextPropertyBuffer(REF(const char*) pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_BufferMap.GetNextProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCKeyValueList::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;}STDMETHODIMPCKeyValueList::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; }}STDMETHODIMPCKeyValueList::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::listvoid 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 CKeyValueListIterSTDMETHODIMP 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 CKeyValueListIterOneKeySTDMETHODIMP 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;}////////////// CHXUniquelyKeyedListSTDMETHODIMP 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}STDMETHODIMPCHXUniquelyKeyedList::SetPropertyULONG32(const char* pPropertyName, ULONG32 uPropertyValue){ return m_UlongMap.SetProperty(pPropertyName,uPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetPropertyULONG32(const char* pPropertyName, REF(ULONG32) uPropertyName){ return m_UlongMap.GetProperty(pPropertyName,uPropertyName);}STDMETHODIMPCHXUniquelyKeyedList::GetFirstPropertyULONG32(REF(const char*) pPropertyName, REF(ULONG32) uPropertyValue){ return m_UlongMap.GetFirstProperty(pPropertyName, uPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetNextPropertyULONG32(REF(const char*) pPropertyName, REF(ULONG32) uPropertyValue){ return m_UlongMap.GetNextProperty(pPropertyName, uPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::SetPropertyBuffer(const char* pPropertyName, IHXBuffer* pPropertyValue){ return m_BufferMap.SetProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetPropertyBuffer(const char* pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_BufferMap.GetProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetFirstPropertyBuffer(REF(const char*) pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_BufferMap.GetFirstProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetNextPropertyBuffer(REF(const char*) pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_BufferMap.GetNextProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::SetPropertyCString(const char* pPropertyName, IHXBuffer* pPropertyValue){ return m_CStringMap.SetProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetPropertyCString(const char* pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_CStringMap.GetProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetFirstPropertyCString(REF(const char*) pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_CStringMap.GetFirstProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::GetNextPropertyCString(REF(const char*) pPropertyName, REF(IHXBuffer*) pPropertyValue){ return m_CStringMap.GetNextProperty(pPropertyName,pPropertyValue);}STDMETHODIMPCHXUniquelyKeyedList::Remove(const char* pPropertyName){ m_UlongMap.Remove(pPropertyName); m_BufferMap.Remove(pPropertyName); m_CStringMap.Remove(pPropertyName); return HXR_OK;}STDMETHODIMPCHXUniquelyKeyedList::RemoveULONG32(const char* pPropertyName){ m_UlongMap.Remove(pPropertyName); return HXR_OK;}STDMETHODIMPCHXUniquelyKeyedList::RemoveBuffer(const char* pPropertyName){ m_BufferMap.Remove(pPropertyName); return HXR_OK;}STDMETHODIMPCHXUniquelyKeyedList::RemoveCString(const char* pPropertyName){ m_CStringMap.Remove(pPropertyName); return HXR_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -