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.

160 lines
5.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: atlstl/util/module_scope.hpp
  3. *
  4. * Purpose: Scoping class for ATL _Module
  5. *
  6. * Created: 8th December 2004
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2004-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 atlstl/util/module_scope.hpp
  40. *
  41. * \brief [C++ only] Definition of the atlstl::module_scope class template
  42. * (\ref group__library__utility "Utility" Library).
  43. */
  44. #ifndef ATLSTL_INCL_ATLSTL_UTIL_HPP_MODULE_SCOPE
  45. #define ATLSTL_INCL_ATLSTL_UTIL_HPP_MODULE_SCOPE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define ATLSTL_VER_ATLSTL_UTIL_HPP_MODULE_SCOPE_MAJOR 2
  48. # define ATLSTL_VER_ATLSTL_UTIL_HPP_MODULE_SCOPE_MINOR 1
  49. # define ATLSTL_VER_ATLSTL_UTIL_HPP_MODULE_SCOPE_REVISION 1
  50. # define ATLSTL_VER_ATLSTL_UTIL_HPP_MODULE_SCOPE_EDIT 26
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef ATLSTL_INCL_ATLSTL_HPP_ATLSTL
  56. # include <atlstl/atlstl.hpp>
  57. #endif /* !ATLSTL_INCL_ATLSTL_HPP_ATLSTL */
  58. #ifndef STLSOFT_INCL_STLSOFT_HPP_ERROR_EXCEPTIONS
  59. # include <stlsoft/error/exceptions.hpp>
  60. #endif /* !STLSOFT_INCL_STLSOFT_HPP_ERROR_EXCEPTIONS */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _ATLSTL_NO_NAMESPACE
  65. # if defined(_STLSOFT_NO_NAMESPACE) || \
  66. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  67. /* There is no stlsoft namespace, so must define ::atlstl */
  68. namespace atlstl
  69. {
  70. # else
  71. /* Define stlsoft::atlstl_project */
  72. namespace stlsoft
  73. {
  74. namespace atlstl_project
  75. {
  76. # endif /* _STLSOFT_NO_NAMESPACE */
  77. #endif /* !_ATLSTL_NO_NAMESPACE */
  78. /* /////////////////////////////////////////////////////////////////////////
  79. * Classes
  80. */
  81. /** \brief Scopes the initialisation and uninitialisation of an ATL module
  82. *
  83. * \ingroup group__library__utility
  84. */
  85. // [[synesis:class:raii: atlstl::module_scope<T<M>, T<X>>]]
  86. template< ss_typename_param_k M
  87. , ss_typename_param_k X = stlsoft_ns_qual(null_exception_policy)
  88. >
  89. class module_scope
  90. {
  91. public:
  92. typedef M module_type;
  93. typedef X exception_policy_type;
  94. typedef module_scope<M, X> class_type;
  95. /// \name Construction
  96. /// @{
  97. public:
  98. module_scope(module_type &m, ATL::_ATL_OBJMAP_ENTRY *pObjMap, HINSTANCE hinst, GUID const* pLibID = NULL)
  99. : m_m(m)
  100. , m_hr(m.Init(pObjMap, hinst, pLibID))
  101. {
  102. if(FAILED(m_hr))
  103. {
  104. exception_policy_type xp;
  105. xp(m_hr);
  106. }
  107. }
  108. ~module_scope() stlsoft_throw_0()
  109. {
  110. m_m.Term();
  111. }
  112. /// @}
  113. /// \name Attributes
  114. /// @{
  115. public:
  116. HRESULT hr() const throw()
  117. {
  118. return m_hr;
  119. }
  120. /// @}
  121. // Members
  122. private:
  123. M &m_m;
  124. const HRESULT m_hr;
  125. };
  126. /* ////////////////////////////////////////////////////////////////////// */
  127. #ifndef _ATLSTL_NO_NAMESPACE
  128. # if defined(_STLSOFT_NO_NAMESPACE) || \
  129. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  130. } // namespace atlstl
  131. # else
  132. } // namespace atlstl_project
  133. } // namespace stlsoft
  134. # endif /* _STLSOFT_NO_NAMESPACE */
  135. #endif /* !_ATLSTL_NO_NAMESPACE */
  136. /* ////////////////////////////////////////////////////////////////////// */
  137. #endif /* !ATLSTL_INCL_ATLSTL_UTIL_HPP_MODULE_SCOPE */
  138. /* ///////////////////////////// end of file //////////////////////////// */