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.

137 lines
3.3 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1995-1999 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. // VCUE_Copy.h
  11. //
  12. // This file contains ATL-style copy policy classes
  13. // ATL uses copy policy classes in its enumerator and collection interface implementations
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16. #if !defined(_GENERICCOPY_H___36A49827_B15B_11D2_BA63_00C04F8EC847___INCLUDED_)
  17. #define _GENERICCOPY_H___36A49827_B15B_11D2_BA63_00C04F8EC847___INCLUDED_
  18. #if _MSC_VER >= 1000
  19. #pragma once
  20. #endif // _MSC_VER >= 1000
  21. #include <AtlCom.h>
  22. namespace VCUE
  23. {
  24. template <class DestinationType, class SourceType = DestinationType>
  25. class GenericCopy
  26. {
  27. public :
  28. typedef DestinationType destination_type;
  29. typedef SourceType source_type;
  30. static void init(destination_type* p)
  31. {
  32. _Copy<destination_type>::init(p);
  33. }
  34. static void destroy(destination_type* p)
  35. {
  36. _Copy<destination_type>::destroy(p);
  37. }
  38. static HRESULT copy(destination_type* pTo, const source_type* pFrom)
  39. {
  40. return _Copy<destination_type>::copy(pTo, const_cast<source_type*>(pFrom));
  41. }
  42. }; // class GenericCopy
  43. template <>
  44. class GenericCopy<VARIANT, BSTR>
  45. {
  46. public :
  47. typedef VARIANT destination_type;
  48. typedef BSTR source_type;
  49. static void init(destination_type* p)
  50. {
  51. GenericCopy<destination_type>::init(p);
  52. }
  53. static void destroy(destination_type* p)
  54. {
  55. GenericCopy<destination_type>::destroy(p);
  56. }
  57. static HRESULT copy(destination_type* pTo, const source_type* pFrom)
  58. {
  59. return CComVariant(*pFrom).Detach(pTo);
  60. }
  61. }; // class GenericCopy<VARIANT, BSTR>
  62. template < class SourceType >
  63. class CopyIfc2Variant
  64. {
  65. public :
  66. static void init(VARIANT* p)
  67. {
  68. GenericCopy<VARIANT>::init(p);
  69. }
  70. static void destroy(VARIANT* p)
  71. {
  72. GenericCopy<VARIANT>::destroy(p);
  73. }
  74. static HRESULT copy(VARIANT* pTo, const SourceType* pFrom)
  75. {
  76. return CComVariant(*pFrom).Detach(pTo);
  77. }
  78. }; // class CopyIfc2Variant< SourceType >
  79. template < class TheType >
  80. class CopyIfc
  81. {
  82. public :
  83. static void init(TheType* p)
  84. {
  85. GenericCopy<TheType>::init(p);
  86. }
  87. static void destroy(TheType* p)
  88. {
  89. GenericCopy<TheType>::destroy(p);
  90. }
  91. static HRESULT copy(TheType* pTo, const TheType* pFrom)
  92. {
  93. ((IUnknown *)(* pFrom))->AddRef();
  94. *pTo = *pFrom;
  95. return S_OK;
  96. }
  97. }; // class CopyIfc< TheType >
  98. template <>
  99. class GenericCopy<VARIANT, long>
  100. {
  101. public :
  102. typedef VARIANT destination_type;
  103. typedef long source_type;
  104. static void init(destination_type* p)
  105. {
  106. GenericCopy<destination_type>::init(p);
  107. }
  108. static void destroy(destination_type* p)
  109. {
  110. GenericCopy<destination_type>::destroy(p);
  111. }
  112. static HRESULT copy(destination_type* pTo, const source_type* pFrom)
  113. {
  114. return CComVariant(*pFrom).Detach(pTo);
  115. }
  116. }; // class GenericCopy<VARIANT, long>
  117. }; // namespace VCUE
  118. #endif // !defined(_GENERICCOPY_H___36A49827_B15B_11D2_BA63_00C04F8EC847___INCLUDED_)