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.

247 lines
7.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: comstl/util/interface_traits.hpp
  3. *
  4. * Purpose: Interface traits.
  5. *
  6. * Created: 25th May 2002
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2002-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file comstl/util/interface_traits.hpp
  40. *
  41. * \brief [C++ only] Definition of the comstl::IID_traits traits class
  42. * (\ref group__library__utility__com "COM Utility" Library).
  43. */
  44. #ifndef COMSTL_INCL_COMSTL_UTIL_HPP_INTERFACE_TRAITS
  45. #define COMSTL_INCL_COMSTL_UTIL_HPP_INTERFACE_TRAITS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define COMSTL_VER_COMSTL_UTIL_HPP_INTERFACE_TRAITS_MAJOR 5
  48. # define COMSTL_VER_COMSTL_UTIL_HPP_INTERFACE_TRAITS_MINOR 0
  49. # define COMSTL_VER_COMSTL_UTIL_HPP_INTERFACE_TRAITS_REVISION 1
  50. # define COMSTL_VER_COMSTL_UTIL_HPP_INTERFACE_TRAITS_EDIT 57
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef COMSTL_INCL_COMSTL_H_COMSTL
  56. # include <comstl/comstl.h>
  57. #endif /* !COMSTL_INCL_COMSTL_H_COMSTL */
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Compiler discrimination
  60. */
  61. #ifdef COMSTL_UUIDOF_SUPPORTED
  62. # undef COMSTL_UUIDOF_SUPPORTED
  63. #endif /* COMSTL_UUIDOF_SUPPORTED */
  64. #if !defined(_COMSTL_NO_UUIDOF) && \
  65. ( defined(STLSOFT_COMPILER_IS_BORLAND) || \
  66. defined(STLSOFT_COMPILER_IS_INTEL) || \
  67. defined(STLSOFT_COMPILER_IS_MWERKS) || \
  68. ( defined(STLSOFT_COMPILER_IS_MSVC) && \
  69. _MSC_VER >= 1200))
  70. # define COMSTL_UUIDOF_SUPPORTED
  71. #endif /* compiler */
  72. /* /////////////////////////////////////////////////////////////////////////
  73. * Namespace
  74. */
  75. #ifndef _COMSTL_NO_NAMESPACE
  76. # if defined(_STLSOFT_NO_NAMESPACE) || \
  77. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  78. /* There is no stlsoft namespace, so must define ::comstl */
  79. namespace comstl
  80. {
  81. # else
  82. /* Define stlsoft::comstl_project */
  83. namespace stlsoft
  84. {
  85. namespace comstl_project
  86. {
  87. # endif /* _STLSOFT_NO_NAMESPACE */
  88. #endif /* !_COMSTL_NO_NAMESPACE */
  89. /* /////////////////////////////////////////////////////////////////////////
  90. * Macros
  91. */
  92. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  93. # define COMSTL_IID_TRAITS_DEFINE__(I, T) \
  94. STLSOFT_TEMPLATE_SPECIALISATION \
  95. struct IID_traits<T> \
  96. { \
  97. public: \
  98. static REFIID iid() { return IID_##I; } \
  99. };
  100. # define COMSTL_IID_TRAITS_DEFINE_NS_(I, T, NS) \
  101. STLSOFT_TEMPLATE_SPECIALISATION \
  102. struct IID_traits<NS::T> \
  103. { \
  104. public: \
  105. static REFIID iid() { return NS::IID_##I; } \
  106. };
  107. # define _COMSTL_IID_TRAITS_DEFINE(I) COMSTL_IID_TRAITS_DEFINE__(I, I)
  108. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  109. /* /////////////////////////////////////////////////////////////////////////
  110. * Classes
  111. */
  112. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  113. /** \brief Interface identifier traits
  114. *
  115. * \ingroup group__library__utility__com
  116. *
  117. * This traits class takes an interface type and provides a specialisation that
  118. * has a statid iid() method which returns the interface identifier (IID) for
  119. * that type.
  120. *
  121. * To use, simply have the expression IID_traits<I>::iid() where I is your
  122. * interface type.
  123. *
  124. * On compilers that support the __uuidof pseudo-operator this is used,
  125. * otherwise you must specify specialisations - using the
  126. * COMSTL_IID_TRAITS_DEFINE macro - for your interfaces, as in
  127. *
  128. * COMSTL_IID_TRAITS_DEFINE(IMyInterface)
  129. *
  130. * All the interfaces currently defined in unknown.idl and objidl.idl are
  131. * so defined in the file comstl_interface_traits_std.h, which is included in
  132. * for non-__uuidof compilations.
  133. *
  134. * \param I The interface
  135. */
  136. template <class I>
  137. struct IID_traits
  138. {
  139. public:
  140. /// Returns a reference to the IID for the parameterising interface
  141. static REFIID iid();
  142. };
  143. #else /* ? STLSOFT_DOCUMENTATION_SKIP_SECTION */
  144. # ifdef COMSTL_UUIDOF_SUPPORTED
  145. template <class I>
  146. struct IID_traits
  147. {
  148. public:
  149. static REFIID iid() { return __uuidof(I); }
  150. };
  151. # define COMSTL_IID_TRAITS_DEFINE(I)
  152. # define COMSTL_IID_TRAITS_DEFINE_NS(I, NS)
  153. # else /* ? COMSTL_UUIDOF_SUPPORTED */
  154. template <class I>
  155. struct IID_traits;
  156. # define COMSTL_IID_TRAITS_DEFINE(I) EXTERN_C const IID IID_##I; \
  157. _COMSTL_IID_TRAITS_DEFINE(I) \
  158. COMSTL_IID_TRAITS_DEFINE__(I, I*)
  159. # define COMSTL_IID_TRAITS_DEFINE_NS(I, NS) COMSTL_IID_TRAITS_DEFINE_NS_(I, I, NS) \
  160. COMSTL_IID_TRAITS_DEFINE_NS_(I, I*, NS)
  161. /* For backwards compatibility */
  162. # define comstl_IID_traits_define(I) COMSTL_IID_TRAITS_DEFINE(I)
  163. # endif /* COMSTL_UUIDOF_SUPPORTED */
  164. #ifndef _COMSTL_NO_NAMESPACE
  165. # if defined(_STLSOFT_NO_NAMESPACE) || \
  166. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  167. } // namespace comstl
  168. # else
  169. } // namespace comstl_project
  170. } // namespace stlsoft
  171. # endif /* _STLSOFT_NO_NAMESPACE */
  172. #endif /* !_COMSTL_NO_NAMESPACE */
  173. #ifndef COMSTL_INCL_COMSTL_INTERNAL_HPP_INTERFACE_TRAITS_STD
  174. # include <comstl/internal/interface_traits_std.hpp>
  175. #endif /* !COMSTL_INCL_COMSTL_INTERNAL_HPP_INTERFACE_TRAITS_STD */
  176. #ifndef _COMSTL_NO_NAMESPACE
  177. # if defined(_STLSOFT_NO_NAMESPACE) || \
  178. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  179. /* There is no stlsoft namespace, so must define ::comstl */
  180. namespace comstl
  181. {
  182. # else
  183. /* Define stlsoft::comstl_project */
  184. namespace stlsoft
  185. {
  186. namespace comstl_project
  187. {
  188. # endif /* _STLSOFT_NO_NAMESPACE */
  189. #endif /* !_COMSTL_NO_NAMESPACE */
  190. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  191. /* ////////////////////////////////////////////////////////////////////// */
  192. #ifndef _COMSTL_NO_NAMESPACE
  193. # if defined(_STLSOFT_NO_NAMESPACE) || \
  194. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  195. } // namespace comstl
  196. # else
  197. } // namespace comstl_project
  198. } // namespace stlsoft
  199. # endif /* _STLSOFT_NO_NAMESPACE */
  200. #endif /* !_COMSTL_NO_NAMESPACE */
  201. /* ////////////////////////////////////////////////////////////////////// */
  202. #endif /* !COMSTL_INCL_COMSTL_UTIL_HPP_INTERFACE_TRAITS */
  203. /* ///////////////////////////// end of file //////////////////////////// */