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.

73 lines
1.6 KiB

  1. #ifndef __ENUMERATORTEMPLATES_H__
  2. #define __ENUMERATORTEMPLATES_H__
  3. template <class TIMPL, class TELT>
  4. class CEnumAny : public TIMPL
  5. {
  6. public:
  7. CEnumAny() : _cRef(1), _cNext(0) {}
  8. virtual ~CEnumAny() {}
  9. // IUnknown methods
  10. // STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  11. STDMETHODIMP_(ULONG) AddRef()
  12. {
  13. return ++_cRef;
  14. }
  15. STDMETHODIMP_(ULONG) Release()
  16. {
  17. if (--_cRef > 0)
  18. return _cRef;
  19. delete this;
  20. return 0;
  21. }
  22. // IEnumXXXX methods
  23. STDMETHODIMP Next(ULONG celt, TELT *rgelt, ULONG *pcelt)
  24. {
  25. UINT cNum = 0;
  26. ZeroMemory(rgelt, sizeof(rgelt[0])*celt);
  27. while (cNum < celt
  28. && _Next(&rgelt[cNum]))
  29. {
  30. _cNext++;
  31. cNum++;
  32. }
  33. if (pcelt)
  34. *pcelt = cNum;
  35. return (celt == cNum) ? S_OK: S_FALSE;
  36. }
  37. STDMETHODIMP Skip(ULONG celt)
  38. { return E_NOTIMPL; }
  39. STDMETHODIMP Reset()
  40. { return E_NOTIMPL; }
  41. STDMETHODIMP Clone(TIMPL **ppenum)
  42. { return E_NOTIMPL; }
  43. protected:
  44. virtual BOOL _Next(TELT *pelt) = 0;
  45. protected:
  46. LONG _cRef;
  47. ULONG _cNext;
  48. };
  49. class CEnumAssociationElements : public CEnumAny<IEnumAssociationElements, IAssociationElement *>
  50. {
  51. public:
  52. STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
  53. {
  54. static const QITAB qit[] = {
  55. QITABENT(CEnumAssociationElements, IEnumAssociationElements),
  56. { 0 }
  57. };
  58. return QISearch(this, qit, riid, ppv);
  59. }
  60. };
  61. #endif // __ENUMERATORTEMPLATES_H__