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.

146 lines
5.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: atlstl/string/string_traits.hpp
  3. *
  4. * Purpose: Contains string_traits for ATL.
  5. *
  6. * Created: 28th April 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 atlstl/string/string_traits.hpp
  40. *
  41. * \brief [C++] Specialisation of the stlsoft::string_traits traits class
  42. * for ATL types
  43. * (\ref group__library__string "String" Library).
  44. */
  45. #ifndef ATLSTL_INCL_ATLSTL_STRING_HPP_STRING_TRAITS
  46. #define ATLSTL_INCL_ATLSTL_STRING_HPP_STRING_TRAITS
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define ATLSTL_VER_ATLSTL_STRING_HPP_STRING_TRAITS_MAJOR 3
  49. # define ATLSTL_VER_ATLSTL_STRING_HPP_STRING_TRAITS_MINOR 0
  50. # define ATLSTL_VER_ATLSTL_STRING_HPP_STRING_TRAITS_REVISION 2
  51. # define ATLSTL_VER_ATLSTL_STRING_HPP_STRING_TRAITS_EDIT 20
  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_STRING_HPP_STRING_TRAITS_FWD
  60. # include <stlsoft/string/string_traits_fwd.hpp>
  61. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Namespace
  64. */
  65. #ifndef _STLSOFT_NO_NAMESPACE
  66. namespace stlsoft
  67. {
  68. #endif /* _STLSOFT_NO_NAMESPACE */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Classes
  71. */
  72. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  73. /* ATL's CComBSTR */
  74. STLSOFT_TEMPLATE_SPECIALISATION
  75. struct string_traits<CComBSTR>
  76. {
  77. typedef CComBSTR value_type;
  78. typedef WCHAR char_type;
  79. typedef ss_size_t size_type;
  80. typedef char_type const const_char_type;
  81. typedef value_type string_type;
  82. typedef LPOLESTR pointer;
  83. typedef LPCOLESTR const_pointer;
  84. typedef pointer iterator;
  85. typedef const_pointer const_iterator;
  86. enum
  87. {
  88. is_pointer = false
  89. , is_pointer_to_const = false
  90. , char_type_size = sizeof(char_type)
  91. };
  92. static string_type empty_string()
  93. {
  94. return string_type();
  95. }
  96. static string_type construct(string_type const& src, size_type pos, size_type len)
  97. {
  98. return string_type(static_cast<int>(len), static_cast<const_pointer>(src) + pos);
  99. }
  100. static string_type &assign_inplace(string_type &str, const_iterator first, const_iterator last)
  101. {
  102. return (str = string_type(static_cast<int>(last - first), first), str);
  103. }
  104. static iterator begin(string_type &str)
  105. {
  106. return &(str[0]);
  107. }
  108. static iterator end(string_type &str)
  109. {
  110. return begin(str) + str.Length();
  111. }
  112. };
  113. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  114. ////////////////////////////////////////////////////////////////////////////
  115. // Unit-testing
  116. #ifdef STLSOFT_UNITTEST
  117. # include "./unittest/string_traits_unittest_.h"
  118. #endif /* STLSOFT_UNITTEST */
  119. /* ////////////////////////////////////////////////////////////////////// */
  120. #ifndef _STLSOFT_NO_NAMESPACE
  121. } // namespace stlsoft
  122. #endif /* _STLSOFT_NO_NAMESPACE */
  123. /* ////////////////////////////////////////////////////////////////////// */
  124. #endif /* !ATLSTL_INCL_ATLSTL_STRING_HPP_STRING_TRAITS */
  125. /* ///////////////////////////// end of file //////////////////////////// */