Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 - 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: BagArray.inl
  6. * Content: CBagArray methods
  7. *
  8. * History:
  9. * Date By Reason
  10. * ====== == ======
  11. * 12-12-2001 simonpow Created
  12. ***************************************************************************/
  13. template <class T>
  14. BOOL CBagArray<T>::AddElements(const T * pElems, DWORD dwNumElem)
  15. {
  16. //ensure pointer passed isn't into this bags contents!
  17. DNASSERT(!(pElems>=m_data.GetAllElements() && pElems<m_data.GetAllElements()+m_data.GetCurrentSize()));
  18. if (!m_data.AllocAtLeast(m_dwTopFreeSlot+dwNumElem))
  19. return FALSE;
  20. for (DWORD dwLoop=0; dwLoop<dwNumElem; dwLoop++)
  21. m_data.SetExistingElement(dwLoop+m_dwTopFreeSlot, pElems[dwLoop]);
  22. m_dwTopFreeSlot+=dwNumElem;
  23. return TRUE;
  24. }
  25. template <class T>
  26. BOOL CBagArray<T>::AddElements(const CBagArray<T>& bag)
  27. {
  28. //ensure bag supplied isn't this bag
  29. DNASSERT(this!=&bag);
  30. if (!m_data.AllocAtLeast(m_dwTopFreeSlot+bag.GetNumElements()))
  31. return FALSE;
  32. for (DWORD dwLoop=0; dwLoop<bag.GetNumElements(); dwLoop++)
  33. m_data.SetExistingElement(dwLoop+m_dwTopFreeSlot, bag.GetElementRef(dwLoop));
  34. m_dwTopFreeSlot+=bag.GetNumElements();
  35. return TRUE;
  36. }
  37. template <class T>
  38. BOOL CBagArray<T>::RemoveElementByValue(const T& elem)
  39. {
  40. for (DWORD dwLoop=0; dwLoop<m_dwTopFreeSlot; dwLoop++)
  41. {
  42. if (m_data.GetElementRef(dwLoop)==elem)
  43. {
  44. m_dwTopFreeSlot--;
  45. if (dwLoop!=m_dwTopFreeSlot)
  46. m_data.SetExistingElement(dwLoop, m_data.GetElementRef(m_dwTopFreeSlot));
  47. return TRUE;
  48. }
  49. }
  50. return FALSE;
  51. }
  52. template <class T>
  53. BOOL CBagArray<T>::FindElement(const T& elem, DWORD * pdwIndex) const
  54. {
  55. for (DWORD dwLoop=0; dwLoop<m_dwTopFreeSlot; dwLoop++)
  56. {
  57. if (m_data.GetElementRef(dwLoop)==elem)
  58. {
  59. *pdwIndex=dwLoop;
  60. return TRUE;
  61. }
  62. }
  63. return FALSE;
  64. }