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.

153 lines
4.4 KiB

  1. /******************************************************************************
  2. Header File: Utility Classes.H
  3. These classes are generally useful classes which can be used for a variety
  4. of purposes.
  5. Copyright (c) 1997 by Microsoft Corporation. All Rights Reserved.
  6. A Pretty Penny Enterprises Production
  7. Change History:
  8. 03-01-1997 Bob_Kjelgaard@Prodigy.Net Created it
  9. ******************************************************************************/
  10. #if !defined(UTILITY_CLASSES)
  11. #define UTILITY_CLASSES
  12. /******************************************************************************
  13. CMapWordToDWord class
  14. This class uses CMapWordToPtr to do its dirty work. When the need arises, I
  15. will make it serializable
  16. ******************************************************************************/
  17. class CMapWordToDWord : public CMapWordToPtr {
  18. public:
  19. unsigned Count() const { return (unsigned)CMapWordToPtr::GetCount(); }
  20. BOOL Lookup(WORD wKey, DWORD& dwItem) const;
  21. void GetNextAssoc(POSITION& pos, WORD& wKey, DWORD& dwItem) const;
  22. DWORD& operator[](WORD wKey);
  23. };
  24. /******************************************************************************
  25. CSafeObArray- This class, unlike CObArray, will delete any objects removed
  26. from the array. Otherwise it is identical.
  27. ******************************************************************************/
  28. class CSafeObArray : public CObject {
  29. CObArray m_coa;
  30. DECLARE_SERIAL(CSafeObArray)
  31. public:
  32. CSafeObArray() {}
  33. ~CSafeObArray();
  34. // Attributes
  35. unsigned GetSize() const { return (unsigned) m_coa.GetSize(); }
  36. CObject* operator[](unsigned u) const { return m_coa.GetAt(u); }
  37. //Operations
  38. int Add(CObject *pco) { return((int)m_coa.Add(pco)) ; }
  39. void InsertAt(unsigned uid, CObject *pco) { m_coa.InsertAt(uid, pco); }
  40. void RemoveAll();
  41. void RemoveAt(int i);
  42. void SetAt(int i, CObject *pco) { m_coa.SetAt(i, pco) ; }
  43. void Copy(CSafeObArray& csoa) ;
  44. void SetSize(int nsize, int ngrow = -1) { m_coa.SetSize(nsize, ngrow) ; }
  45. CObArray* GetCOA() { return &m_coa ; }
  46. virtual void Serialize(CArchive& car);
  47. };
  48. /******************************************************************************
  49. CSafeMapWordToOb
  50. This class encapsulates a CMapWordToOb object, but it does what the
  51. documentation says the CMapWordToOb does, and definitely oes not do- delete
  52. the underling objects when the map no longer references them!
  53. ******************************************************************************/
  54. class CSafeMapWordToOb : public CObject {
  55. CMapWordToOb m_cmw2o;
  56. DECLARE_SERIAL(CSafeMapWordToOb)
  57. public:
  58. CSafeMapWordToOb() {}
  59. ~CSafeMapWordToOb();
  60. // Attributes
  61. unsigned GetCount() const { return (unsigned) m_cmw2o.GetCount(); }
  62. BOOL Lookup(WORD wKey, CObject*& pco) const {
  63. return m_cmw2o.Lookup(wKey, pco);
  64. }
  65. POSITION GetStartPosition() const { return m_cmw2o.GetStartPosition(); }
  66. void GetNextAssoc(POSITION& pos, WORD& wKey, CObject*& pco) const {
  67. m_cmw2o.GetNextAssoc(pos, wKey, pco);
  68. }
  69. // Operations
  70. CObject*& operator[](WORD wKey);
  71. BOOL RemoveKey(WORD wKey);
  72. void RemoveAll();
  73. virtual void Serialize(CArchive& car);
  74. };
  75. class CStringTable : public CObject {
  76. DECLARE_SERIAL(CStringTable)
  77. CString m_csEmpty;
  78. CUIntArray m_cuaKeys;
  79. CStringArray m_csaValues;
  80. CUIntArray m_cuaRefFlags ; // Referenced flags used in WS checking
  81. public:
  82. CStringTable() {}
  83. // Attributes
  84. unsigned Count() const { return (unsigned)m_cuaKeys.GetSize(); }
  85. CString operator[](WORD wKey) const;
  86. void Details(unsigned u, WORD &wKey, CString &csValue);
  87. // Operations
  88. void Map(WORD wKey, CString csValue);
  89. void Remove(WORD wKey);
  90. void Reset() {
  91. m_csaValues.RemoveAll();
  92. m_cuaKeys.RemoveAll();
  93. }
  94. virtual void Serialize(CArchive& car);
  95. // Reference flag management routines
  96. bool GetRefFlag(unsigned u) { return (m_cuaRefFlags[u] != 0) ; }
  97. void SetRefFlag(unsigned u) { m_cuaRefFlags[u] = (unsigned) true ; }
  98. void ClearRefFlag(unsigned u) { m_cuaRefFlags[u] = (unsigned) false ; }
  99. void InitRefFlags() ;
  100. };
  101. #endif
  102.