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.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: rangelib/error/exceptions.hpp
  3. *
  4. * Purpose: Range exceptions.
  5. *
  6. * Created: 30th December 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-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 rangelib/error/exceptions.hpp
  40. *
  41. * \brief [C++ only] Definition of the rangelib::range_exception and
  42. * rangelib::empty_range_exception exception classes.
  43. *
  44. * (\ref group__library__error "Error" Library).
  45. */
  46. #ifndef RANGELIB_INCL_RANGELIB_ERROR_HPP_EXCEPTIONS
  47. #define RANGELIB_INCL_RANGELIB_ERROR_HPP_EXCEPTIONS
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define RANGELIB_VER_RANGELIB_ERROR_HPP_EXCEPTIONS_MAJOR 2
  50. # define RANGELIB_VER_RANGELIB_ERROR_HPP_EXCEPTIONS_MINOR 0
  51. # define RANGELIB_VER_RANGELIB_ERROR_HPP_EXCEPTIONS_REVISION 2
  52. # define RANGELIB_VER_RANGELIB_ERROR_HPP_EXCEPTIONS_EDIT 17
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Auto-generation and compatibility
  56. */
  57. /*
  58. [Incompatibilies-start]
  59. [Incompatibilies-end]
  60. [DocumentationStatus:Ready]
  61. */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Includes
  64. */
  65. #ifndef RANGELIB_INCL_RANGELIB_HPP_RANGELIB
  66. # include <rangelib/rangelib.hpp>
  67. #endif /* !RANGELIB_INCL_RANGELIB_HPP_RANGELIB */
  68. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_EXCEPTION_STRING
  69. # include <stlsoft/util/exception_string.hpp>
  70. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_EXCEPTION_STRING */
  71. #ifndef STLSOFT_INCL_STDEXCEPT
  72. # define STLSOFT_INCL_STDEXCEPT
  73. # include <stdexcept>
  74. #endif /* !STLSOFT_INCL_STDEXCEPT */
  75. #ifdef STLSOFT_UNITEST
  76. # include <string.h>
  77. #endif /* STLSOFT_UNITEST */
  78. /* /////////////////////////////////////////////////////////////////////////
  79. * Namespace
  80. */
  81. #ifndef RANGELIB_NO_NAMESPACE
  82. # if defined(_STLSOFT_NO_NAMESPACE) || \
  83. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  84. /* There is no stlsoft namespace, so must define ::rangelib */
  85. namespace rangelib
  86. {
  87. # else
  88. /* Define stlsoft::rangelib_project */
  89. namespace stlsoft
  90. {
  91. namespace rangelib_project
  92. {
  93. # endif /* _STLSOFT_NO_NAMESPACE */
  94. #endif /* !RANGELIB_NO_NAMESPACE */
  95. /* /////////////////////////////////////////////////////////////////////////
  96. * Classes
  97. */
  98. /** \brief General exception class for RangeLib failures.
  99. *
  100. * \ingroup group__library__error
  101. *
  102. */
  103. class range_exception
  104. #if defined(STLSOFT_COMPILER_IS_DMC)
  105. : public std::exception
  106. #else /* ? compiler */
  107. : public stlsoft_ns_qual_std(exception)
  108. #endif /* compiler */
  109. {
  110. /// \name Types
  111. /// @{
  112. private:
  113. typedef stlsoft_ns_qual(exception_string) string_type;
  114. public:
  115. typedef range_exception class_type;
  116. #if defined(STLSOFT_COMPILER_IS_DMC)
  117. typedef std::exception parent_class_type;
  118. #else /* ? compiler */
  119. typedef stlsoft_ns_qual_std(exception) parent_class_type;
  120. #endif /* compiler */
  121. /// @}
  122. /// \name Construction
  123. /// @{
  124. public:
  125. ss_explicit_k range_exception(char const* reason = NULL)
  126. : m_reason((NULL == reason) ? "" : reason)
  127. {}
  128. /// Destructor
  129. ///
  130. /// \note This does not do have any implementation, but is required to placate
  131. /// the Comeau and GCC compilers, which otherwise complain about mismatched
  132. /// exception specifications between this class and its parent
  133. virtual ~range_exception() stlsoft_throw_0()
  134. {}
  135. /// @}
  136. /// \name Accessors
  137. /// @{
  138. public:
  139. virtual char const* what() const stlsoft_throw_0()
  140. {
  141. return m_reason.empty() ? this->real_what_() : m_reason.c_str();
  142. }
  143. /// @}
  144. /// \name Implementation
  145. /// @{
  146. private:
  147. virtual char const* real_what_() const throw()
  148. {
  149. return "Range exception";
  150. }
  151. /// @}
  152. /// \name Members
  153. /// @{
  154. private:
  155. const string_type m_reason;
  156. /// @}
  157. /// \name Not to be implemented
  158. /// @{
  159. private:
  160. class_type& operator =(class_type const&);
  161. /// @}
  162. };
  163. /** \brief Indicates that an operation requiring non-empty range was invoked
  164. * on an empty range.
  165. *
  166. * \ingroup group__library__error
  167. *
  168. */
  169. class empty_range_exception
  170. : public range_exception
  171. {
  172. public:
  173. typedef range_exception parent_class_type;
  174. typedef empty_range_exception class_type;
  175. /// \name Construction
  176. /// @{
  177. public:
  178. ss_explicit_k empty_range_exception(char const* reason = NULL)
  179. : parent_class_type(reason)
  180. {}
  181. /// Destructor
  182. ///
  183. /// \note This does not do have any implementation, but is required to placate
  184. /// the Comeau and GCC compilers, which otherwise complain about mismatched
  185. /// exception specifications between this class and its parent
  186. virtual ~empty_range_exception() stlsoft_throw_0()
  187. {}
  188. /// @}
  189. /// \name Implementation
  190. /// @{
  191. private:
  192. virtual char const* real_what_() const throw()
  193. {
  194. return "Range was empty";
  195. }
  196. /// @}
  197. };
  198. ////////////////////////////////////////////////////////////////////////////
  199. // Unit-testing
  200. #ifdef STLSOFT_UNITTEST
  201. # include "./unittest/exceptions_unittest_.h"
  202. #endif /* STLSOFT_UNITTEST */
  203. /* ////////////////////////////////////////////////////////////////////// */
  204. #ifndef RANGELIB_NO_NAMESPACE
  205. # if defined(_STLSOFT_NO_NAMESPACE) || \
  206. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  207. } // namespace rangelib
  208. # else
  209. } // namespace rangelib_project
  210. } // namespace stlsoft
  211. # endif /* _STLSOFT_NO_NAMESPACE */
  212. #endif /* !RANGELIB_NO_NAMESPACE */
  213. /* ////////////////////////////////////////////////////////////////////// */
  214. #endif /* !RANGELIB_INCL_RANGELIB_ERROR_HPP_EXCEPTIONS */
  215. /* ///////////////////////////// end of file //////////////////////////// */