123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- // MyMapPtrToPtr.cpp: implementation of the CMyMapPtrToPtr class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "datamanager.h"
- #include "MyMapPtrToPtr.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMyMapPtrToPtr::CMyMapPtrToPtr()
- {
- }
- CMyMapPtrToPtr::~CMyMapPtrToPtr()
- {
- }
- void CMyMapPtrToPtr::SetAt(LPVOID key, LPVOID newValue )
- {
- UINT uID = (UINT)key;
- CDataNodeBase* pNodeNew = (CDataNodeBase*)newValue;
- CDataNodeBase* pNode = NULL;
- if(this->Lookup(key, (void*&)pNode))
- {
- POSITION pos = m_listSubs.Find(pNode);
- ASSERT(pos);
- if(pos)
- m_listSubs.RemoveAt(pos);
- }
-
- //维护按ID递增管理的列表:
- if(m_listSubs.GetCount())
- {
- pNode = (CDataNodeBase*)m_listSubs.GetHead();
- if(pNodeNew->GetID() < pNode->GetID())
- m_listSubs.AddHead(pNodeNew);
- else
- {
- pNode = (CDataNodeBase*)m_listSubs.GetTail();
- if(pNodeNew->GetID() > pNode->GetID())
- m_listSubs.AddTail(pNodeNew);
- else
- {
- POSITION pos = m_listSubs.GetHeadPosition();
- POSITION posLast = pos;
- while(pos)
- {
- posLast = pos;
- pNode = (CDataNodeBase*)m_listSubs.GetNext(pos);
- if(pNode->GetID() > pNodeNew->GetID())
- break;
- }
- m_listSubs.InsertBefore(posLast, pNodeNew);
- }
- }
- }
- else
- {
- m_listSubs.AddTail(pNodeNew);
- }
- CMapPtrToPtr::SetAt(key, newValue);
- }
- BOOL CMyMapPtrToPtr::RemoveKey(LPVOID key)
- {
- UINT uID = (UINT)key;
- CDataNodeBase* pNode = NULL;
- if(this->Lookup(key, (void*&)pNode))
- {
- POSITION pos = m_listSubs.Find(pNode);
- ASSERT(pos);
- if(pos)
- m_listSubs.RemoveAt(pos);
- }
- return CMapPtrToPtr::RemoveKey(key);
- }
- void CMyMapPtrToPtr::RemoveAll( )
- {
- m_listSubs.RemoveAll();
- CMapPtrToPtr::RemoveAll();
- }
- //ID递增方式管理的子项集合
- CPtrList& CMyMapPtrToPtr::GetPtrList()
- {
- return m_listSubs;
- }
|