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.

175 lines
5.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: mfcstl/collections/carray_swap.hpp
  3. *
  4. * Purpose: Contains the CArray_swap utility function.
  5. *
  6. * Created: 4th August 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 mfcstl/collections/carray_swap.hpp
  40. *
  41. * \brief [C++ only] Definition of the mfcstl::CArray_swap utility function
  42. * (\ref group__library__collections "Collections" Library).
  43. */
  44. #ifndef MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP
  45. #define MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP_MAJOR 2
  48. # define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP_MINOR 0
  49. # define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP_REVISION 2
  50. # define MFCSTL_VER_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP_EDIT 14
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef MFCSTL_INCL_MFCSTL_HPP_MFCSTL
  56. # include <mfcstl/mfcstl.hpp>
  57. #endif /* !MFCSTL_INCL_MFCSTL_HPP_MFCSTL */
  58. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
  59. # include <stlsoft/util/std_swap.hpp>
  60. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Version compatibility
  63. */
  64. // All version of MFC up to and including 8.0 support swap-by-members
  65. #if _MFC_VER <= 0x0800 && \
  66. !defined(MFCSTL_CARRAY_SWAP_MEMBERS_SUPPORT)
  67. # define MFCSTL_CARRAY_SWAP_MEMBERS_SUPPORT
  68. #endif /* _MFC_VER <= 0x0800 && !MFCSTL_CARRAY_SWAP_MEMBERS_SUPPORT */
  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. #ifdef MFCSTL_CARRAY_SWAP_MEMBERS_SUPPORT
  88. #ifdef STLSOFT_CF_NAMESPACE_SUPPORT
  89. namespace array_impl
  90. {
  91. #endif /* STLSOFT_CF_NAMESPACE_SUPPORT */
  92. /** Helper class that facilitates safe swapping of the state of CArray<>
  93. * instances
  94. */
  95. template <class A>
  96. class CArray_swap_veneer
  97. : public A
  98. {
  99. /// \name Member Types
  100. /// @{
  101. public:
  102. typedef CArray_swap_veneer<A> class_type;
  103. /// @}
  104. /// \name Operations
  105. /// @{
  106. public:
  107. static void swap(class_type& lhs, class_type& rhs)
  108. {
  109. std_swap(lhs.m_pData, rhs.m_pData);
  110. std_swap(lhs.m_nSize, rhs.m_nSize);
  111. std_swap(lhs.m_nMaxSize, rhs.m_nMaxSize);
  112. std_swap(lhs.m_nGrowBy, rhs.m_nGrowBy);
  113. }
  114. /// @}
  115. };
  116. #ifdef STLSOFT_CF_NAMESPACE_SUPPORT
  117. } // namespace array_impl
  118. #endif /* STLSOFT_CF_NAMESPACE_SUPPORT */
  119. /** \brief Swaps the contents of two instances of CArray-family
  120. * containers.
  121. *
  122. * \ingroup group__library__collections
  123. */
  124. template <class A>
  125. void CArray_swap(A& lhs, A& rhs)
  126. {
  127. #ifdef STLSOFT_CF_NAMESPACE_SUPPORT
  128. using array_impl::CArray_swap_veneer;
  129. #endif /* STLSOFT_CF_NAMESPACE_SUPPORT */
  130. typedef CArray_swap_veneer<A> swapper_t;
  131. swapper_t::swap(static_cast<swapper_t&>(lhs), static_cast<swapper_t&>(rhs));
  132. }
  133. #endif /* MFCSTL_CARRAY_SWAP_MEMBERS_SUPPORT */
  134. /* ////////////////////////////////////////////////////////////////////// */
  135. #ifndef _MFCSTL_NO_NAMESPACE
  136. # if defined(_STLSOFT_NO_NAMESPACE) || \
  137. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  138. } // namespace mfcstl
  139. # else
  140. } // namespace mfcstl_project
  141. } // namespace stlsoft
  142. # endif /* _STLSOFT_NO_NAMESPACE */
  143. #endif /* !_MFCSTL_NO_NAMESPACE */
  144. /* ////////////////////////////////////////////////////////////////////// */
  145. #endif /* MFCSTL_INCL_MFCSTL_COLLECTIONS_HPP_ARRAY_SWAP */
  146. /* ///////////////////////////// end of file //////////////////////////// */