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.

261 lines
8.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: atlstl/shims/access/string/ccombstr.hpp
  3. *
  4. * Purpose: Contains classes and functions for dealing with OLE/COM strings.
  5. *
  6. * Created: 27th May 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 atlstl/shims/access/string/ccombstr.hpp
  40. *
  41. * \brief [C++] Definition of the string access shims for
  42. * <code>CComBSTR</code>
  43. * (\ref group__concept__shim__string_access "String Access Shims" Concept).
  44. */
  45. #ifndef ATLSTL_INCL_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR
  46. #define ATLSTL_INCL_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define ATLSTL_VER_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR_MAJOR 4
  49. # define ATLSTL_VER_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR_MINOR 0
  50. # define ATLSTL_VER_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR_REVISION 1
  51. # define ATLSTL_VER_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR_EDIT 97
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef ATLSTL_INCL_ATLSTL_HPP_ATLSTL
  57. # include <atlstl/atlstl.hpp>
  58. #endif /* !ATLSTL_INCL_ATLSTL_HPP_ATLSTL */
  59. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  60. # include <stlsoft/shims/access/string.hpp>
  61. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  62. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CSTRING_MAKER
  63. # include <stlsoft/string/cstring_maker.hpp>
  64. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_CSTRING_MAKER */
  65. #ifdef STLSOFT_UNITTEST
  66. # include <wchar.h>
  67. #endif /* STLSOFT_UNITTEST */
  68. /* /////////////////////////////////////////////////////////////////////////
  69. * Namespace
  70. */
  71. #ifndef _ATLSTL_NO_NAMESPACE
  72. # if defined(_STLSOFT_NO_NAMESPACE) || \
  73. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  74. /* There is no stlsoft namespace, so must define ::atlstl */
  75. namespace atlstl
  76. {
  77. # else
  78. /* Define stlsoft::atlstl_project */
  79. namespace stlsoft
  80. {
  81. namespace atlstl_project
  82. {
  83. # endif /* _STLSOFT_NO_NAMESPACE */
  84. #endif /* !_ATLSTL_NO_NAMESPACE */
  85. /* /////////////////////////////////////////////////////////////////////////
  86. * c_str_data
  87. *
  88. * This can be applied to an expression, and the return value is either a
  89. * pointer to the character string or to an empty string.
  90. */
  91. /** \brief \ref group__concept__shim__string_access__c_str_data for CComBSTR
  92. *
  93. * \ingroup group__concept__shim__string_access
  94. *
  95. */
  96. inline LPCOLESTR c_str_data(atlstl_ns_qual_atl(CComBSTR) const& s)
  97. {
  98. return c_str_ptr(s);
  99. }
  100. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  101. inline LPCOLESTR c_str_data_w(atlstl_ns_qual_atl(CComBSTR) const& s)
  102. {
  103. return c_str_data(s);
  104. }
  105. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  106. /* /////////////////////////////////////////////////////////////////////////
  107. * c_str_len
  108. *
  109. * This can be applied to an expression, and the return value is the number
  110. * of characters in the character string in the expression.
  111. */
  112. /* CComBSTR */
  113. /** \brief \ref group__concept__shim__string_access__c_str_len for CComBSTR
  114. *
  115. * \ingroup group__concept__shim__string_access
  116. *
  117. */
  118. inline as_size_t c_str_len(atlstl_ns_qual_atl(CComBSTR) const& s)
  119. {
  120. return s.Length();
  121. }
  122. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  123. inline as_size_t c_str_len_w(atlstl_ns_qual_atl(CComBSTR) const& s)
  124. {
  125. return c_str_len(s);
  126. }
  127. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  128. /* /////////////////////////////////////////////////////////////////////////
  129. * c_str_ptr
  130. *
  131. * This can be applied to an expression, and the return value is either a
  132. * pointer to the character string or to an empty string.
  133. */
  134. /* CComBSTR */
  135. /** \brief \ref group__concept__shim__string_access__c_str_ptr for CComBSTR
  136. *
  137. * \ingroup group__concept__shim__string_access
  138. *
  139. */
  140. inline LPCOLESTR c_str_ptr(atlstl_ns_qual_atl(CComBSTR) const& s)
  141. {
  142. /* NULL is a valid BSTR value, so check for that */
  143. return (s.m_str != 0) ? s.m_str : L"";
  144. }
  145. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  146. inline LPCOLESTR c_str_ptr_w(atlstl_ns_qual_atl(CComBSTR) const& s)
  147. {
  148. return c_str_ptr(s);
  149. }
  150. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  151. /* /////////////////////////////////////////////////////////////////////////
  152. * c_str_ptr_null
  153. *
  154. * This can be applied to an expression, and the return value is either a
  155. * pointer to the character string or NULL.
  156. */
  157. /* CComBSTR */
  158. /** \brief \ref group__concept__shim__string_access__c_str_ptr_null for CComBSTR
  159. *
  160. * \ingroup group__concept__shim__string_access
  161. *
  162. */
  163. inline LPCOLESTR c_str_ptr_null(atlstl_ns_qual_atl(CComBSTR) const& s)
  164. {
  165. /* NULL is a valid BSTR value, so may return that */
  166. return s.m_str;
  167. }
  168. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  169. inline LPCOLESTR c_str_ptr_null_w(atlstl_ns_qual_atl(CComBSTR) const& s)
  170. {
  171. return c_str_ptr_null(s);
  172. }
  173. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  174. ////////////////////////////////////////////////////////////////////////////
  175. // Unit-testing
  176. #ifdef STLSOFT_UNITTEST
  177. # include "./unittest/ccombstr_unittest_.h"
  178. #endif /* STLSOFT_UNITTEST */
  179. /* ////////////////////////////////////////////////////////////////////// */
  180. #ifndef _ATLSTL_NO_NAMESPACE
  181. # if defined(_STLSOFT_NO_NAMESPACE) || \
  182. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  183. } // namespace atlstl
  184. # else
  185. } // namespace stlsoft::atlstl_project
  186. } // namespace stlsoft
  187. # endif /* _STLSOFT_NO_NAMESPACE */
  188. #endif /* !_ATLSTL_NO_NAMESPACE */
  189. /* /////////////////////////////////////////////////////////////////////////
  190. * Namespace
  191. *
  192. * The string access shims exist either in the stlsoft namespace, or in the
  193. * global namespace. This is required by the lookup rules.
  194. *
  195. */
  196. #ifndef _ATLSTL_NO_NAMESPACE
  197. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  198. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  199. namespace stlsoft
  200. {
  201. # else /* ? _STLSOFT_NO_NAMESPACE */
  202. /* There is no stlsoft namespace, so must define in the global namespace */
  203. # endif /* !_STLSOFT_NO_NAMESPACE */
  204. using ::atlstl::c_str_data;
  205. using ::atlstl::c_str_data_w;
  206. using ::atlstl::c_str_len;
  207. using ::atlstl::c_str_len_w;
  208. using ::atlstl::c_str_ptr;
  209. using ::atlstl::c_str_ptr_w;
  210. using ::atlstl::c_str_ptr_null;
  211. using ::atlstl::c_str_ptr_null_w;
  212. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  213. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  214. } // namespace stlsoft
  215. # else /* ? _STLSOFT_NO_NAMESPACE */
  216. /* There is no stlsoft namespace, so must define in the global namespace */
  217. # endif /* !_STLSOFT_NO_NAMESPACE */
  218. #endif /* !_ATLSTL_NO_NAMESPACE */
  219. /* ////////////////////////////////////////////////////////////////////// */
  220. #endif /* !ATLSTL_INCL_ATLSTL_SHIMS_ACCESS_STRING_HPP_CCOMBSTR */
  221. /* ///////////////////////////// end of file //////////////////////////// */