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.

86 lines
3.0 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // CHSTRARR.H
  6. //
  7. // Purpose: Utility library version of MFC CHStringArray
  8. //
  9. //***************************************************************************
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #ifndef _CHStringArray_
  14. #define _CHStringArray_
  15. #include <polarity.h>
  16. #include <ProvExce.h>
  17. class POLARITY CHStringArray
  18. {
  19. public:
  20. CHStringArray();
  21. ~CHStringArray();
  22. // Attributes
  23. int GetSize() const { return m_nSize; }
  24. int GetUpperBound() const { return m_nSize-1; }
  25. void SetSize(int nNewSize, int nGrowBy = -1) throw ( CHeap_Exception ) ;
  26. // Operations
  27. // Clean up
  28. void FreeExtra() throw ( CHeap_Exception ) ;
  29. void RemoveAll() { SetSize(0); }
  30. // Accessing elements
  31. #if (!defined DEBUG && !defined _DEBUG)
  32. CHString GetAt(int nIndex) const{ return m_pData[nIndex]; }
  33. void SetAt(int nIndex, LPCWSTR newElement){ m_pData[nIndex] = newElement; }
  34. CHString& ElementAt(int nIndex) { return m_pData[nIndex]; }
  35. #else
  36. CHString GetAt(int nIndex) const;
  37. void SetAt(int nIndex, LPCWSTR newElement);
  38. CHString& ElementAt(int nIndex);
  39. #endif
  40. // Direct Access to the element data (may return NULL)
  41. const CHString* GetData() const { return (const CHString*)m_pData; }
  42. CHString* GetData() { return (CHString*)m_pData; }
  43. // Potentially growing the array
  44. void SetAtGrow(int nIndex, LPCWSTR newElement) throw ( CHeap_Exception ) ;
  45. int Add(LPCWSTR newElement) throw ( CHeap_Exception )
  46. {
  47. int nIndex = m_nSize;
  48. SetAtGrow(nIndex, newElement);
  49. return nIndex;
  50. }
  51. int Append(const CHStringArray& src) throw ( CHeap_Exception ) ;
  52. void Copy(const CHStringArray& src) throw ( CHeap_Exception ) ;
  53. // overloaded operator helpers
  54. CHString operator[](int nIndex) const { return GetAt(nIndex); }
  55. CHString& operator[](int nIndex) { return ElementAt(nIndex); }
  56. // Operations that move elements around
  57. void InsertAt(int nIndex, LPCWSTR newElement, int nCount = 1) throw ( CHeap_Exception ) ;
  58. void RemoveAt(int nIndex, int nCount = 1);
  59. void InsertAt(int nStartIndex, CHStringArray* pNewArray) throw ( CHeap_Exception ) ;
  60. // Implementation
  61. protected:
  62. CHString* m_pData; // the actual array of data
  63. int m_nSize; // # of elements (upperBound - 1)
  64. int m_nMaxSize; // max allocated
  65. int m_nGrowBy; // grow amount
  66. // local typedefs for class templates
  67. typedef CHString BASE_TYPE;
  68. typedef LPCWSTR BASE_ARG_TYPE;
  69. };
  70. ////////////////////////////////////////////////////////////////////////////
  71. #endif