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.

115 lines
2.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: QueryUnk.hxx
  7. //
  8. // Contents: Controlling IUnknown for IQuery/IRowset
  9. //
  10. // History: 18 Jul 1995 AlanW Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. class CRowset;
  15. //+-------------------------------------------------------------------------
  16. //
  17. // Class: CQueryUnknown
  18. //
  19. // Purpose: Controlling IUnknown for IQuery to manage the simultaneous
  20. // destruction of connected rowsets.
  21. //
  22. // History: 18 Jul 1995 AlanW Created
  23. //
  24. //--------------------------------------------------------------------------
  25. class CQueryUnknown : public IUnknown
  26. {
  27. public:
  28. //
  29. // IUnknown methods.
  30. //
  31. STDMETHOD(QueryInterface) (THIS_ REFIID riid, void ** ppvObj);
  32. STDMETHOD_(ULONG,AddRef) (THIS);
  33. STDMETHOD_(ULONG,Release) (THIS);
  34. //
  35. // Local methods
  36. //
  37. BOOL IsQueryActive( void ) const { return _cRowsets > 0; }
  38. void ReInit( ULONG cRowsets = 0, CRowset ** apRowsets = 0 );
  39. CQueryUnknown( IUnknown & rUnk ) :
  40. _rUnk(rUnk),
  41. _ref(0),
  42. _cRowsets(0),
  43. _apRowsets(0) {}
  44. ~CQueryUnknown();
  45. private:
  46. ULONG _ref;
  47. ULONG _cRowsets;
  48. CRowset ** _apRowsets;
  49. IUnknown & _rUnk;
  50. };
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Class: CRowsetArray
  54. //
  55. // Purpose: Smart container for an array of rowsets.
  56. //
  57. // History: 19 Jul 1995 AlanW Created
  58. //
  59. //--------------------------------------------------------------------------
  60. class CRowsetArray
  61. {
  62. public:
  63. CRowsetArray( ULONG cRowsets ) :
  64. _apRowsets(cRowsets)
  65. {
  66. if (cRowsets > 0)
  67. {
  68. RtlZeroMemory(_apRowsets.GetPointer(), cRowsets * sizeof (CRowset *));
  69. }
  70. }
  71. ~CRowsetArray()
  72. {
  73. if (_apRowsets.GetPointer())
  74. {
  75. for (unsigned i = 0; i < _apRowsets.Count(); i++)
  76. if (_apRowsets[i])
  77. {
  78. delete _apRowsets[i];
  79. _apRowsets[i] = 0;
  80. }
  81. }
  82. }
  83. CRowset * * GetPointer() { return _apRowsets.GetPointer(); }
  84. CRowset * * Acquire() { return _apRowsets.Acquire(); }
  85. CRowset * & operator[](ULONG iElem)
  86. { return _apRowsets[iElem]; }
  87. unsigned Count() const { return _apRowsets.Count(); }
  88. private:
  89. XArray<CRowset *> _apRowsets;
  90. };