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.

186 lines
6.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: comstl/functional/interface_functionals.hpp
  3. *
  4. * Purpose: Interface-specific predicates and functions.
  5. *
  6. * Created: 14th June 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/functional/interface_functionals.hpp
  40. *
  41. * \brief [C++ only] Function classes for manipulating interfaces pointers
  42. * (\ref group__library__functional "Functional" Library).
  43. */
  44. #ifndef COMSTL_INCL_COMSTL_FUNCTIONAL_HPP_INTERFACE_FUNCTIONALS
  45. #define COMSTL_INCL_COMSTL_FUNCTIONAL_HPP_INTERFACE_FUNCTIONALS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define COMSTL_VER_HPP_INTERFACE_FUNCTIONALS_MAJOR 4
  48. # define COMSTL_VER_HPP_INTERFACE_FUNCTIONALS_MINOR 0
  49. # define COMSTL_VER_HPP_INTERFACE_FUNCTIONALS_REVISION 2
  50. # define COMSTL_VER_HPP_INTERFACE_FUNCTIONALS_EDIT 67
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Auto-generation and compatibility
  54. */
  55. /*
  56. [Incompatibilies-start]
  57. [Incompatibilies-end]
  58. STLSOFT_COMPILER_IS_GCC: __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
  59. */
  60. /* /////////////////////////////////////////////////////////////////////////
  61. * Includes
  62. */
  63. #ifndef COMSTL_INCL_COMSTL_H_COMSTL
  64. # include <comstl/comstl.h>
  65. #endif /* !COMSTL_INCL_COMSTL_H_COMSTL */
  66. #ifndef COMSTL_INCL_COMSTL_UTIL_H_REFCOUNT_FUNCTIONS
  67. # include <comstl/util/refcount_functions.h>
  68. #endif /* !COMSTL_INCL_COMSTL_UTIL_H_REFCOUNT_FUNCTIONS */
  69. #ifndef STLSOFT_INCL_FUNCTIONAL
  70. # define STLSOFT_INCL_FUNCTIONAL
  71. # include <functional>
  72. #endif /* !STLSOFT_INCL_FUNCTIONAL */
  73. /* /////////////////////////////////////////////////////////////////////////
  74. * Namespace
  75. */
  76. #ifndef _COMSTL_NO_NAMESPACE
  77. # if defined(_STLSOFT_NO_NAMESPACE) || \
  78. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  79. /* There is no stlsoft namespace, so must define ::comstl */
  80. namespace comstl
  81. {
  82. # else
  83. /* Define stlsoft::comstl_project */
  84. namespace stlsoft
  85. {
  86. namespace comstl_project
  87. {
  88. # endif /* _STLSOFT_NO_NAMESPACE */
  89. #endif /* !_COMSTL_NO_NAMESPACE */
  90. /* /////////////////////////////////////////////////////////////////////////
  91. * Functionals
  92. */
  93. /** \brief A function class that releases COM interfaces
  94. *
  95. * \ingroup group__library__functional
  96. *
  97. * This function class releases COM interfaces by calling Release()
  98. * on them. Note that the function class benignly ignores null interface
  99. * pointers.
  100. *
  101. * \param I The COM interface on which to parameterise the template
  102. */
  103. template <ss_typename_param_k I>
  104. // [[synesis:class:unary-functor: interface_release]]
  105. struct interface_release
  106. : public comstl_ns_qual_std(unary_function)<I*, void>
  107. {
  108. public:
  109. typedef I interface_type;
  110. /// \brief Function call operator
  111. ///
  112. /// \param pi The interface pointer to release
  113. void operator ()(interface_type *pi)
  114. {
  115. safe_release(pi);
  116. }
  117. };
  118. /** \brief A function class that adds references to COM interfaces
  119. *
  120. * \ingroup group__library__functional
  121. *
  122. * This function class adds a reference to COM interfaces by calling AddRef()
  123. * on them. Note that the function class benignly ignores null interface
  124. * pointers.
  125. *
  126. * \param I The COM interface on which to parameterise the template
  127. */
  128. template <ss_typename_param_k I>
  129. // [[synesis:class:unary-functor: interface_addref]]
  130. struct interface_addref
  131. : public comstl_ns_qual_std(unary_function)<I*, void>
  132. {
  133. public:
  134. typedef I interface_type;
  135. /// \brief Function call operator
  136. ///
  137. /// \param pi The interface pointer on which to add a reference
  138. void operator ()(interface_type *pi)
  139. {
  140. safe_addref(pi);
  141. }
  142. };
  143. ////////////////////////////////////////////////////////////////////////////
  144. // Unit-testing
  145. #ifdef STLSOFT_UNITTEST
  146. # include "./unittest/interface_functionals_unittest_.h"
  147. #endif /* STLSOFT_UNITTEST */
  148. /* ////////////////////////////////////////////////////////////////////// */
  149. #ifndef _COMSTL_NO_NAMESPACE
  150. # if defined(_STLSOFT_NO_NAMESPACE) || \
  151. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  152. } // namespace comstl
  153. # else
  154. } // namespace comstl_project
  155. } // namespace stlsoft
  156. # endif /* _STLSOFT_NO_NAMESPACE */
  157. #endif /* !_COMSTL_NO_NAMESPACE */
  158. /* ////////////////////////////////////////////////////////////////////// */
  159. #endif /* !COMSTL_INCL_COMSTL_FUNCTIONAL_HPP_INTERFACE_FUNCTIONALS */
  160. /* ///////////////////////////// end of file //////////////////////////// */