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.

95 lines
2.5 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. SMALLARR.H
  5. Abstract:
  6. Small Array
  7. History:
  8. --*/
  9. #ifndef __WMI_SMALL_ARR__H_
  10. #define __WMI_SMALL_ARR__H_
  11. #include "corepol.h"
  12. #include "flexarry.h"
  13. class POLARITY CSmallArrayBlob
  14. {
  15. protected:
  16. int m_nSize;
  17. int m_nExtent;
  18. void* m_apMembers[ANYSIZE_ARRAY];
  19. public:
  20. static CSmallArrayBlob* CreateBlob(int nInitialSize);
  21. CSmallArrayBlob* InsertAt(int nIndex, void* pMember);
  22. void SetAt(int nIndex, void* pMember, void** ppOld = NULL);
  23. CSmallArrayBlob* RemoveAt(int nIndex, void** ppOld = NULL);
  24. void* operator[](int nIndex) const {return m_apMembers[nIndex];}
  25. void* GetAt(int nIndex) const {return m_apMembers[nIndex];}
  26. void** GetArrayPtr() {return (void**)m_apMembers;}
  27. void* const* GetArrayPtr() const {return (void**)m_apMembers;}
  28. int Size() const {return m_nSize;}
  29. void Sort();
  30. void Trim();
  31. void** CloneData();
  32. protected:
  33. void Initialize(int nInitialSize);
  34. CSmallArrayBlob* Grow();
  35. void CopyData(CSmallArrayBlob* pOther);
  36. CSmallArrayBlob* EnsureExtent(int nDesired);
  37. CSmallArrayBlob* ShrinkIfNeeded();
  38. CSmallArrayBlob* Shrink();
  39. static int __cdecl CompareEls(const void* pelem1, const void* pelem2);
  40. };
  41. class CSmallArray
  42. {
  43. protected:
  44. void* m_pData;
  45. public:
  46. inline CSmallArray();
  47. inline ~CSmallArray();
  48. inline void* GetAt(int nIndex) const;
  49. inline void* operator[](int nIndex) const { return GetAt(nIndex); }
  50. inline void SetAt(int nIndex, void *p, void** ppOld = NULL);
  51. inline int RemoveAt(int nIndex, void** ppOld = NULL);
  52. inline int InsertAt(int nIndex, void* pMember);
  53. int inline Add(void *pSrc) { return InsertAt(Size(), pSrc); }
  54. int inline Size() const;
  55. inline void Trim();
  56. inline void Empty();
  57. inline void** GetArrayPtr();
  58. inline void* const* GetArrayPtr() const;
  59. inline void Sort();
  60. inline void** UnbindPtr();
  61. protected:
  62. inline BOOL IsSingleton() const;
  63. inline BOOL IsEmpty() const;
  64. inline BOOL IsBlob() const;
  65. inline void EnsureBlob(int nMinSize);
  66. inline void* const & GetOnlyMember() const;
  67. inline void* & GetOnlyMember();
  68. inline void SetOnlyMember(void* p);
  69. inline CSmallArrayBlob* GetBlob();
  70. inline const CSmallArrayBlob* GetBlob() const;
  71. inline void SetBlob(CSmallArrayBlob* pBlob);
  72. };
  73. #include <smallarr.inl>
  74. #endif