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.

234 lines
7.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/error/throw_policies.hpp
  3. *
  4. * Purpose: Exception throwing policy classes.
  5. *
  6. * Created: 19th January 2002
  7. * Updated: 5th March 2011
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2002-2011, Matthew Wilson and Synesis Software
  12. * Copyright (c) 2006, Pablo Aguilar
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software, nor Pablo
  24. * Aguilar, nor the names of any contributors may be used to endorse or
  25. * promote products derived from this software without specific prior written
  26. * permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file stlsoft/error/throw_policies.hpp
  42. *
  43. * \brief [C++ only] Definition of the stlsoft::nothrow_exception_policy and
  44. * stlsoft::throw_exception_policy exception policy classes
  45. * (\ref group__library__error "Error" Library).
  46. */
  47. #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_THROW_POLICIES
  48. #define STLSOFT_INCL_STLSOFT_ERROR_HPP_THROW_POLICIES
  49. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  50. # define STLSOFT_VER_STLSOFT_ERROR_HPP_THROW_POLICIES_MAJOR 5
  51. # define STLSOFT_VER_STLSOFT_ERROR_HPP_THROW_POLICIES_MINOR 0
  52. # define STLSOFT_VER_STLSOFT_ERROR_HPP_THROW_POLICIES_REVISION 2
  53. # define STLSOFT_VER_STLSOFT_ERROR_HPP_THROW_POLICIES_EDIT 51
  54. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Compatibility
  57. */
  58. /*
  59. [DocumentationStatus:Ready]
  60. */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Includes
  63. */
  64. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  65. # include <stlsoft/stlsoft.h>
  66. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  67. #ifndef STLSOFT_INCL_EXCEPTION
  68. # define STLSOFT_INCL_EXCEPTION
  69. # include <exception>
  70. #endif /* !STLSOFT_INCL_EXCEPTION */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Namespace
  73. */
  74. #ifndef _STLSOFT_NO_NAMESPACE
  75. namespace stlsoft
  76. {
  77. #endif /* _STLSOFT_NO_NAMESPACE */
  78. /* /////////////////////////////////////////////////////////////////////////
  79. * Classes
  80. */
  81. /** \brief The no-throwing exception policy. It does not throw, and its throw type is empty.
  82. *
  83. * \ingroup group__library__error
  84. *
  85. */
  86. // [[synesis:class:exception-policy: null_exception_policy]]
  87. struct null_exception_policy
  88. {
  89. /// \name Member Types
  90. /// @{
  91. public:
  92. /// The thrown type
  93. struct thrown_type
  94. {
  95. };
  96. /// @}
  97. /// \name Operators
  98. /// @{
  99. public:
  100. /// Function call operator, taking no parameters
  101. void operator ()() const
  102. {}
  103. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  104. /// Function call operator, taking one parameter
  105. template <ss_typename_param_k T>
  106. void operator ()(T const& /* t */) const stlsoft_throw_0()
  107. {
  108. // Do nothing
  109. }
  110. /// Function call operator, taking two parameters
  111. template< ss_typename_param_k T1
  112. , ss_typename_param_k T2
  113. >
  114. void operator ()(T1 const& /* t1 */, T2 const& /* t2 */) const stlsoft_throw_0()
  115. {
  116. // Do nothing
  117. }
  118. /// Function call operator, taking three parameters
  119. template< ss_typename_param_k T1
  120. , ss_typename_param_k T2
  121. , ss_typename_param_k T3
  122. >
  123. void operator ()(T1 const& /* t1 */, T2 const& /* t2 */, T3 const& /* t3 */) const stlsoft_throw_0()
  124. {
  125. // Do nothing
  126. }
  127. /// Function call operator, taking four parameters
  128. template< ss_typename_param_k T1
  129. , ss_typename_param_k T2
  130. , ss_typename_param_k T3
  131. , ss_typename_param_k T4
  132. >
  133. void operator ()(T1 const& /* t1 */, T2 const& /* t2 */, T3 const& /* t3 */, T4 const& /* t4 */) const stlsoft_throw_0()
  134. {
  135. // Do nothing
  136. }
  137. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  138. /// @}
  139. };
  140. /** \brief Alternative typedef for null_exception_policy
  141. *
  142. * \ingroup group__library__error
  143. *
  144. */
  145. typedef null_exception_policy nothrow_exception_policy;
  146. /** \brief The throwing exception policy. It throws instances of its parameterising type.
  147. *
  148. * \ingroup group__library__error
  149. *
  150. */
  151. template<ss_typename_param_k E>
  152. // [[synesis:class:exception-policy: throw_exception_policy]]
  153. struct throw_exception_policy
  154. {
  155. /// \name Member Types
  156. /// @{
  157. public:
  158. /// The thrown type
  159. typedef E thrown_type;
  160. /// @}
  161. /// \name Operators
  162. /// @{
  163. public:
  164. /// Function call operator, taking no parameters
  165. void operator ()() const
  166. {
  167. STLSOFT_THROW_X(thrown_type());
  168. }
  169. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  170. /// Function call operator, taking one parameter
  171. template <ss_typename_param_k T>
  172. void operator ()(T const& t) const
  173. {
  174. STLSOFT_THROW_X(thrown_type(t));
  175. }
  176. /// Function call operator, taking two parameters
  177. template<ss_typename_param_k T1, ss_typename_param_k T2>
  178. void operator ()(T1 const& t1, T2 const& t2) const
  179. {
  180. STLSOFT_THROW_X(thrown_type(t1, t2));
  181. }
  182. /// Function call operator, taking three parameters
  183. template<ss_typename_param_k T1, ss_typename_param_k T2, ss_typename_param_k T3>
  184. void operator ()(T1 const& t1, T2 const& t2, T3 const& t3) const
  185. {
  186. STLSOFT_THROW_X(thrown_type(t1, t2, t3));
  187. }
  188. /// Function call operator, taking four parameters
  189. template<ss_typename_param_k T1, ss_typename_param_k T2, ss_typename_param_k T3, ss_typename_param_k T4>
  190. void operator ()(T1 const& t1, T2 const& t2, T3 const& t3, T4 const& t4) const
  191. {
  192. STLSOFT_THROW_X(thrown_type(t1, t2, t3, t4));
  193. }
  194. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  195. /// @}
  196. };
  197. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  198. # ifdef _STLSOFT_INCLUDE_OBSOLETE
  199. typedef null_exception_policy null_exception;
  200. typedef null_exception_policy nothrow_exception;
  201. # endif /* _STLSOFT_INCLUDE_OBSOLETE */
  202. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  203. /* ////////////////////////////////////////////////////////////////////// */
  204. #ifndef _STLSOFT_NO_NAMESPACE
  205. } // namespace stlsoft
  206. #endif /* _STLSOFT_NO_NAMESPACE */
  207. /* ////////////////////////////////////////////////////////////////////// */
  208. #endif /* !STLSOFT_INCL_STLSOFT_ERROR_HPP_THROW_POLICIES */
  209. /* ///////////////////////////// end of file //////////////////////////// */