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.

280 lines
9.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: mfcstl/shims/access/string/CException.hpp
  3. *
  4. * Purpose: Contains classes and functions for dealing with MFC
  5. * exceptions.
  6. *
  7. * Created: 15th September 2010
  8. * Updated: 15th September 2010
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2010, Matthew Wilson and Synesis Software
  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 the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file mfcstl/shims/access/string/CException.hpp
  41. *
  42. * \brief [C++] Definition of the string access shims for
  43. * <code>CException</code>
  44. * (\ref group__concept__shim__string_access "String Access Shims" Concept).
  45. */
  46. #ifndef MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION
  47. #define MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION_MAJOR 1
  50. # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION_MINOR 0
  51. # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION_REVISION 1
  52. # define MFCSTL_VER_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION_EDIT 90
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef MFCSTL_INCL_MFCSTL_HPP_MFCSTL
  58. # include <mfcstl/mfcstl.hpp>
  59. #endif /* !MFCSTL_INCL_MFCSTL_HPP_MFCSTL */
  60. #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
  61. # include <stlsoft/memory/auto_buffer.hpp>
  62. #endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
  63. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
  64. # include <stlsoft/shims/access/string/fwd.h>
  65. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
  66. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING
  67. # include <stlsoft/string/shim_string.hpp>
  68. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Namespace
  71. */
  72. #ifndef _MFCSTL_NO_NAMESPACE
  73. # if defined(_STLSOFT_NO_NAMESPACE) || \
  74. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  75. /* There is no stlsoft namespace, so must define ::mfcstl */
  76. namespace mfcstl
  77. {
  78. # else
  79. /* Define stlsoft::mfcstl_project */
  80. namespace stlsoft
  81. {
  82. namespace mfcstl_project
  83. {
  84. # endif /* _STLSOFT_NO_NAMESPACE */
  85. #endif /* !_MFCSTL_NO_NAMESPACE */
  86. /* /////////////////////////////////////////////////////////////////////////
  87. * Constants
  88. */
  89. ms_size_t const MFCSTL_EXCEPTION_SAS_CCH = 128;
  90. /* /////////////////////////////////////////////////////////////////////////
  91. * Functions
  92. */
  93. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  94. struct ximpl_CException_sas_util
  95. {
  96. typedef stlsoft_ns_qual(auto_buffer)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> buffer_t;
  97. typedef stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> shim_string_t;
  98. static shim_string_t create_(CException const& x)
  99. {
  100. buffer_t buff(buffer_t::internal_size());
  101. for(; !buff.empty(); buff.resize(1u + 2* buff.size()))
  102. {
  103. buff[buff.size() - 1] = '~';
  104. if(!const_cast<CException&>(x).GetErrorMessage(&buff[0], buff.size(), NULL))
  105. {
  106. }
  107. else if('\0' != buff[buff.size() - 1])
  108. {
  109. break;
  110. }
  111. }
  112. return shim_string_t(buff.data());
  113. }
  114. };
  115. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  116. /* /////////////////////////////////////////////////////////////////////////
  117. * c_str_data
  118. *
  119. * This can be applied to an expression, and the return value is either a
  120. * pointer to the character string or to an empty string.
  121. */
  122. /* CException */
  123. /** \brief \ref group__concept__shim__string_access__c_str_data for CException
  124. *
  125. * \ingroup group__concept__shim__string_access
  126. *
  127. */
  128. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_data(CException const& x)
  129. {
  130. return ximpl_CException_sas_util::create_(x);
  131. }
  132. #if defined(UNICODE)
  133. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_data_w(CException const& x)
  134. #else /* ? UNICODE */
  135. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_data_a(CException const& x)
  136. #endif /* UNICODE */
  137. {
  138. return c_str_data(x);
  139. }
  140. /* /////////////////////////////////////////////////////////////////////////
  141. * c_str_len
  142. *
  143. * This can be applied to an expression, and the return value is the number of
  144. * characters in the character string in the expression.
  145. */
  146. /* CException */
  147. /** \brief \ref group__concept__shim__string_access__c_str_len for CException
  148. *
  149. * \ingroup group__concept__shim__string_access
  150. *
  151. */
  152. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_len(CException const& x)
  153. {
  154. return ximpl_CException_sas_util::create_(x);
  155. }
  156. #if defined(UNICODE)
  157. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_len_w(CException const& x)
  158. #else /* ? UNICODE */
  159. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_len_a(CException const& x)
  160. #endif /* UNICODE */
  161. {
  162. return c_str_len(x);
  163. }
  164. /* /////////////////////////////////////////////////////////////////////////
  165. * c_str_ptr
  166. *
  167. * This can be applied to an expression, and the return value is either a
  168. * pointer to the character string or to an empty string.
  169. */
  170. /* CException */
  171. /** \brief \ref group__concept__shim__string_access__c_str_ptr for CException
  172. *
  173. * \ingroup group__concept__shim__string_access
  174. *
  175. */
  176. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_ptr(CException const& x)
  177. {
  178. return ximpl_CException_sas_util::create_(x);
  179. }
  180. #if defined(UNICODE)
  181. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_ptr_w(CException const& x)
  182. #else /* ? UNICODE */
  183. inline stlsoft_ns_qual(basic_shim_string)<TCHAR, MFCSTL_EXCEPTION_SAS_CCH> c_str_ptr_a(CException const& x)
  184. #endif /* UNICODE */
  185. {
  186. return c_str_ptr(x);
  187. }
  188. /* ////////////////////////////////////////////////////////////////////// */
  189. #ifndef _MFCSTL_NO_NAMESPACE
  190. # if defined(_STLSOFT_NO_NAMESPACE) || \
  191. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  192. } // namespace mfcstl
  193. # else
  194. } // namespace stlsoft::mfcstl_project
  195. } // namespace stlsoft
  196. # endif /* _STLSOFT_NO_NAMESPACE */
  197. #endif /* !_MFCSTL_NO_NAMESPACE */
  198. /* /////////////////////////////////////////////////////////////////////////
  199. * Namespace
  200. *
  201. * The string access shims exist either in the stlsoft namespace, or in the
  202. * global namespace. This is required by the lookup rules.
  203. *
  204. */
  205. #ifndef _MFCSTL_NO_NAMESPACE
  206. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  207. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  208. namespace stlsoft
  209. {
  210. # else /* ? _STLSOFT_NO_NAMESPACE */
  211. /* There is no stlsoft namespace, so must define in the global namespace */
  212. # endif /* !_STLSOFT_NO_NAMESPACE */
  213. using ::mfcstl::c_str_data;
  214. #if defined(UNICODE)
  215. using ::mfcstl::c_str_data_w;
  216. #else /* ? UNICODE */
  217. using ::mfcstl::c_str_data_a;
  218. #endif /* UNICODE */
  219. using ::mfcstl::c_str_len;
  220. #if defined(UNICODE)
  221. using ::mfcstl::c_str_len_w;
  222. #else /* ? UNICODE */
  223. using ::mfcstl::c_str_len_a;
  224. #endif /* UNICODE */
  225. using ::mfcstl::c_str_ptr;
  226. #if defined(UNICODE)
  227. using ::mfcstl::c_str_ptr_w;
  228. #else /* ? UNICODE */
  229. using ::mfcstl::c_str_ptr_a;
  230. #endif /* UNICODE */
  231. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  232. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  233. } // namespace stlsoft
  234. # else /* ? _STLSOFT_NO_NAMESPACE */
  235. /* There is no stlsoft namespace, so must define in the global namespace */
  236. # endif /* !_STLSOFT_NO_NAMESPACE */
  237. #endif /* !_MFCSTL_NO_NAMESPACE */
  238. /* ////////////////////////////////////////////////////////////////////// */
  239. #endif /* !MFCSTL_INCL_MFCSTL_SHIMS_ACCESS_STRING_HPP_CEXCEPTION */
  240. /* ///////////////////////////// end of file //////////////////////////// */