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.

132 lines
2.5 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: NMTempl.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12/11/1996 RaviR Created
  15. //____________________________________________________________________________
  16. //
  17. #ifndef NMTEMPL_H
  18. #define NMTEMPL_H
  19. //____________________________________________________________________________
  20. //
  21. // Template: XMapIterator
  22. //____________________________________________________________________________
  23. //
  24. template<typename _MAP, typename _KEY, typename _VALUE> class XMapIterator
  25. {
  26. public:
  27. typedef _MAP MAP;
  28. typedef _KEY KEY;
  29. typedef _VALUE VALUE;
  30. // Constructor
  31. inline XMapIterator(MAP& map) : m_map(map), m_pos(NULL), m_bEnd(FALSE)
  32. {
  33. Reset();
  34. }
  35. // Attributes
  36. inline BOOL IsEnd()
  37. {
  38. return m_bEnd;
  39. }
  40. inline operator VALUE ()
  41. {
  42. return m_value;
  43. }
  44. inline KEY& GetKey(void)
  45. {
  46. return m_key;
  47. }
  48. inline VALUE& GetValue(void)
  49. {
  50. return m_value;
  51. }
  52. // Operations
  53. inline void Reset()
  54. {
  55. m_bEnd = FALSE;
  56. m_pos = m_map.GetStartPosition();
  57. if (m_pos)
  58. m_map.GetNextAssoc(m_pos, m_key, m_value);
  59. else
  60. m_bEnd = TRUE;
  61. }
  62. inline void Advance()
  63. {
  64. ASSERT(IsEnd() == FALSE);
  65. if (m_pos)
  66. m_map.GetNextAssoc(m_pos, m_key, m_value);
  67. else
  68. m_bEnd = TRUE;
  69. }
  70. // Implementation
  71. private:
  72. VALUE m_value;
  73. KEY m_key;
  74. MAP& m_map;
  75. POSITION m_pos;
  76. BOOL m_bEnd;
  77. };
  78. HRESULT
  79. DataObject_GetHGLOBALData(
  80. IDataObject* piDataObject,
  81. CLIPFORMAT cfClipFormat,
  82. HGLOBAL* phGlobal);
  83. template <typename DATATYPE>
  84. HRESULT ExtractData(IDataObject* pDO, CLIPFORMAT cf, DATATYPE* pDATATYPE)
  85. {
  86. ASSERT(pDO != NULL);
  87. ASSERT(pDATATYPE!= NULL);
  88. if (pDO == NULL || pDATATYPE == NULL)
  89. return E_POINTER;
  90. HGLOBAL hGlobal = NULL;
  91. HRESULT hr = DataObject_GetHGLOBALData(pDO, cf, &hGlobal);
  92. if (FAILED(hr))
  93. return hr;
  94. DATATYPE* pdata = reinterpret_cast<DATATYPE*>(::GlobalLock(hGlobal));
  95. ASSERT(pdata != NULL);
  96. *pDATATYPE = *pdata;
  97. ::GlobalUnlock(hGlobal);
  98. ::GlobalFree(hGlobal);
  99. return S_OK;
  100. }
  101. #endif // NMTEMPL_H